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

5
import 'package:file/memory.dart';
6
import 'package:flutter_tools/src/artifacts.dart';
7 8 9 10 11
import 'package:flutter_tools/src/base/file_system.dart';
import 'package:flutter_tools/src/base/platform.dart';
import 'package:flutter_tools/src/build_info.dart';
import 'package:flutter_tools/src/cache.dart';

12 13
import '../src/common.dart';
import '../src/context.dart';
14 15

void main() {
16 17
  group('Artifacts', () {
    MemoryFileSystem memoryFileSystem;
18 19 20
    Directory tempDir;

    setUp(() {
21
      memoryFileSystem = MemoryFileSystem();
22
      tempDir = memoryFileSystem.systemTempDirectory.createTempSync('flutter_artifacts_test.');
23 24 25
    });

    tearDown(() {
26
      tryToDelete(tempDir);
27 28
    });

29 30 31 32 33 34 35 36 37
    group('CachedArtifacts', () {
      CachedArtifacts artifacts;

      setUp(() {
        artifacts = CachedArtifacts();
      });

      testUsingContext('getArtifactPath', () {
        expect(
38
          artifacts.getArtifactPath(Artifact.flutterFramework, platform: TargetPlatform.ios, mode: BuildMode.release),
39
          fs.path.join(tempDir.path, 'bin', 'cache', 'artifacts', 'engine', 'ios-release', 'Flutter.framework'),
40 41
        );
        expect(
42
          artifacts.getArtifactPath(Artifact.flutterTester),
43
          fs.path.join(tempDir.path, 'bin', 'cache', 'artifacts', 'engine', 'linux-x64', 'flutter_tester'),
44 45 46 47
        );
      }, overrides: <Type, Generator>{
        Cache: () => Cache(rootOverride: tempDir),
        FileSystem: () => memoryFileSystem,
48
        ProcessManager: () => FakeProcessManager.any(),
49 50
        Platform: () => FakePlatform(operatingSystem: 'linux'),
      });
51

52 53
      testUsingContext('getEngineType', () {
        expect(
54
          artifacts.getEngineType(TargetPlatform.android_arm, BuildMode.debug),
55
          'android-arm',
56 57
        );
        expect(
58
          artifacts.getEngineType(TargetPlatform.ios, BuildMode.release),
59
          'ios-release',
60 61
        );
        expect(
62
          artifacts.getEngineType(TargetPlatform.darwin_x64),
63
          'darwin-x64',
64 65 66 67
        );
      }, overrides: <Type, Generator>{
        Cache: () => Cache(rootOverride: tempDir),
        FileSystem: () => memoryFileSystem,
68
        ProcessManager: () => FakeProcessManager.any(),
69 70
        Platform: () => FakePlatform(operatingSystem: 'linux'),
      });
71 72
    });

73 74
    group('LocalEngineArtifacts', () {
      LocalEngineArtifacts artifacts;
75

76 77 78 79 80 81
      setUp(() {
        artifacts = LocalEngineArtifacts(tempDir.path,
          memoryFileSystem.path.join(tempDir.path, 'out', 'android_debug_unopt'),
          memoryFileSystem.path.join(tempDir.path, 'out', 'host_debug_unopt'),
        );
      });
82

83 84
      testUsingContext('getArtifactPath', () {
        expect(
85
          artifacts.getArtifactPath(Artifact.flutterFramework, platform: TargetPlatform.ios, mode: BuildMode.release),
86
          fs.path.join(tempDir.path, 'out', 'android_debug_unopt', 'Flutter.framework'),
87 88
        );
        expect(
89
          artifacts.getArtifactPath(Artifact.flutterTester),
90
          fs.path.join(tempDir.path, 'out', 'android_debug_unopt', 'flutter_tester'),
91 92 93 94 95 96 97
        );
        expect(
          artifacts.getArtifactPath(Artifact.engineDartSdkPath),
          fs.path.join(tempDir.path, 'out', 'host_debug_unopt', 'dart-sdk'),
        );
      }, overrides: <Type, Generator>{
        FileSystem: () => memoryFileSystem,
98
        ProcessManager: () => FakeProcessManager.any(),
99 100
        Platform: () => FakePlatform(operatingSystem: 'linux'),
      });
101

102 103
      testUsingContext('getEngineType', () {
        expect(
104
          artifacts.getEngineType(TargetPlatform.android_arm, BuildMode.debug),
105
          'android_debug_unopt',
106 107
        );
        expect(
108
          artifacts.getEngineType(TargetPlatform.ios, BuildMode.release),
109
          'android_debug_unopt',
110 111
        );
        expect(
112
          artifacts.getEngineType(TargetPlatform.darwin_x64),
113
          'android_debug_unopt',
114 115 116
        );
      }, overrides: <Type, Generator>{
        FileSystem: () => memoryFileSystem,
117
        ProcessManager: () => FakeProcessManager.any(),
118 119
        Platform: () => FakePlatform(operatingSystem: 'linux'),
      });
120 121 122 123 124

      testUsingContext('Looks up dart.exe on windows platforms', () async {
        expect(artifacts.getArtifactPath(Artifact.engineDartBinary), contains('.exe'));
      }, overrides: <Type, Generator>{
        FileSystem: () => memoryFileSystem,
125
        ProcessManager: () => FakeProcessManager.any(),
126 127 128 129 130 131 132
        Platform: () => FakePlatform(operatingSystem: 'windows'),
      });

      testUsingContext('Looks up dart on linux platforms', () async {
        expect(artifacts.getArtifactPath(Artifact.engineDartBinary), isNot(contains('.exe')));
      }, overrides: <Type, Generator>{
        FileSystem: () => memoryFileSystem,
133
        ProcessManager: () => FakeProcessManager.any(),
134 135
        Platform: () => FakePlatform(operatingSystem: 'linux'),
      });
136 137
    });
  });
138
}