Unverified Commit 06a20be5 authored by Jenn Magder's avatar Jenn Magder Committed by GitHub

Remove MockBuildSystem from generate_synthetic_packages_test (#77983)

parent 82675474
...@@ -95,14 +95,14 @@ void main() { ...@@ -95,14 +95,14 @@ void main() {
group('Gradle', () { group('Gradle', () {
Directory tempDir; Directory tempDir;
FakeProcessManager processManager; FakeProcessManager processManager;
FakeAndroidSdk mockAndroidSdk; FakeAndroidSdk fakeAndroidSdk;
TestUsage testUsage; TestUsage testUsage;
setUp(() { setUp(() {
testUsage = TestUsage(); testUsage = TestUsage();
tempDir = globals.fs.systemTempDirectory.createTempSync('flutter_tools_packages_test.'); tempDir = globals.fs.systemTempDirectory.createTempSync('flutter_tools_packages_test.');
processManager = FakeProcessManager.any(); processManager = FakeProcessManager.any();
mockAndroidSdk = FakeAndroidSdk(globals.fs.directory('irrelevant')); fakeAndroidSdk = FakeAndroidSdk(globals.fs.directory('irrelevant'));
}); });
tearDown(() { tearDown(() {
...@@ -169,7 +169,7 @@ void main() { ...@@ -169,7 +169,7 @@ void main() {
)); ));
}, },
overrides: <Type, Generator>{ overrides: <Type, Generator>{
AndroidSdk: () => mockAndroidSdk, AndroidSdk: () => fakeAndroidSdk,
FlutterProjectFactory: () => FakeFlutterProjectFactory(tempDir), FlutterProjectFactory: () => FakeFlutterProjectFactory(tempDir),
ProcessManager: () => processManager, ProcessManager: () => processManager,
Usage: () => testUsage, Usage: () => testUsage,
...@@ -209,7 +209,7 @@ void main() { ...@@ -209,7 +209,7 @@ void main() {
)); ));
}, },
overrides: <Type, Generator>{ overrides: <Type, Generator>{
AndroidSdk: () => mockAndroidSdk, AndroidSdk: () => fakeAndroidSdk,
FlutterProjectFactory: () => FakeFlutterProjectFactory(tempDir), FlutterProjectFactory: () => FakeFlutterProjectFactory(tempDir),
ProcessManager: () => processManager, ProcessManager: () => processManager,
Usage: () => testUsage, Usage: () => testUsage,
......
...@@ -4,6 +4,8 @@ ...@@ -4,6 +4,8 @@
// @dart = 2.8 // @dart = 2.8
import 'dart:async';
import 'package:file/memory.dart'; import 'package:file/memory.dart';
import 'package:flutter_tools/src/artifacts.dart'; import 'package:flutter_tools/src/artifacts.dart';
import 'package:flutter_tools/src/base/file_system.dart'; import 'package:flutter_tools/src/base/file_system.dart';
...@@ -11,11 +13,11 @@ import 'package:flutter_tools/src/base/logger.dart'; ...@@ -11,11 +13,11 @@ import 'package:flutter_tools/src/base/logger.dart';
import 'package:flutter_tools/src/dart/generate_synthetic_packages.dart'; import 'package:flutter_tools/src/dart/generate_synthetic_packages.dart';
import 'package:flutter_tools/src/build_system/build_system.dart'; import 'package:flutter_tools/src/build_system/build_system.dart';
import 'package:flutter_tools/src/build_system/targets/localizations.dart'; import 'package:flutter_tools/src/build_system/targets/localizations.dart';
import 'package:mockito/mockito.dart';
import '../../src/common.dart'; import '../../src/common.dart';
import '../../src/context.dart'; import '../../src/context.dart';
import '../../src/fake_process_manager.dart'; import '../../src/fake_process_manager.dart';
import '../../src/fakes.dart';
void main() { void main() {
testWithoutContext('calls buildSystem.build with blank l10n.yaml file', () async { testWithoutContext('calls buildSystem.build with blank l10n.yaml file', () async {
...@@ -42,7 +44,15 @@ void main() { ...@@ -42,7 +44,15 @@ void main() {
artifacts: artifacts, artifacts: artifacts,
processManager: FakeProcessManager.any(), processManager: FakeProcessManager.any(),
); );
final BuildSystem buildSystem = MockBuildSystem(); final Completer<void> completer = Completer<void>();
final BuildResult exception = BuildResult(success: false, exceptions: <String, ExceptionMeasurement>{
'hello': ExceptionMeasurement('hello', 'bar', null),
});
final TestBuildSystem buildSystem = TestBuildSystem.all(exception, (Target target, Environment environment) {
expect(target, const GenerateLocalizationsTarget());
expect(environment, environment);
completer.complete();
});
await expectLater( await expectLater(
() => generateLocalizationsSyntheticPackage( () => generateLocalizationsSyntheticPackage(
...@@ -51,11 +61,7 @@ void main() { ...@@ -51,11 +61,7 @@ void main() {
), ),
throwsToolExit(message: 'Generating synthetic localizations package has failed.'), throwsToolExit(message: 'Generating synthetic localizations package has failed.'),
); );
// [BuildSystem] should have called build with [GenerateLocalizationsTarget]. await completer.future;
verify(buildSystem.build(
const GenerateLocalizationsTarget(),
environment,
)).called(1);
}); });
testWithoutContext('calls buildSystem.build with l10n.yaml synthetic-package: true', () async { testWithoutContext('calls buildSystem.build with l10n.yaml synthetic-package: true', () async {
...@@ -83,7 +89,15 @@ void main() { ...@@ -83,7 +89,15 @@ void main() {
artifacts: artifacts, artifacts: artifacts,
processManager: fakeProcessManager, processManager: fakeProcessManager,
); );
final BuildSystem buildSystem = MockBuildSystem(); final Completer<void> completer = Completer<void>();
final BuildResult exception = BuildResult(success: false, exceptions: <String, ExceptionMeasurement>{
'hello': ExceptionMeasurement('hello', 'bar', null),
});
final TestBuildSystem buildSystem = TestBuildSystem.all(exception, (Target target, Environment environment) {
expect(target, const GenerateLocalizationsTarget());
expect(environment, environment);
completer.complete();
});
await expectLater( await expectLater(
() => generateLocalizationsSyntheticPackage( () => generateLocalizationsSyntheticPackage(
...@@ -92,11 +106,7 @@ void main() { ...@@ -92,11 +106,7 @@ void main() {
), ),
throwsToolExit(message: 'Generating synthetic localizations package has failed.'), throwsToolExit(message: 'Generating synthetic localizations package has failed.'),
); );
// [BuildSystem] should have called build with [GenerateLocalizationsTarget]. await completer.future;
verify(buildSystem.build(
const GenerateLocalizationsTarget(),
environment,
)).called(1);
}); });
testWithoutContext('calls buildSystem.build with l10n.yaml synthetic-package: null', () async { testWithoutContext('calls buildSystem.build with l10n.yaml synthetic-package: null', () async {
...@@ -122,7 +132,15 @@ void main() { ...@@ -122,7 +132,15 @@ void main() {
artifacts: Artifacts.test(), artifacts: Artifacts.test(),
processManager: FakeProcessManager.any(), processManager: FakeProcessManager.any(),
); );
final BuildSystem buildSystem = MockBuildSystem(); final Completer<void> completer = Completer<void>();
final BuildResult exception = BuildResult(success: false, exceptions: <String, ExceptionMeasurement>{
'hello': ExceptionMeasurement('hello', 'bar', null),
});
final TestBuildSystem buildSystem = TestBuildSystem.all(exception, (Target target, Environment environment) {
expect(target, const GenerateLocalizationsTarget());
expect(environment, environment);
completer.complete();
});
await expectLater( await expectLater(
() => generateLocalizationsSyntheticPackage( () => generateLocalizationsSyntheticPackage(
...@@ -131,11 +149,7 @@ void main() { ...@@ -131,11 +149,7 @@ void main() {
), ),
throwsToolExit(message: 'Generating synthetic localizations package has failed.'), throwsToolExit(message: 'Generating synthetic localizations package has failed.'),
); );
// [BuildSystem] should have called build with [GenerateLocalizationsTarget]. await completer.future;
verify(buildSystem.build(
const GenerateLocalizationsTarget(),
environment,
)).called(1);
}); });
testWithoutContext('does not call buildSystem.build when l10n.yaml is not present', () async { testWithoutContext('does not call buildSystem.build when l10n.yaml is not present', () async {
...@@ -158,17 +172,13 @@ void main() { ...@@ -158,17 +172,13 @@ void main() {
artifacts: Artifacts.test(), artifacts: Artifacts.test(),
processManager: FakeProcessManager.any(), processManager: FakeProcessManager.any(),
); );
final BuildSystem buildSystem = MockBuildSystem(); // Will throw if build is called.
final TestBuildSystem buildSystem = TestBuildSystem.all(null);
await generateLocalizationsSyntheticPackage( await generateLocalizationsSyntheticPackage(
environment: environment, environment: environment,
buildSystem: buildSystem, buildSystem: buildSystem,
); );
// [BuildSystem] should not be called with [GenerateLocalizationsTarget].
verifyNever(buildSystem.build(
const GenerateLocalizationsTarget(),
environment,
));
}); });
testWithoutContext('does not call buildSystem.build with incorrect l10n.yaml format', () async { testWithoutContext('does not call buildSystem.build with incorrect l10n.yaml format', () async {
...@@ -194,7 +204,8 @@ void main() { ...@@ -194,7 +204,8 @@ void main() {
artifacts: Artifacts.test(), artifacts: Artifacts.test(),
processManager: FakeProcessManager.any(), processManager: FakeProcessManager.any(),
); );
final BuildSystem buildSystem = MockBuildSystem(); // Will throw if build is called.
final TestBuildSystem buildSystem = TestBuildSystem.all(null);
await expectLater( await expectLater(
() => generateLocalizationsSyntheticPackage( () => generateLocalizationsSyntheticPackage(
...@@ -203,11 +214,6 @@ void main() { ...@@ -203,11 +214,6 @@ void main() {
), ),
throwsToolExit(message: 'to contain a map, instead was helloWorld'), throwsToolExit(message: 'to contain a map, instead was helloWorld'),
); );
// [BuildSystem] should not be called with [GenerateLocalizationsTarget].
verifyNever(buildSystem.build(
const GenerateLocalizationsTarget(),
environment,
));
}); });
testWithoutContext('does not call buildSystem.build with non-bool "synthetic-package" value', () async { testWithoutContext('does not call buildSystem.build with non-bool "synthetic-package" value', () async {
...@@ -233,7 +239,8 @@ void main() { ...@@ -233,7 +239,8 @@ void main() {
artifacts: Artifacts.test(), artifacts: Artifacts.test(),
processManager: FakeProcessManager.any(), processManager: FakeProcessManager.any(),
); );
final BuildSystem buildSystem = MockBuildSystem(); // Will throw if build is called.
final TestBuildSystem buildSystem = TestBuildSystem.all(null);
await expectLater( await expectLater(
() => generateLocalizationsSyntheticPackage( () => generateLocalizationsSyntheticPackage(
...@@ -242,12 +249,5 @@ void main() { ...@@ -242,12 +249,5 @@ void main() {
), ),
throwsToolExit(message: 'to have a bool value, instead was "nonBoolValue"'), throwsToolExit(message: 'to have a bool value, instead was "nonBoolValue"'),
); );
// [BuildSystem] should not be called with [GenerateLocalizationsTarget].
verifyNever(buildSystem.build(
const GenerateLocalizationsTarget(),
environment,
));
}); });
} }
class MockBuildSystem extends Mock implements BuildSystem {}
...@@ -660,7 +660,7 @@ class TestBuildSystem implements BuildSystem { ...@@ -660,7 +660,7 @@ class TestBuildSystem implements BuildSystem {
return _singleResult; return _singleResult;
} }
if (_nextResult >= _results.length) { if (_nextResult >= _results.length) {
throw StateError('Unexpected buildIncremental request of ${target.name}'); throw StateError('Unexpected build request of ${target.name}');
} }
return _results[_nextResult++]; return _results[_nextResult++];
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment