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

import 'package:file/memory.dart';
6
import 'package:file_testing/file_testing.dart';
7
import 'package:flutter_tools/src/build_system/targets/dart.dart';
8 9
import 'package:mockito/mockito.dart';
import 'package:platform/platform.dart';
10 11 12
import 'package:flutter_tools/src/artifacts.dart';
import 'package:flutter_tools/src/base/logger.dart';
import 'package:flutter_tools/src/build_system/depfile.dart';
13 14 15 16
import 'package:flutter_tools/src/base/file_system.dart';
import 'package:flutter_tools/src/build_system/build_system.dart';
import 'package:flutter_tools/src/build_system/targets/windows.dart';

17
import '../../../src/common.dart';
18
import '../../../src/context.dart';
19
import '../../../src/fake_process_manager.dart';
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38

final Platform kWindowsPlatform = FakePlatform(
  operatingSystem: 'windows',
  environment: <String, String>{},
);

const List<String> kRequiredFiles = <String>[
  r'C:\bin\cache\artifacts\engine\windows-x64\flutter_export.h',
  r'C:\bin\cache\artifacts\engine\windows-x64\flutter_messenger.h',
  r'C:\bin\cache\artifacts\engine\windows-x64\flutter_windows.dll',
  r'C:\bin\cache\artifacts\engine\windows-x64\flutter_windows.dll.exp',
  r'C:\bin\cache\artifacts\engine\windows-x64\flutter_windows.dll.lib',
  r'C:\bin\cache\artifacts\engine\windows-x64\flutter_windows.dll.pdb',
  r'C:\bin\cache\artifacts\engine\windows-x64\flutter_plugin_registrar.h',
  r'C:\bin\cache\artifacts\engine\windows-x64\flutter_windows.h',
  r'C:\bin\cache\artifacts\engine\windows-x64\icudtl.dat',
  r'C:\bin\cache\artifacts\engine\windows-x64\cpp_client_wrapper\foo',
  r'C:\packages\flutter_tools\lib\src\build_system\targets\windows.dart',
];
39 40

