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

5
import 'package:platform/platform.dart';
6 7
import 'package:flutter_tools/src/base/file_system.dart';
import 'package:flutter_tools/src/build_system/build_system.dart';
8
import 'package:flutter_tools/src/build_system/targets/dart.dart';
9 10
import 'package:flutter_tools/src/build_system/targets/linux.dart';
import 'package:flutter_tools/src/cache.dart';
11
import 'package:flutter_tools/src/globals.dart' as globals;
12 13
import 'package:mockito/mockito.dart';

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

void main() {
18 19 20 21
  Testbed testbed;
  const BuildSystem buildSystem = BuildSystem();
  Environment environment;
  MockPlatform mockPlatform;
22

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

28 29 30 31 32
  setUp(() {
    mockPlatform = MockPlatform();
    when(mockPlatform.isWindows).thenReturn(false);
    when(mockPlatform.isMacOS).thenReturn(false);
    when(mockPlatform.isLinux).thenReturn(true);
33
    when(mockPlatform.environment).thenReturn(Map<String, String>.unmodifiable(<String, String>{}));
34 35
    testbed = Testbed(setup: () {
      Cache.flutterRoot = '';
36 37
      environment = Environment.test(
        globals.fs.currentDirectory,
38 39 40
        defines: <String, String>{
          kBuildMode: 'debug',
        }
41
      );
42 43 44 45 46 47 48 49 50 51
      globals.fs.file('bin/cache/artifacts/engine/linux-x64/unrelated-stuff').createSync(recursive: true);
      globals.fs.file('bin/cache/artifacts/engine/linux-x64/libflutter_linux_glfw.so').createSync(recursive: true);
      globals.fs.file('bin/cache/artifacts/engine/linux-x64/flutter_export.h').createSync();
      globals.fs.file('bin/cache/artifacts/engine/linux-x64/flutter_messenger.h').createSync();
      globals.fs.file('bin/cache/artifacts/engine/linux-x64/flutter_plugin_registrar.h').createSync();
      globals.fs.file('bin/cache/artifacts/engine/linux-x64/flutter_glfw.h').createSync();
      globals.fs.file('bin/cache/artifacts/engine/linux-x64/icudtl.dat').createSync();
      globals.fs.file('bin/cache/artifacts/engine/linux-x64/cpp_client_wrapper_glfw/foo').createSync(recursive: true);
      globals.fs.file('packages/flutter_tools/lib/src/build_system/targets/linux.dart').createSync(recursive: true);
      globals.fs.directory('linux').createSync();
52 53
    }, overrides: <Type, Generator>{
      Platform: () => mockPlatform,
54
    });
55
  });
56

57
  test('Copies files to correct cache directory, excluding unrelated code', () => testbed.run(() async {
58
    final BuildResult result = await buildSystem.build(const UnpackLinuxDebug(), environment);
59

60
    expect(result.hasException, false);
61 62 63 64 65 66 67 68
    expect(globals.fs.file('linux/flutter/ephemeral/libflutter_linux_glfw.so').existsSync(), true);
    expect(globals.fs.file('linux/flutter/ephemeral/flutter_export.h').existsSync(), true);
    expect(globals.fs.file('linux/flutter/ephemeral/flutter_messenger.h').existsSync(), true);
    expect(globals.fs.file('linux/flutter/ephemeral/flutter_plugin_registrar.h').existsSync(), true);
    expect(globals.fs.file('linux/flutter/ephemeral/flutter_glfw.h').existsSync(), true);
    expect(globals.fs.file('linux/flutter/ephemeral/icudtl.dat').existsSync(), true);
    expect(globals.fs.file('linux/flutter/ephemeral/cpp_client_wrapper_glfw/foo').existsSync(), true);
    expect(globals.fs.file('linux/flutter/ephemeral/unrelated-stuff').existsSync(), false);
69
  }));
70

71
  test('Does not re-copy files unecessarily', () => testbed.run(() async {
72
    await buildSystem.build(const UnpackLinuxDebug(), environment);
73 74 75
    // 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);
76
    globals.fs.file('linux/flutter/ephemeral/libflutter_linux_glfw.so').setLastModifiedSync(theDistantPast);
77
    await buildSystem.build(const UnpackLinuxDebug(), environment);
78

79
    expect(globals.fs.file('linux/flutter/ephemeral/libflutter_linux_glfw.so').statSync().modified, equals(theDistantPast));
80
  }));
81

82
  test('Detects changes in input cache files', () => testbed.run(() async {
83
    await buildSystem.build(const UnpackLinuxDebug(), environment);
84
    globals.fs.file('bin/cache/artifacts/engine/linux-x64/libflutter_linux_glfw.so').writeAsStringSync('asd'); // modify cache.
85

86
    await buildSystem.build(const UnpackLinuxDebug(), environment);
87

88
    expect(globals.fs.file('linux/flutter/ephemeral/libflutter_linux_glfw.so').readAsStringSync(), 'asd');
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103
  }));

  test('Copies artifacts to out directory', () => testbed.run(() async {
    environment.buildDir.createSync(recursive: true);

    // Create input files.
    environment.buildDir.childFile('app.dill').createSync();

    await const DebugBundleLinuxAssets().build(environment);
    final Directory output = environment.outputDir
      .childDirectory('flutter_assets');

    expect(output.childFile('kernel_blob.bin').existsSync(), true);
    expect(output.childFile('FontManifest.json').existsSync(), false);
    expect(output.childFile('AssetManifest.json').existsSync(), true);
104
  }));
105 106 107
}

class MockPlatform extends Mock implements Platform {}