Ian Hickson | 449f4a6 | 2019-11-27 15:04:02 -0800 | [diff] [blame] | 1 | // Copyright 2014 The Flutter Authors. All rights reserved. |
KyleWong | 4b4a9400 | 2019-02-13 23:48:03 +0800 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | |
| 6 | import 'package:flutter_tools/src/build_info.dart'; |
| 7 | |
Ian Hickson | d919e69 | 2019-07-13 11:51:44 -0700 | [diff] [blame] | 8 | import '../src/common.dart'; |
| 9 | import '../src/context.dart'; |
KyleWong | 4b4a9400 | 2019-02-13 23:48:03 +0800 | [diff] [blame] | 10 | |
| 11 | void main() { |
Alexandre Ardhuin | bfa1d25 | 2019-03-23 00:02:21 +0100 | [diff] [blame] | 12 | setUpAll(() { }); |
KyleWong | 4b4a9400 | 2019-02-13 23:48:03 +0800 | [diff] [blame] | 13 | |
| 14 | group('Validate build number', () { |
Alexandre Ardhuin | bfa1d25 | 2019-03-23 00:02:21 +0100 | [diff] [blame] | 15 | setUp(() async { }); |
KyleWong | 4b4a9400 | 2019-02-13 23:48:03 +0800 | [diff] [blame] | 16 | |
| 17 | testUsingContext('CFBundleVersion for iOS', () async { |
| 18 | String buildName = validatedBuildNumberForPlatform(TargetPlatform.ios, 'xyz'); |
Jenn Magder | 9a68b0d | 2019-09-17 17:07:41 -0700 | [diff] [blame] | 19 | expect(buildName, isNull); |
Jenn Magder | dd1fb3b | 2019-07-31 16:18:09 -0700 | [diff] [blame] | 20 | buildName = validatedBuildNumberForPlatform(TargetPlatform.ios, '0.0.1'); |
| 21 | expect(buildName, '0.0.1'); |
KyleWong | 4b4a9400 | 2019-02-13 23:48:03 +0800 | [diff] [blame] | 22 | 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 Ardhuin | bfa1d25 | 2019-03-23 00:02:21 +0100 | [diff] [blame] | 37 | setUp(() async { }); |
KyleWong | 4b4a9400 | 2019-02-13 23:48:03 +0800 | [diff] [blame] | 38 | |
| 39 | testUsingContext('CFBundleShortVersionString for iOS', () async { |
| 40 | String buildName = validatedBuildNameForPlatform(TargetPlatform.ios, 'xyz'); |
Jenn Magder | 9a68b0d | 2019-09-17 17:07:41 -0700 | [diff] [blame] | 41 | expect(buildName, isNull); |
Jenn Magder | dd1fb3b | 2019-07-31 16:18:09 -0700 | [diff] [blame] | 42 | buildName = validatedBuildNameForPlatform(TargetPlatform.ios, '0.0.1'); |
| 43 | expect(buildName, '0.0.1'); |
KyleWong | 4b4a9400 | 2019-02-13 23:48:03 +0800 | [diff] [blame] | 44 | 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 Williams | ab260ba | 2019-10-28 09:37:29 -0700 | [diff] [blame] | 56 | |
| 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 Field | 8b29933 | 2020-01-27 14:36:02 -0800 | [diff] [blame] | 78 | expect(() => BuildMode.fromName('foo'), throwsArgumentError); |
Jonah Williams | ab260ba | 2019-10-28 09:37:29 -0700 | [diff] [blame] | 79 | }); |
KyleWong | 4b4a9400 | 2019-02-13 23:48:03 +0800 | [diff] [blame] | 80 | }); |
Jonah Williams | da4b5d6 | 2020-02-05 17:45:24 -0800 | [diff] [blame] | 81 | |
| 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 Magder | 7c24ebc | 2020-02-11 19:43:43 -0800 | [diff] [blame] | 88 | |
| 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 Anderson | 9de7787 | 2020-02-27 22:46:23 -0800 | [diff] [blame] | 94 | expect(() => getIOSArchForName('bogus'), throwsException); |
Jenn Magder | 7c24ebc | 2020-02-11 19:43:43 -0800 | [diff] [blame] | 95 | }); |
KyleWong | 4b4a9400 | 2019-02-13 23:48:03 +0800 | [diff] [blame] | 96 | } |