void main() {
41
  testWithoutContext('UnpackWindows copies files to the correct cache directory', () async {
42
    final MockArtifacts artifacts = MockArtifacts();
43 44
    final FileSystem fileSystem = MemoryFileSystem.test(style: FileSystemStyle.windows);
    final Environment environment = Environment.test(
45 46 47 48 49
      fileSystem.currentDirectory,
      artifacts: artifacts,
      processManager: FakeProcessManager.any(),
      fileSystem: fileSystem,
      logger: BufferLogger.test(),
50 51 52
      defines: <String, String>{
        kBuildMode: 'debug',
      }
53
    );
54 55 56 57 58 59
    final DepfileService depfileService = DepfileService(
      logger: BufferLogger.test(),
      fileSystem: fileSystem,
    );
    environment.buildDir.createSync(recursive: true);

60 61 62 63 64 65 66 67 68 69
    when(artifacts.getArtifactPath(
      Artifact.windowsDesktopPath,
      mode: anyNamed('mode'),
      platform: anyNamed('platform')
    )).thenReturn(r'C:\bin\cache\artifacts\engine\windows-x64\');
    when(artifacts.getArtifactPath(
      Artifact.windowsCppClientWrapper,
      mode: anyNamed('mode'),
      platform: anyNamed('platform')
    )).thenReturn(r'C:\bin\cache\artifacts\engine\windows-x64\cpp_client_wrapper\');
70 71 72 73
    for (final String path in kRequiredFiles) {
      fileSystem.file(path).createSync(recursive: true);
    }
    fileSystem.directory('windows').createSync();
74

75
    await const UnpackWindows().build(environment);
76

77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130
    // Output files are copied correctly.
    expect(fileSystem.file(r'C:\windows\flutter\ephemeral\flutter_export.h'), exists);
    expect(fileSystem.file(r'C:\windows\flutter\ephemeral\flutter_messenger.h'), exists);
    expect(fileSystem.file(r'C:\windows\flutter\ephemeral\flutter_windows.dll'), exists);
    expect(fileSystem.file(r'C:\windows\flutter\ephemeral\flutter_windows.dll.exp'), exists);
    expect(fileSystem.file(r'C:\windows\flutter\ephemeral\flutter_windows.dll.lib'), exists);
    expect(fileSystem.file(r'C:\windows\flutter\ephemeral\flutter_windows.dll.pdb'), exists);
    expect(fileSystem.file(r'C:\windows\flutter\ephemeral\flutter_export.h'), exists);
    expect(fileSystem.file(r'C:\windows\flutter\ephemeral\flutter_messenger.h'), exists);
    expect(fileSystem.file(r'C:\windows\flutter\ephemeral\flutter_plugin_registrar.h'), exists);
    expect(fileSystem.file(r'C:\windows\flutter\ephemeral\flutter_windows.h'), exists);
    expect(fileSystem.file(r'C:\windows\flutter\ephemeral\icudtl.dat'), exists);
    expect(fileSystem.file(r'C:\windows\flutter\ephemeral\cpp_client_wrapper\foo'), exists);


    final File outputDepfile = environment.buildDir
      .childFile('windows_engine_sources.d');

    // Depfile is created correctly.
    expect(outputDepfile, exists);

    final List<String> inputPaths = depfileService.parse(outputDepfile)
      .inputs.map((File file) => file.path).toList();
    final List<String> outputPaths = depfileService.parse(outputDepfile)
      .outputs.map((File file) => file.path).toList();

    // Depfile has expected sources.
    expect(inputPaths, unorderedEquals(<String>[
      r'C:\bin\cache\artifacts\engine\windows-x64\flutter_export.h',
      r'C:\bin\cache\artifacts\engine\windows-x64\flutter_messenger.h',
      r'C:\bin\cache\artifacts\engine\windows-x64\flutter_windows.dll',
      r'C:\bin\cache\artifacts\engine\windows-x64\flutter_windows.dll.exp',
      r'C:\bin\cache\artifacts\engine\windows-x64\flutter_windows.dll.lib',
      r'C:\bin\cache\artifacts\engine\windows-x64\flutter_windows.dll.pdb',
      r'C:\bin\cache\artifacts\engine\windows-x64\flutter_plugin_registrar.h',
      r'C:\bin\cache\artifacts\engine\windows-x64\flutter_windows.h',
      r'C:\bin\cache\artifacts\engine\windows-x64\icudtl.dat',
      r'C:\bin\cache\artifacts\engine\windows-x64\cpp_client_wrapper\foo',
    ]));
    expect(outputPaths, unorderedEquals(<String>[
      r'C:\windows\flutter\ephemeral\flutter_export.h',
      r'C:\windows\flutter\ephemeral\flutter_messenger.h',
      r'C:\windows\flutter\ephemeral\flutter_windows.dll',
      r'C:\windows\flutter\ephemeral\flutter_windows.dll.exp',
      r'C:\windows\flutter\ephemeral\flutter_windows.dll.lib',
      r'C:\windows\flutter\ephemeral\flutter_windows.dll.pdb',
      r'C:\windows\flutter\ephemeral\flutter_plugin_registrar.h',
      r'C:\windows\flutter\ephemeral\flutter_windows.h',
      r'C:\windows\flutter\ephemeral\icudtl.dat',
      r'C:\windows\flutter\ephemeral\cpp_client_wrapper\foo',
    ]));
  });

  // AssetBundleFactory still uses context injection
131 132 133 134 135 136
  FileSystem fileSystem;

  setUp(() {
    fileSystem = MemoryFileSystem.test(style: FileSystemStyle.windows);
  });

137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155
  testUsingContext('DebugBundleWindowsAssets creates correct bundle structure', () async {
    final Environment environment = Environment.test(
      fileSystem.currentDirectory,
      artifacts: MockArtifacts(),
      processManager: FakeProcessManager.any(),
      fileSystem: fileSystem,
      logger: BufferLogger.test(),
      defines: <String, String>{
        kBuildMode: 'debug',
      }
    );

    environment.buildDir.childFile('app.dill').createSync(recursive: true);

    await const DebugBundleWindowsAssets().build(environment);

    // Depfile is created and dill is copied.
    expect(environment.buildDir.childFile('flutter_assets.d'), exists);
    expect(fileSystem.file(r'C:\flutter_assets\kernel_blob.bin'), exists);
156 157 158 159
    expect(fileSystem.file(r'C:\flutter_assets\AssetManifest.json'), exists);
  }, overrides: <Type, Generator>{
    FileSystem: () => fileSystem,
    ProcessManager: () => FakeProcessManager.any(),
160
  });
161 162
}

163
class MockArtifacts extends Mock implements Artifacts {}