From 7caef218b55acac803aa67e7393e97f75ec70c5c Mon Sep 17 00:00:00 2001 From: Jonah Williams Date: Tue, 12 Nov 2019 15:35:59 -0800 Subject: [PATCH] refactorings to testbed.run and testbed.test (#44488) --- .../hermetic/assemble_test.dart | 39 ++++++++----------- 1 file changed, 16 insertions(+), 23 deletions(-) diff --git a/packages/flutter_tools/test/commands.shard/hermetic/assemble_test.dart b/packages/flutter_tools/test/commands.shard/hermetic/assemble_test.dart index cb1dd10b755..176cb51e24e 100644 --- a/packages/flutter_tools/test/commands.shard/hermetic/assemble_test.dart +++ b/packages/flutter_tools/test/commands.shard/hermetic/assemble_test.dart @@ -16,20 +16,14 @@ import '../../src/common.dart'; import '../../src/testbed.dart'; void main() { - Testbed testbed; - MockBuildSystem mockBuildSystem; Cache.disableLocking(); - - setUp(() { - mockBuildSystem = MockBuildSystem(); - testbed = Testbed(overrides: { - BuildSystem: () => mockBuildSystem, - Cache: () => FakeCache(), - }); + final Testbed testbed = Testbed(overrides: { + BuildSystem: () => MockBuildSystem(), + Cache: () => FakeCache(), }); - test('Can run a build', () => testbed.run(() async { - when(mockBuildSystem.build(any, any, buildSystemConfig: anyNamed('buildSystemConfig'))) + testbed.test('Can run a build', () async { + when(buildSystem.build(any, any, buildSystemConfig: anyNamed('buildSystemConfig'))) .thenAnswer((Invocation invocation) async { return BuildResult(success: true); }); @@ -38,30 +32,30 @@ void main() { final BufferLogger bufferLogger = logger; expect(bufferLogger.traceText, contains('build succeeded.')); - })); + }); - test('Throws ToolExit if not provided with output', () => testbed.run(() async { - when(mockBuildSystem.build(any, any, buildSystemConfig: anyNamed('buildSystemConfig'))) + testbed.test('Throws ToolExit if not provided with output', () async { + when(buildSystem.build(any, any, buildSystemConfig: anyNamed('buildSystemConfig'))) .thenAnswer((Invocation invocation) async { return BuildResult(success: true); }); final CommandRunner commandRunner = createTestCommandRunner(AssembleCommand()); expect(commandRunner.run(['assemble', 'debug_macos_bundle_flutter_assets']), throwsA(isInstanceOf())); - })); + }); - test('Throws ToolExit if called with non-existent rule', () => testbed.run(() async { - when(mockBuildSystem.build(any, any, buildSystemConfig: anyNamed('buildSystemConfig'))) + testbed.test('Throws ToolExit if called with non-existent rule', () async { + when(buildSystem.build(any, any, buildSystemConfig: anyNamed('buildSystemConfig'))) .thenAnswer((Invocation invocation) async { return BuildResult(success: true); }); final CommandRunner commandRunner = createTestCommandRunner(AssembleCommand()); expect(commandRunner.run(['assemble', '-o Output', 'undefined']), throwsA(isInstanceOf())); - })); + }); - test('Only writes input and output files when the values change', () => testbed.run(() async { - when(mockBuildSystem.build(any, any, buildSystemConfig: anyNamed('buildSystemConfig'))) + testbed.test('Only writes input and output files when the values change', () async { + when(buildSystem.build(any, any, buildSystemConfig: anyNamed('buildSystemConfig'))) .thenAnswer((Invocation invocation) async { return BuildResult( success: true, @@ -86,8 +80,7 @@ void main() { expect(inputs.lastModifiedSync(), theDistantPast); expect(outputs.lastModifiedSync(), theDistantPast); - - when(mockBuildSystem.build(any, any, buildSystemConfig: anyNamed('buildSystemConfig'))) + when(buildSystem.build(any, any, buildSystemConfig: anyNamed('buildSystemConfig'))) .thenAnswer((Invocation invocation) async { return BuildResult( success: true, @@ -99,7 +92,7 @@ void main() { expect(inputs.readAsStringSync(), contains('foo')); expect(inputs.readAsStringSync(), contains('fizz')); expect(inputs.lastModifiedSync(), isNot(theDistantPast)); - })); + }); } class MockBuildSystem extends Mock implements BuildSystem {}