artifacts_test.dart 4.35 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
// 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';
import 'package:test/test.dart';

import 'src/context.dart';

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

    Directory tempDir;
    CachedArtifacts artifacts;

    setUp(() {
      tempDir = fs.systemTempDirectory.createTempSync('flutter_temp');
      artifacts = new CachedArtifacts();
    });

    tearDown(() {
      tempDir.deleteSync(recursive: true);
    });

    testUsingContext('getArtifactPath', () {
      expect(
          artifacts.getArtifactPath(Artifact.flutterFramework, TargetPlatform.ios, BuildMode.release),
          fs.path.join(tempDir.path, 'bin', 'cache', 'artifacts', 'engine', 'ios-release', 'Flutter.framework')
      );
34 35 36 37
      expect(
          artifacts.getArtifactPath(Artifact.entryPointsExtraJson, TargetPlatform.android_arm64, BuildMode.release),
          fs.path.join(tempDir.path, 'bin', 'cache', 'artifacts', 'engine', 'android-arm64-release', 'entry_points_extra.json')
      );
38
      expect(
39
          artifacts.getArtifactPath(Artifact.flutterTester),
40
          fs.path.join(tempDir.path, 'bin', 'cache', 'artifacts', 'engine', 'linux-x64', 'flutter_tester')
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72
      );
    }, overrides: <Type, Generator> {
      Cache: () => new Cache(rootOverride: tempDir),
      Platform: () => new FakePlatform(operatingSystem: 'linux')
    });

    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> {
      Cache: () => new Cache(rootOverride: tempDir),
      Platform: () => new FakePlatform(operatingSystem: 'linux')
    });
  });

  group('LocalEngineArtifacts', () {

    Directory tempDir;
    LocalEngineArtifacts artifacts;

    setUp(() {
      tempDir = fs.systemTempDirectory.createTempSync('flutter_temp');
73 74 75 76
      artifacts = new LocalEngineArtifacts(tempDir.path,
        fs.path.join(tempDir.path, 'out', 'android_debug_unopt'),
        fs.path.join(tempDir.path, 'out', 'host_debug_unopt'),
      );
77 78 79 80 81 82 83 84 85
    });

    tearDown(() {
      tempDir.deleteSync(recursive: true);
    });

    testUsingContext('getArtifactPath', () {
      expect(
          artifacts.getArtifactPath(Artifact.dartIoEntriesTxt, TargetPlatform.android_arm, BuildMode.debug),
86
          fs.path.join(tempDir.path, 'third_party', 'dart', 'runtime', 'bin', 'dart_io_entries.txt')
87
      );
88 89 90 91
      expect(
          artifacts.getArtifactPath(Artifact.entryPointsJson, TargetPlatform.android_arm, BuildMode.profile),
          fs.path.join(tempDir.path, 'out', 'android_debug_unopt', 'dart_entry_points', 'entry_points.json')
      );
92 93 94 95 96
      expect(
          artifacts.getArtifactPath(Artifact.flutterFramework, TargetPlatform.ios, BuildMode.release),
          fs.path.join(tempDir.path, 'out', 'android_debug_unopt', 'Flutter.framework')
      );
      expect(
97
          artifacts.getArtifactPath(Artifact.flutterTester),
98
          fs.path.join(tempDir.path, 'out', 'android_debug_unopt', 'flutter_tester')
99
      );
100 101 102 103
      expect(
        artifacts.getArtifactPath(Artifact.engineDartSdkPath),
        fs.path.join(tempDir.path, 'out', 'host_debug_unopt', 'dart-sdk')
      );
104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125
    }, overrides: <Type, Generator> {
      Platform: () => new FakePlatform(operatingSystem: 'linux')
    });

    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> {
      Platform: () => new FakePlatform(operatingSystem: 'linux')
    });
  });
}