windows_test.dart 5.15 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12
// Copyright 2019 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:file/memory.dart';
import 'package:flutter_tools/src/base/file_system.dart';
import 'package:flutter_tools/src/base/platform.dart';
import 'package:flutter_tools/src/build_system/build_system.dart';
import 'package:flutter_tools/src/build_system/targets/windows.dart';
import 'package:flutter_tools/src/cache.dart';
import 'package:mockito/mockito.dart';

13 14
import '../../../src/common.dart';
import '../../../src/testbed.dart';
15 16

void main() {
17 18 19 20
  Testbed testbed;
  const BuildSystem buildSystem = BuildSystem();
  Environment environment;
  Platform platform;
21

22 23 24 25
  setUpAll(() {
    Cache.disableLocking();
    Cache.flutterRoot = '';
  });
26

27 28 29 30 31 32 33 34 35 36 37 38
  setUp(() {
    platform = MockPlatform();
    when(platform.isWindows).thenReturn(true);
    when(platform.isMacOS).thenReturn(false);
    when(platform.isLinux).thenReturn(false);
    when(platform.pathSeparator).thenReturn(r'\');
    testbed = Testbed(setup: () {
      environment = Environment(
        projectDir: fs.currentDirectory,
      );
      fs.file(r'C:\bin\cache\artifacts\engine\windows-x64\flutter_export.h').createSync(recursive: true);
      fs.file(r'C:\bin\cache\artifacts\engine\windows-x64\flutter_messenger.h').createSync();
39 40 41 42
      fs.file(r'C:\bin\cache\artifacts\engine\windows-x64\flutter_windows_glfw.dll').createSync();
      fs.file(r'C:\bin\cache\artifacts\engine\windows-x64\flutter_windows_glfw.dll.exp').createSync();
      fs.file(r'C:\bin\cache\artifacts\engine\windows-x64\flutter_windows_glfw.dll.lib').createSync();
      fs.file(r'C:\bin\cache\artifacts\engine\windows-x64\flutter_windows_glfw.dll.pdb').createSync();
43 44 45 46 47
      fs.file(r'C:\bin\cache\artifacts\engine\windows-x64\lutter_export.h').createSync();
      fs.file(r'C:\bin\cache\artifacts\engine\windows-x64\flutter_messenger.h').createSync();
      fs.file(r'C:\bin\cache\artifacts\engine\windows-x64\flutter_plugin_registrar.h').createSync();
      fs.file(r'C:\bin\cache\artifacts\engine\windows-x64\flutter_glfw.h').createSync();
      fs.file(r'C:\bin\cache\artifacts\engine\windows-x64\icudtl.dat').createSync();
48
      fs.file(r'C:\bin\cache\artifacts\engine\windows-x64\cpp_client_wrapper_glfw\foo').createSync(recursive: true);
49 50 51 52 53
      fs.file(r'C:\packages\flutter_tools\lib\src\build_system\targets\windows.dart').createSync(recursive: true);
      fs.directory('windows').createSync();
    }, overrides: <Type, Generator>{
      FileSystem: () => MemoryFileSystem(style: FileSystemStyle.windows),
      Platform: () => platform,
54
    });
55
  });
56

57 58
  test('Copies files to correct cache directory', () => testbed.run(() async {
    await buildSystem.build(const UnpackWindows(), environment);
59

60 61
    expect(fs.file(r'C:\windows\flutter\flutter_export.h').existsSync(), true);
    expect(fs.file(r'C:\windows\flutter\flutter_messenger.h').existsSync(), true);
62 63 64 65
    expect(fs.file(r'C:\windows\flutter\flutter_windows_glfw.dll').existsSync(), true);
    expect(fs.file(r'C:\windows\flutter\flutter_windows_glfw.dll.exp').existsSync(), true);
    expect(fs.file(r'C:\windows\flutter\flutter_windows_glfw.dll.lib').existsSync(), true);
    expect(fs.file(r'C:\windows\flutter\flutter_windows_glfw.dll.pdb').existsSync(), true);
66 67 68 69 70
    expect(fs.file(r'C:\windows\flutter\flutter_export.h').existsSync(), true);
    expect(fs.file(r'C:\windows\flutter\flutter_messenger.h').existsSync(), true);
    expect(fs.file(r'C:\windows\flutter\flutter_plugin_registrar.h').existsSync(), true);
    expect(fs.file(r'C:\windows\flutter\flutter_glfw.h').existsSync(), true);
    expect(fs.file(r'C:\windows\flutter\icudtl.dat').existsSync(), true);
71
    expect(fs.file(r'C:\windows\flutter\cpp_client_wrapper_glfw\foo').existsSync(), true);
72
  }));
73

74 75 76 77 78 79 80
  test('Does not re-copy files unecessarily', () => testbed.run(() async {
    await buildSystem.build(const UnpackWindows(), environment);
    // Set a date in the far distant past to deal with the limited resolution
    // of the windows filesystem.
    final DateTime theDistantPast = DateTime(1991, 8, 23);
    fs.file(r'C:\windows\flutter\flutter_export.h').setLastModifiedSync(theDistantPast);
    await buildSystem.build(const UnpackWindows(), environment);
81

82 83
    expect(fs.file(r'C:\windows\flutter\flutter_export.h').statSync().modified, equals(theDistantPast));
  }));
84

85 86 87 88 89 90 91 92
  test('Detects changes in input cache files', () => testbed.run(() async {
    await buildSystem.build(const UnpackWindows(), environment);
    // Set a date in the far distant past to deal with the limited resolution
    // of the windows filesystem.
    final DateTime theDistantPast = DateTime(1991, 8, 23);
    fs.file(r'C:\windows\flutter\flutter_export.h').setLastModifiedSync(theDistantPast);
    final DateTime modified = fs.file(r'C:\windows\flutter\flutter_export.h').statSync().modified;
    fs.file(r'C:\bin\cache\artifacts\engine\windows-x64\flutter_export.h').writeAsStringSync('asd'); // modify cache.
93

94
    await buildSystem.build(const UnpackWindows(), environment);
95

96 97
    expect(fs.file(r'C:\windows\flutter\flutter_export.h').statSync().modified, isNot(modified));
  }));
98 99 100
}

class MockPlatform extends Mock implements Platform {}