mirror of
https://github.com/flutter/packages.git
synced 2025-08-06 17:28:42 +08:00
[flutter_plugin_tools] Migrate java-test to new base command (#4105)
Switches `java-test` to the new base command that handles the boilerplate of looping over target packages. Includes test improvements: - Adds failure tests; previously no failure cases were covered. - Captures output so test output isn't spammed with command output. Part of flutter/flutter#83413
This commit is contained in:
@ -11,6 +11,7 @@ import 'package:flutter_plugin_tools/src/java_test_command.dart';
|
||||
import 'package:path/path.dart' as p;
|
||||
import 'package:test/test.dart';
|
||||
|
||||
import 'mocks.dart';
|
||||
import 'util.dart';
|
||||
|
||||
void main() {
|
||||
@ -45,7 +46,7 @@ void main() {
|
||||
],
|
||||
);
|
||||
|
||||
await runner.run(<String>['java-test']);
|
||||
await runCapturingPrint(runner, <String>['java-test']);
|
||||
|
||||
expect(
|
||||
processRunner.recordedCalls,
|
||||
@ -72,7 +73,7 @@ void main() {
|
||||
],
|
||||
);
|
||||
|
||||
await runner.run(<String>['java-test']);
|
||||
await runCapturingPrint(runner, <String>['java-test']);
|
||||
|
||||
expect(
|
||||
processRunner.recordedCalls,
|
||||
@ -85,5 +86,70 @@ void main() {
|
||||
]),
|
||||
);
|
||||
});
|
||||
|
||||
test('fails when the app needs to be built', () async {
|
||||
createFakePlugin(
|
||||
'plugin1',
|
||||
packagesDir,
|
||||
platformSupport: <String, PlatformSupport>{
|
||||
kPlatformAndroid: PlatformSupport.inline
|
||||
},
|
||||
extraFiles: <String>[
|
||||
'example/android/app/src/test/example_test.java',
|
||||
],
|
||||
);
|
||||
|
||||
Error? commandError;
|
||||
final List<String> output = await runCapturingPrint(
|
||||
runner, <String>['java-test'], errorHandler: (Error e) {
|
||||
commandError = e;
|
||||
});
|
||||
|
||||
expect(commandError, isA<ToolExit>());
|
||||
|
||||
expect(
|
||||
output,
|
||||
containsAllInOrder(<Matcher>[
|
||||
contains('ERROR: Run "flutter build apk" on example'),
|
||||
contains('plugin1:\n'
|
||||
' example has not been built.')
|
||||
]),
|
||||
);
|
||||
});
|
||||
|
||||
test('fails when a test fails', () async {
|
||||
createFakePlugin(
|
||||
'plugin1',
|
||||
packagesDir,
|
||||
platformSupport: <String, PlatformSupport>{
|
||||
kPlatformAndroid: PlatformSupport.inline
|
||||
},
|
||||
extraFiles: <String>[
|
||||
'example/android/gradlew',
|
||||
'example/android/app/src/test/example_test.java',
|
||||
],
|
||||
);
|
||||
|
||||
// Simulate failure from `gradlew`.
|
||||
final MockProcess mockDriveProcess = MockProcess();
|
||||
mockDriveProcess.exitCodeCompleter.complete(1);
|
||||
processRunner.processToReturn = mockDriveProcess;
|
||||
|
||||
Error? commandError;
|
||||
final List<String> output = await runCapturingPrint(
|
||||
runner, <String>['java-test'], errorHandler: (Error e) {
|
||||
commandError = e;
|
||||
});
|
||||
|
||||
expect(commandError, isA<ToolExit>());
|
||||
|
||||
expect(
|
||||
output,
|
||||
containsAllInOrder(<Matcher>[
|
||||
contains('plugin1:\n'
|
||||
' example tests failed.')
|
||||
]),
|
||||
);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
Reference in New Issue
Block a user