Skip to content

Commit 7caef21

Browse files
author
Jonah Williams
authored
refactorings to testbed.run and testbed.test (flutter#44488)
1 parent 9acf105 commit 7caef21

File tree

1 file changed

+16
-23
lines changed

1 file changed

+16
-23
lines changed

packages/flutter_tools/test/commands.shard/hermetic/assemble_test.dart

Lines changed: 16 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -16,20 +16,14 @@ import '../../src/common.dart';
1616
import '../../src/testbed.dart';
1717

1818
void main() {
19-
Testbed testbed;
20-
MockBuildSystem mockBuildSystem;
2119
Cache.disableLocking();
22-
23-
setUp(() {
24-
mockBuildSystem = MockBuildSystem();
25-
testbed = Testbed(overrides: <Type, Generator>{
26-
BuildSystem: () => mockBuildSystem,
27-
Cache: () => FakeCache(),
28-
});
20+
final Testbed testbed = Testbed(overrides: <Type, Generator>{
21+
BuildSystem: () => MockBuildSystem(),
22+
Cache: () => FakeCache(),
2923
});
3024

31-
test('Can run a build', () => testbed.run(() async {
32-
when(mockBuildSystem.build(any, any, buildSystemConfig: anyNamed('buildSystemConfig')))
25+
testbed.test('Can run a build', () async {
26+
when(buildSystem.build(any, any, buildSystemConfig: anyNamed('buildSystemConfig')))
3327
.thenAnswer((Invocation invocation) async {
3428
return BuildResult(success: true);
3529
});
@@ -38,30 +32,30 @@ void main() {
3832
final BufferLogger bufferLogger = logger;
3933

4034
expect(bufferLogger.traceText, contains('build succeeded.'));
41-
}));
35+
});
4236

43-
test('Throws ToolExit if not provided with output', () => testbed.run(() async {
44-
when(mockBuildSystem.build(any, any, buildSystemConfig: anyNamed('buildSystemConfig')))
37+
testbed.test('Throws ToolExit if not provided with output', () async {
38+
when(buildSystem.build(any, any, buildSystemConfig: anyNamed('buildSystemConfig')))
4539
.thenAnswer((Invocation invocation) async {
4640
return BuildResult(success: true);
4741
});
4842
final CommandRunner<void> commandRunner = createTestCommandRunner(AssembleCommand());
4943

5044
expect(commandRunner.run(<String>['assemble', 'debug_macos_bundle_flutter_assets']), throwsA(isInstanceOf<ToolExit>()));
51-
}));
45+
});
5246

53-
test('Throws ToolExit if called with non-existent rule', () => testbed.run(() async {
54-
when(mockBuildSystem.build(any, any, buildSystemConfig: anyNamed('buildSystemConfig')))
47+
testbed.test('Throws ToolExit if called with non-existent rule', () async {
48+
when(buildSystem.build(any, any, buildSystemConfig: anyNamed('buildSystemConfig')))
5549
.thenAnswer((Invocation invocation) async {
5650
return BuildResult(success: true);
5751
});
5852
final CommandRunner<void> commandRunner = createTestCommandRunner(AssembleCommand());
5953

6054
expect(commandRunner.run(<String>['assemble', '-o Output', 'undefined']), throwsA(isInstanceOf<ToolExit>()));
61-
}));
55+
});
6256

63-
test('Only writes input and output files when the values change', () => testbed.run(() async {
64-
when(mockBuildSystem.build(any, any, buildSystemConfig: anyNamed('buildSystemConfig')))
57+
testbed.test('Only writes input and output files when the values change', () async {
58+
when(buildSystem.build(any, any, buildSystemConfig: anyNamed('buildSystemConfig')))
6559
.thenAnswer((Invocation invocation) async {
6660
return BuildResult(
6761
success: true,
@@ -86,8 +80,7 @@ void main() {
8680
expect(inputs.lastModifiedSync(), theDistantPast);
8781
expect(outputs.lastModifiedSync(), theDistantPast);
8882

89-
90-
when(mockBuildSystem.build(any, any, buildSystemConfig: anyNamed('buildSystemConfig')))
83+
when(buildSystem.build(any, any, buildSystemConfig: anyNamed('buildSystemConfig')))
9184
.thenAnswer((Invocation invocation) async {
9285
return BuildResult(
9386
success: true,
@@ -99,7 +92,7 @@ void main() {
9992
expect(inputs.readAsStringSync(), contains('foo'));
10093
expect(inputs.readAsStringSync(), contains('fizz'));
10194
expect(inputs.lastModifiedSync(), isNot(theDistantPast));
102-
}));
95+
});
10396
}
10497

10598
class MockBuildSystem extends Mock implements BuildSystem {}

0 commit comments

Comments
 (0)