artifacts_test.dart 3.6 KB
Newer Older
1 2 3 4 5 6 7 8 9 10
// Copyright 2017 The Chromium Authors. All rights reserved.
// 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/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';
import 'package:flutter_tools/src/artifacts.dart';

11
import 'src/common.dart';
12 13 14 15 16 17 18 19 20
import 'src/context.dart';

void main() {
  group('CachedArtifacts', () {

    Directory tempDir;
    CachedArtifacts artifacts;

    setUp(() {
21
      tempDir = fs.systemTempDirectory.createTempSync('flutter_tools_artifacts_test_cached.');
22
      artifacts = CachedArtifacts();
23 24 25
    });

    tearDown(() {
26
      tryToDelete(tempDir);
27 28 29 30 31 32 33 34
    });

    testUsingContext('getArtifactPath', () {
      expect(
          artifacts.getArtifactPath(Artifact.flutterFramework, TargetPlatform.ios, BuildMode.release),
          fs.path.join(tempDir.path, 'bin', 'cache', 'artifacts', 'engine', 'ios-release', 'Flutter.framework')
      );
      expect(
35
          artifacts.getArtifactPath(Artifact.flutterTester),
36
          fs.path.join(tempDir.path, 'bin', 'cache', 'artifacts', 'engine', 'linux-x64', 'flutter_tester')
37 38
      );
    }, overrides: <Type, Generator> {
39 40
      Cache: () => Cache(rootOverride: tempDir),
      Platform: () => FakePlatform(operatingSystem: 'linux')
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
    });

    testUsingContext('getEngineType', () {
      expect(
          artifacts.getEngineType(TargetPlatform.android_arm, BuildMode.debug),
          'android-arm'
      );
      expect(
          artifacts.getEngineType(TargetPlatform.ios, BuildMode.release),
          'ios-release'
      );
      expect(
          artifacts.getEngineType(TargetPlatform.darwin_x64),
          'darwin-x64'
      );
    }, overrides: <Type, Generator> {
57 58
      Cache: () => Cache(rootOverride: tempDir),
      Platform: () => FakePlatform(operatingSystem: 'linux')
59 60 61 62 63 64 65 66 67
    });
  });

  group('LocalEngineArtifacts', () {

    Directory tempDir;
    LocalEngineArtifacts artifacts;

    setUp(() {
68
      tempDir = fs.systemTempDirectory.createTempSync('flutter_tools_artifacts_test_local.');
69
      artifacts = LocalEngineArtifacts(tempDir.path,
70 71 72
        fs.path.join(tempDir.path, 'out', 'android_debug_unopt'),
        fs.path.join(tempDir.path, 'out', 'host_debug_unopt'),
      );
73 74 75
    });

    tearDown(() {
76
      tryToDelete(tempDir);
77 78 79 80 81 82 83 84
    });

    testUsingContext('getArtifactPath', () {
      expect(
          artifacts.getArtifactPath(Artifact.flutterFramework, TargetPlatform.ios, BuildMode.release),
          fs.path.join(tempDir.path, 'out', 'android_debug_unopt', 'Flutter.framework')
      );
      expect(
85
          artifacts.getArtifactPath(Artifact.flutterTester),
86
          fs.path.join(tempDir.path, 'out', 'android_debug_unopt', 'flutter_tester')
87
      );
88 89 90 91
      expect(
        artifacts.getArtifactPath(Artifact.engineDartSdkPath),
        fs.path.join(tempDir.path, 'out', 'host_debug_unopt', 'dart-sdk')
      );
92
    }, overrides: <Type, Generator> {
93
      Platform: () => FakePlatform(operatingSystem: 'linux')
94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109
    });

    testUsingContext('getEngineType', () {
      expect(
          artifacts.getEngineType(TargetPlatform.android_arm, BuildMode.debug),
          'android_debug_unopt'
      );
      expect(
          artifacts.getEngineType(TargetPlatform.ios, BuildMode.release),
          'android_debug_unopt'
      );
      expect(
          artifacts.getEngineType(TargetPlatform.darwin_x64),
          'android_debug_unopt'
      );
    }, overrides: <Type, Generator> {
110
      Platform: () => FakePlatform(operatingSystem: 'linux')
111 112
    });
  });
113
}