windows_test.dart 5.5 KB
Newer Older
Ian Hickson's avatar
Ian Hickson committed
1
// Copyright 2014 The Flutter Authors. All rights reserved.
2 3 4 5 6
// 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';
7

8 9 10
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';
11
import 'package:flutter_tools/src/globals.dart' as globals;
12
import 'package:mockito/mockito.dart';
13
import 'package:platform/platform.dart';
14

15
import '../../../src/common.dart';
16
import '../../../src/fake_process_manager.dart';
17
import '../../../src/testbed.dart';
18 19

void main() {
20 21 22 23
  Testbed testbed;
  const BuildSystem buildSystem = BuildSystem();
  Environment environment;
  Platform platform;
24

25 26 27 28
  setUpAll(() {
    Cache.disableLocking();
    Cache.flutterRoot = '';
  });
29

30 31 32 33 34 35 36
  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: () {
37 38
      environment = Environment.test(
        globals.fs.currentDirectory,
39
      );
40 41 42 43 44 45 46 47 48 49 50 51 52 53
      globals.fs.file(r'C:\bin\cache\artifacts\engine\windows-x64\flutter_export.h').createSync(recursive: true);
      globals.fs.file(r'C:\bin\cache\artifacts\engine\windows-x64\flutter_messenger.h').createSync();
      globals.fs.file(r'C:\bin\cache\artifacts\engine\windows-x64\flutter_windows.dll').createSync();
      globals.fs.file(r'C:\bin\cache\artifacts\engine\windows-x64\flutter_windows.dll.exp').createSync();
      globals.fs.file(r'C:\bin\cache\artifacts\engine\windows-x64\flutter_windows.dll.lib').createSync();
      globals.fs.file(r'C:\bin\cache\artifacts\engine\windows-x64\flutter_windows.dll.pdb').createSync();
      globals.fs.file(r'C:\bin\cache\artifacts\engine\windows-x64\lutter_export.h').createSync();
      globals.fs.file(r'C:\bin\cache\artifacts\engine\windows-x64\flutter_messenger.h').createSync();
      globals.fs.file(r'C:\bin\cache\artifacts\engine\windows-x64\flutter_plugin_registrar.h').createSync();
      globals.fs.file(r'C:\bin\cache\artifacts\engine\windows-x64\flutter_windows.h').createSync();
      globals.fs.file(r'C:\bin\cache\artifacts\engine\windows-x64\icudtl.dat').createSync();
      globals.fs.file(r'C:\bin\cache\artifacts\engine\windows-x64\cpp_client_wrapper\foo').createSync(recursive: true);
      globals.fs.file(r'C:\packages\flutter_tools\lib\src\build_system\targets\windows.dart').createSync(recursive: true);
      globals.fs.directory('windows').createSync();
54 55
    }, overrides: <Type, Generator>{
      FileSystem: () => MemoryFileSystem(style: FileSystemStyle.windows),
56
      ProcessManager: () => FakeProcessManager.any(),
57
      Platform: () => platform,
58
    });
59
  });
60

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

64 65 66 67 68 69 70 71 72 73 74 75
    expect(globals.fs.file(r'C:\windows\flutter\flutter_export.h').existsSync(), true);
    expect(globals.fs.file(r'C:\windows\flutter\flutter_messenger.h').existsSync(), true);
    expect(globals.fs.file(r'C:\windows\flutter\flutter_windows.dll').existsSync(), true);
    expect(globals.fs.file(r'C:\windows\flutter\flutter_windows.dll.exp').existsSync(), true);
    expect(globals.fs.file(r'C:\windows\flutter\flutter_windows.dll.lib').existsSync(), true);
    expect(globals.fs.file(r'C:\windows\flutter\flutter_windows.dll.pdb').existsSync(), true);
    expect(globals.fs.file(r'C:\windows\flutter\flutter_export.h').existsSync(), true);
    expect(globals.fs.file(r'C:\windows\flutter\flutter_messenger.h').existsSync(), true);
    expect(globals.fs.file(r'C:\windows\flutter\flutter_plugin_registrar.h').existsSync(), true);
    expect(globals.fs.file(r'C:\windows\flutter\flutter_windows.h').existsSync(), true);
    expect(globals.fs.file(r'C:\windows\flutter\icudtl.dat').existsSync(), true);
    expect(globals.fs.file(r'C:\windows\flutter\cpp_client_wrapper\foo').existsSync(), true);
76
  }));
77

78 79 80 81 82
  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);
83
    globals.fs.file(r'C:\windows\flutter\flutter_export.h').setLastModifiedSync(theDistantPast);
84
    await buildSystem.build(const UnpackWindows(), environment);
85

86
    expect(globals.fs.file(r'C:\windows\flutter\flutter_export.h').statSync().modified, equals(theDistantPast));
87
  }));
88

89 90 91 92 93
  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);
94 95 96
    globals.fs.file(r'C:\windows\flutter\flutter_export.h').setLastModifiedSync(theDistantPast);
    final DateTime modified = globals.fs.file(r'C:\windows\flutter\flutter_export.h').statSync().modified;
    globals.fs.file(r'C:\bin\cache\artifacts\engine\windows-x64\flutter_export.h').writeAsStringSync('asd'); // modify cache.
97

98
    await buildSystem.build(const UnpackWindows(), environment);
99

100
    expect(globals.fs.file(r'C:\windows\flutter\flutter_export.h').statSync().modified, isNot(modified));
101
  }));
102 103 104
}

class MockPlatform extends Mock implements Platform {}