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


import 'package:flutter_tools/src/build_info.dart';

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

void main() {
12
  setUpAll(() { });
13 14

  group('Validate build number', () {
15
    setUp(() async { });
16 17 18

    testUsingContext('CFBundleVersion for iOS', () async {
      String buildName = validatedBuildNumberForPlatform(TargetPlatform.ios, 'xyz');
19
      expect(buildName, isNull);
20 21
      buildName = validatedBuildNumberForPlatform(TargetPlatform.ios, '0.0.1');
      expect(buildName, '0.0.1');
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
      buildName = validatedBuildNumberForPlatform(TargetPlatform.ios, '123.xyz');
      expect(buildName, '123');
      buildName = validatedBuildNumberForPlatform(TargetPlatform.ios, '123.456.xyz');
      expect(buildName, '123.456');
    });

    testUsingContext('versionCode for Android', () async {
      String buildName = validatedBuildNumberForPlatform(TargetPlatform.android_arm, '123.abc+-');
      expect(buildName, '123');
      buildName = validatedBuildNumberForPlatform(TargetPlatform.android_arm, 'abc');
      expect(buildName, '1');
    });
  });

  group('Validate build name', () {
37
    setUp(() async { });
38 39 40

    testUsingContext('CFBundleShortVersionString for iOS', () async {
      String buildName = validatedBuildNameForPlatform(TargetPlatform.ios, 'xyz');
41
      expect(buildName, isNull);
42 43
      buildName = validatedBuildNameForPlatform(TargetPlatform.ios, '0.0.1');
      expect(buildName, '0.0.1');
44 45 46 47 48 49 50 51 52 53 54 55
      buildName = validatedBuildNameForPlatform(TargetPlatform.ios, '123.456.xyz');
      expect(buildName, '123.456.0');
      buildName = validatedBuildNameForPlatform(TargetPlatform.ios, '123.xyz');
      expect(buildName, '123.0.0');
    });

    testUsingContext('versionName for Android', () async {
      String buildName = validatedBuildNameForPlatform(TargetPlatform.android_arm, '123.abc+-');
      expect(buildName, '123.abc+-');
      buildName = validatedBuildNameForPlatform(TargetPlatform.android_arm, 'abc+-');
      expect(buildName, 'abc+-');
    });
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77

    test('build mode configuration is correct', () {
      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
78
      expect(() => BuildMode.fromName('foo'), throwsArgumentError);
79
    });
80 81
  });
}