build_info_test.dart 6.4 KB
Newer Older
Ian Hickson's avatar
Ian Hickson committed
1
// Copyright 2014 The Flutter Authors. All rights reserved.
2 3 4 5
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.


6
import 'package:flutter_tools/src/base/logger.dart';
7 8
import 'package:flutter_tools/src/build_info.dart';

9
import '../src/common.dart';
10 11

void main() {
12 13 14 15
  BufferLogger logger;
  setUp(() {
    logger = BufferLogger.test();
  });
16 17

  group('Validate build number', () {
18 19
    testWithoutContext('CFBundleVersion for iOS', () async {
      String buildName = validatedBuildNumberForPlatform(TargetPlatform.ios, 'xyz', logger);
20
      expect(buildName, isNull);
21
      buildName = validatedBuildNumberForPlatform(TargetPlatform.ios, '0.0.1', logger);
22
      expect(buildName, '0.0.1');
23
      buildName = validatedBuildNumberForPlatform(TargetPlatform.ios, '123.xyz', logger);
24
      expect(buildName, '123');
25
      buildName = validatedBuildNumberForPlatform(TargetPlatform.ios, '123.456.xyz', logger);
26 27 28
      expect(buildName, '123.456');
    });

29 30
    testWithoutContext('versionCode for Android', () async {
      String buildName = validatedBuildNumberForPlatform(TargetPlatform.android_arm, '123.abc+-', logger);
31
      expect(buildName, '123');
32
      buildName = validatedBuildNumberForPlatform(TargetPlatform.android_arm, 'abc', logger);
33 34 35 36 37
      expect(buildName, '1');
    });
  });

  group('Validate build name', () {
38 39
    testWithoutContext('CFBundleShortVersionString for iOS', () async {
      String buildName = validatedBuildNameForPlatform(TargetPlatform.ios, 'xyz', logger);
40
      expect(buildName, isNull);
41
      buildName = validatedBuildNameForPlatform(TargetPlatform.ios, '0.0.1', logger);
42
      expect(buildName, '0.0.1');
43 44 45

      buildName = validatedBuildNameForPlatform(TargetPlatform.ios, '123.456.xyz', logger);
      expect(logger.traceText, contains('Invalid build-name'));
46
      expect(buildName, '123.456.0');
47 48

      buildName = validatedBuildNameForPlatform(TargetPlatform.ios, '123.xyz', logger);
49 50 51
      expect(buildName, '123.0.0');
    });

52 53
    testWithoutContext('versionName for Android', () async {
      String buildName = validatedBuildNameForPlatform(TargetPlatform.android_arm, '123.abc+-', logger);
54
      expect(buildName, '123.abc+-');
55
      buildName = validatedBuildNameForPlatform(TargetPlatform.android_arm, 'abc+-', logger);
56 57
      expect(buildName, 'abc+-');
    });
58

59
    testWithoutContext('build mode configuration is correct', () {
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79
      expect(BuildMode.debug.isRelease, false);
      expect(BuildMode.debug.isPrecompiled, false);
      expect(BuildMode.debug.isJit, true);

      expect(BuildMode.profile.isRelease, false);
      expect(BuildMode.profile.isPrecompiled, true);
      expect(BuildMode.profile.isJit, false);

      expect(BuildMode.release.isRelease, true);
      expect(BuildMode.release.isPrecompiled, true);
      expect(BuildMode.release.isJit, false);

      expect(BuildMode.jitRelease.isRelease, true);
      expect(BuildMode.jitRelease.isPrecompiled, false);
      expect(BuildMode.jitRelease.isJit, true);

      expect(BuildMode.fromName('debug'), BuildMode.debug);
      expect(BuildMode.fromName('profile'), BuildMode.profile);
      expect(BuildMode.fromName('jit_release'), BuildMode.jitRelease);
      expect(BuildMode.fromName('release'), BuildMode.release);
Dan Field's avatar
Dan Field committed
80
      expect(() => BuildMode.fromName('foo'), throwsArgumentError);
81
    });
82
  });
83

84
  testWithoutContext('getNameForTargetPlatform on Darwin arches', () {
85 86 87 88 89
    expect(getNameForTargetPlatform(TargetPlatform.ios, darwinArch: DarwinArch.arm64), 'ios-arm64');
    expect(getNameForTargetPlatform(TargetPlatform.ios, darwinArch: DarwinArch.armv7), 'ios-armv7');
    expect(getNameForTargetPlatform(TargetPlatform.ios, darwinArch: DarwinArch.x86_64), 'ios-x86_64');
    expect(getNameForTargetPlatform(TargetPlatform.android), isNot(contains('ios')));
  });
90

91
  testWithoutContext('getIOSArchForName on Darwin arches', () {
92 93 94 95
    expect(getIOSArchForName('armv7'), DarwinArch.armv7);
    expect(getIOSArchForName('arm64'), DarwinArch.arm64);
    expect(getIOSArchForName('arm64e'), DarwinArch.arm64);
    expect(getIOSArchForName('x86_64'), DarwinArch.x86_64);
96
    expect(() => getIOSArchForName('bogus'), throwsException);
97
  });
98

99
  testWithoutContext('toEnvironmentConfig encoding of standard values', () {
100 101 102 103 104 105 106 107
    const BuildInfo buildInfo = BuildInfo(BuildMode.debug, '',
      treeShakeIcons: true,
      trackWidgetCreation: true,
      dartDefines: <String>['foo=2', 'bar=2'],
      dartObfuscation: true,
      splitDebugInfoPath: 'foo/',
      extraFrontEndOptions: <String>['--enable-experiment=non-nullable', 'bar'],
      extraGenSnapshotOptions: <String>['--enable-experiment=non-nullable', 'fizz'],
108
      bundleSkSLPath: 'foo/bar/baz.sksl.json',
109
      packagesPath: 'foo/.packages',
110 111 112 113 114
    );

    expect(buildInfo.toEnvironmentConfig(), <String, String>{
      'TREE_SHAKE_ICONS': 'true',
      'TRACK_WIDGET_CREATION': 'true',
115
      'DART_DEFINES': 'foo%3D2,bar%3D2',
116 117
      'DART_OBFUSCATION': 'true',
      'SPLIT_DEBUG_INFO': 'foo/',
118 119
      'EXTRA_FRONT_END_OPTIONS': '--enable-experiment%3Dnon-nullable,bar',
      'EXTRA_GEN_SNAPSHOT_OPTIONS': '--enable-experiment%3Dnon-nullable,fizz',
120
      'BUNDLE_SKSL_PATH': 'foo/bar/baz.sksl.json',
121
      'PACKAGE_CONFIG': 'foo/.packages',
122 123
    });
  });
124 125 126 127 128 129 130 131 132 133 134 135

  testWithoutContext('encodeDartDefines encodes define values with URI encode compnents', () {
    expect(encodeDartDefines(<String>['"hello"']), '%22hello%22');
    expect(encodeDartDefines(<String>['https://www.google.com']), 'https%3A%2F%2Fwww.google.com');
    expect(encodeDartDefines(<String>['2,3,4', '5']), '2%2C3%2C4,5');
    expect(encodeDartDefines(<String>['true', 'false', 'flase']), 'true,false,flase');
    expect(encodeDartDefines(<String>['1232,456', '2']), '1232%2C456,2');
  });

  testWithoutContext('decodeDartDefines decodes URI encoded dart defines', () {
    expect(decodeDartDefines(<String, String>{
      kDartDefines: '%22hello%22'
136
    }, kDartDefines), <String>['"hello"']);
137 138
    expect(decodeDartDefines(<String, String>{
      kDartDefines: 'https%3A%2F%2Fwww.google.com'
139
    }, kDartDefines), <String>['https://www.google.com']);
140 141
    expect(decodeDartDefines(<String, String>{
      kDartDefines: '2%2C3%2C4,5'
142
    }, kDartDefines), <String>['2,3,4', '5']);
143 144
    expect(decodeDartDefines(<String, String>{
      kDartDefines: 'true,false,flase'
145
    }, kDartDefines), <String>['true', 'false', 'flase']);
146 147
    expect(decodeDartDefines(<String, String>{
      kDartDefines: '1232%2C456,2'
148
    }, kDartDefines), <String>['1232,456', '2']);
149
  });
150
}