2019-04-26 19:33:41 +00:00
|
|
|
// 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:flutter_tools/src/base/file_system.dart';
|
|
|
|
import 'package:flutter_tools/src/compile.dart';
|
|
|
|
import 'package:flutter_tools/src/project.dart';
|
|
|
|
import 'package:flutter_tools/src/test/test_compiler.dart';
|
|
|
|
import 'package:mockito/mockito.dart';
|
|
|
|
|
2019-07-13 18:51:44 +00:00
|
|
|
import '../src/common.dart';
|
|
|
|
import '../src/testbed.dart';
|
2019-04-26 19:33:41 +00:00
|
|
|
|
|
|
|
void main() {
|
2019-04-30 22:42:16 +00:00
|
|
|
group(TestCompiler, () {
|
|
|
|
Testbed testbed;
|
|
|
|
FakeTestCompiler testCompiler;
|
|
|
|
MockResidentCompiler residentCompiler;
|
|
|
|
|
|
|
|
setUp(() {
|
|
|
|
testbed = Testbed(
|
2019-05-20 19:51:57 +00:00
|
|
|
setup: () async {
|
2019-04-30 22:42:16 +00:00
|
|
|
fs.file('pubspec.yaml').createSync();
|
|
|
|
fs.file('.packages').createSync();
|
|
|
|
fs.file('test/foo.dart').createSync(recursive: true);
|
|
|
|
residentCompiler = MockResidentCompiler();
|
|
|
|
testCompiler = FakeTestCompiler(
|
|
|
|
false,
|
|
|
|
FlutterProject.current(),
|
|
|
|
residentCompiler,
|
|
|
|
);
|
|
|
|
},
|
2019-04-26 19:33:41 +00:00
|
|
|
);
|
2019-04-30 22:42:16 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
test('Reports a dill file when compile is successful', () => testbed.run(() async {
|
2019-04-26 19:33:41 +00:00
|
|
|
when(residentCompiler.recompile(
|
|
|
|
'test/foo.dart',
|
|
|
|
<Uri>[Uri.parse('test/foo.dart')],
|
|
|
|
outputPath: testCompiler.outputDill.path,
|
|
|
|
)).thenAnswer((Invocation invocation) async {
|
|
|
|
fs.file('abc.dill').createSync();
|
2019-04-29 23:02:42 +00:00
|
|
|
return const CompilerOutput('abc.dill', 0, <Uri>[]);
|
2019-04-26 19:33:41 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
expect(await testCompiler.compile('test/foo.dart'), 'test/foo.dart.dill');
|
|
|
|
expect(fs.file('test/foo.dart.dill').existsSync(), true);
|
2019-04-30 22:42:16 +00:00
|
|
|
}));
|
2019-04-26 19:33:41 +00:00
|
|
|
|
2019-04-30 22:42:16 +00:00
|
|
|
test('Reports null when a compile fails', () => testbed.run(() async {
|
2019-04-26 19:33:41 +00:00
|
|
|
when(residentCompiler.recompile(
|
|
|
|
'test/foo.dart',
|
|
|
|
<Uri>[Uri.parse('test/foo.dart')],
|
|
|
|
outputPath: testCompiler.outputDill.path,
|
|
|
|
)).thenAnswer((Invocation invocation) async {
|
|
|
|
fs.file('abc.dill').createSync();
|
2019-04-29 23:02:42 +00:00
|
|
|
return const CompilerOutput('abc.dill', 1, <Uri>[]);
|
2019-04-26 19:33:41 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
expect(await testCompiler.compile('test/foo.dart'), null);
|
|
|
|
expect(fs.file('test/foo.dart.dill').existsSync(), false);
|
2019-06-18 18:24:19 +00:00
|
|
|
verify(residentCompiler.shutdown()).called(1);
|
|
|
|
}));
|
|
|
|
|
|
|
|
test('Disposing test compiler shuts down backing compiler', () => testbed.run(() async {
|
|
|
|
testCompiler.compiler = residentCompiler;
|
|
|
|
expect(testCompiler.compilerController.isClosed, false);
|
|
|
|
await testCompiler.dispose();
|
|
|
|
expect(testCompiler.compilerController.isClosed, true);
|
|
|
|
verify(residentCompiler.shutdown()).called(1);
|
2019-04-30 22:42:16 +00:00
|
|
|
}));
|
2019-04-26 19:33:41 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Override the creation of the Resident Compiler to simplify testing.
|
|
|
|
class FakeTestCompiler extends TestCompiler {
|
|
|
|
FakeTestCompiler(
|
|
|
|
bool trackWidgetCreation,
|
|
|
|
FlutterProject flutterProject,
|
|
|
|
this.residentCompiler,
|
|
|
|
) : super(trackWidgetCreation, flutterProject);
|
|
|
|
|
|
|
|
final MockResidentCompiler residentCompiler;
|
|
|
|
|
|
|
|
@override
|
|
|
|
Future<ResidentCompiler> createCompiler() async {
|
|
|
|
return residentCompiler;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class MockResidentCompiler extends Mock implements ResidentCompiler {}
|