blob: 6fdd1692045fb42cfc3fc624c5e0b9dab0e94177 [file] [log] [blame]
Ian Hickson449f4a62019-11-27 15:04:02 -08001// Copyright 2014 The Flutter Authors. All rights reserved.
KyleWong4b4a94002019-02-13 23:48:03 +08002// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5
6import 'package:flutter_tools/src/build_info.dart';
7
Ian Hicksond919e692019-07-13 11:51:44 -07008import '../src/common.dart';
9import '../src/context.dart';
KyleWong4b4a94002019-02-13 23:48:03 +080010
11void main() {
Alexandre Ardhuinbfa1d252019-03-23 00:02:21 +010012 setUpAll(() { });
KyleWong4b4a94002019-02-13 23:48:03 +080013
14 group('Validate build number', () {
Alexandre Ardhuinbfa1d252019-03-23 00:02:21 +010015 setUp(() async { });
KyleWong4b4a94002019-02-13 23:48:03 +080016
17 testUsingContext('CFBundleVersion for iOS', () async {
18 String buildName = validatedBuildNumberForPlatform(TargetPlatform.ios, 'xyz');
Jenn Magder9a68b0d2019-09-17 17:07:41 -070019 expect(buildName, isNull);
Jenn Magderdd1fb3b2019-07-31 16:18:09 -070020 buildName = validatedBuildNumberForPlatform(TargetPlatform.ios, '0.0.1');
21 expect(buildName, '0.0.1');
KyleWong4b4a94002019-02-13 23:48:03 +080022 buildName = validatedBuildNumberForPlatform(TargetPlatform.ios, '123.xyz');
23 expect(buildName, '123');
24 buildName = validatedBuildNumberForPlatform(TargetPlatform.ios, '123.456.xyz');
25 expect(buildName, '123.456');
26 });
27
28 testUsingContext('versionCode for Android', () async {
29 String buildName = validatedBuildNumberForPlatform(TargetPlatform.android_arm, '123.abc+-');
30 expect(buildName, '123');
31 buildName = validatedBuildNumberForPlatform(TargetPlatform.android_arm, 'abc');
32 expect(buildName, '1');
33 });
34 });
35
36 group('Validate build name', () {
Alexandre Ardhuinbfa1d252019-03-23 00:02:21 +010037 setUp(() async { });
KyleWong4b4a94002019-02-13 23:48:03 +080038
39 testUsingContext('CFBundleShortVersionString for iOS', () async {
40 String buildName = validatedBuildNameForPlatform(TargetPlatform.ios, 'xyz');
Jenn Magder9a68b0d2019-09-17 17:07:41 -070041 expect(buildName, isNull);
Jenn Magderdd1fb3b2019-07-31 16:18:09 -070042 buildName = validatedBuildNameForPlatform(TargetPlatform.ios, '0.0.1');
43 expect(buildName, '0.0.1');
KyleWong4b4a94002019-02-13 23:48:03 +080044 buildName = validatedBuildNameForPlatform(TargetPlatform.ios, '123.456.xyz');
45 expect(buildName, '123.456.0');
46 buildName = validatedBuildNameForPlatform(TargetPlatform.ios, '123.xyz');
47 expect(buildName, '123.0.0');
48 });
49
50 testUsingContext('versionName for Android', () async {
51 String buildName = validatedBuildNameForPlatform(TargetPlatform.android_arm, '123.abc+-');
52 expect(buildName, '123.abc+-');
53 buildName = validatedBuildNameForPlatform(TargetPlatform.android_arm, 'abc+-');
54 expect(buildName, 'abc+-');
55 });
Jonah Williamsab260ba2019-10-28 09:37:29 -070056
57 test('build mode configuration is correct', () {
58 expect(BuildMode.debug.isRelease, false);
59 expect(BuildMode.debug.isPrecompiled, false);
60 expect(BuildMode.debug.isJit, true);
61
62 expect(BuildMode.profile.isRelease, false);
63 expect(BuildMode.profile.isPrecompiled, true);
64 expect(BuildMode.profile.isJit, false);
65
66 expect(BuildMode.release.isRelease, true);
67 expect(BuildMode.release.isPrecompiled, true);
68 expect(BuildMode.release.isJit, false);
69
70 expect(BuildMode.jitRelease.isRelease, true);
71 expect(BuildMode.jitRelease.isPrecompiled, false);
72 expect(BuildMode.jitRelease.isJit, true);
73
74 expect(BuildMode.fromName('debug'), BuildMode.debug);
75 expect(BuildMode.fromName('profile'), BuildMode.profile);
76 expect(BuildMode.fromName('jit_release'), BuildMode.jitRelease);
77 expect(BuildMode.fromName('release'), BuildMode.release);
Dan Field8b299332020-01-27 14:36:02 -080078 expect(() => BuildMode.fromName('foo'), throwsArgumentError);
Jonah Williamsab260ba2019-10-28 09:37:29 -070079 });
KyleWong4b4a94002019-02-13 23:48:03 +080080 });
Jonah Williamsda4b5d62020-02-05 17:45:24 -080081
82 test('getNameForTargetPlatform on Darwin arches', () {
83 expect(getNameForTargetPlatform(TargetPlatform.ios, darwinArch: DarwinArch.arm64), 'ios-arm64');
84 expect(getNameForTargetPlatform(TargetPlatform.ios, darwinArch: DarwinArch.armv7), 'ios-armv7');
85 expect(getNameForTargetPlatform(TargetPlatform.ios, darwinArch: DarwinArch.x86_64), 'ios-x86_64');
86 expect(getNameForTargetPlatform(TargetPlatform.android), isNot(contains('ios')));
87 });
Jenn Magder7c24ebc2020-02-11 19:43:43 -080088
89 test('getIOSArchForName on Darwin arches', () {
90 expect(getIOSArchForName('armv7'), DarwinArch.armv7);
91 expect(getIOSArchForName('arm64'), DarwinArch.arm64);
92 expect(getIOSArchForName('arm64e'), DarwinArch.arm64);
93 expect(getIOSArchForName('x86_64'), DarwinArch.x86_64);
Zachary Anderson9de77872020-02-27 22:46:23 -080094 expect(() => getIOSArchForName('bogus'), throwsException);
Jenn Magder7c24ebc2020-02-11 19:43:43 -080095 });
KyleWong4b4a94002019-02-13 23:48:03 +080096}