mirror of
https://github.com/flutter/packages.git
synced 2025-08-06 00:42:13 +08:00
[flutter_plugin_tool] Add more failure test coverage (#4132)
Many commands had insufficient failure testing. This adds new tests that ensure that for every Process call, at least one test fails if a failure from that process were ignored (with the exception of calls in the `publish` command, which has a custom process mocking system, so was out of scope here; it already has more coverage than most tests did though.) For a few existing failure tests, adds output checks to ensure that they are testing for the *right* failures. Other changes: - Adds convenience constructors to MockProcess for the common cases of a mock process that just exits with a 0 or 1 status, to reduce test verbosity. - Fixes a few bugs that were found by the new tests. - Minor test cleanup, especially cases where a mock process was being set up just to make all calls succeed, which is the default as of recent changes.
This commit is contained in:
@ -46,10 +46,10 @@ void main() {
|
||||
createFakePlugin('plugin_tools_test_package_b', packagesDir);
|
||||
|
||||
processRunner.processesToReturn.add(
|
||||
MockProcess()..exitCodeCompleter.complete(0),
|
||||
MockProcess.succeeding(),
|
||||
);
|
||||
processRunner.processesToReturn.add(
|
||||
MockProcess()..exitCodeCompleter.complete(0),
|
||||
MockProcess.succeeding(),
|
||||
);
|
||||
await runCapturingPrint(runner, <String>['publish-check']);
|
||||
|
||||
@ -70,10 +70,9 @@ void main() {
|
||||
test('fail on negative test', () async {
|
||||
createFakePlugin('plugin_tools_test_package_a', packagesDir);
|
||||
|
||||
final MockProcess process = MockProcess();
|
||||
final MockProcess process = MockProcess.failing();
|
||||
process.stdoutController.close(); // ignore: unawaited_futures
|
||||
process.stderrController.close(); // ignore: unawaited_futures
|
||||
process.exitCodeCompleter.complete(1);
|
||||
|
||||
processRunner.processesToReturn.add(process);
|
||||
|
||||
@ -100,13 +99,11 @@ void main() {
|
||||
const String preReleaseOutput = 'Package has 1 warning.'
|
||||
'Packages with an SDK constraint on a pre-release of the Dart SDK should themselves be published as a pre-release version.';
|
||||
|
||||
final MockProcess process = MockProcess();
|
||||
final MockProcess process = MockProcess.failing();
|
||||
process.stdoutController.add(preReleaseOutput.codeUnits);
|
||||
process.stdoutController.close(); // ignore: unawaited_futures
|
||||
process.stderrController.close(); // ignore: unawaited_futures
|
||||
|
||||
process.exitCodeCompleter.complete(1);
|
||||
|
||||
processRunner.processesToReturn.add(process);
|
||||
|
||||
expect(
|
||||
@ -121,13 +118,11 @@ void main() {
|
||||
const String preReleaseOutput = 'Package has 1 warning.'
|
||||
'Packages with an SDK constraint on a pre-release of the Dart SDK should themselves be published as a pre-release version.';
|
||||
|
||||
final MockProcess process = MockProcess();
|
||||
final MockProcess process = MockProcess.failing();
|
||||
process.stdoutController.add(preReleaseOutput.codeUnits);
|
||||
process.stdoutController.close(); // ignore: unawaited_futures
|
||||
process.stderrController.close(); // ignore: unawaited_futures
|
||||
|
||||
process.exitCodeCompleter.complete(1);
|
||||
|
||||
processRunner.processesToReturn.add(process);
|
||||
|
||||
expect(runCapturingPrint(runner, <String>['publish-check']),
|
||||
@ -139,13 +134,11 @@ void main() {
|
||||
|
||||
const String publishOutput = 'Package has 0 warnings.';
|
||||
|
||||
final MockProcess process = MockProcess();
|
||||
final MockProcess process = MockProcess.succeeding();
|
||||
process.stderrController.add(publishOutput.codeUnits);
|
||||
process.stdoutController.close(); // ignore: unawaited_futures
|
||||
process.stderrController.close(); // ignore: unawaited_futures
|
||||
|
||||
process.exitCodeCompleter.complete(0);
|
||||
|
||||
processRunner.processesToReturn.add(process);
|
||||
|
||||
final List<String> output =
|
||||
@ -195,7 +188,7 @@ void main() {
|
||||
createFakePlugin('no_publish_b', packagesDir, version: '0.2.0');
|
||||
|
||||
processRunner.processesToReturn.add(
|
||||
MockProcess()..exitCodeCompleter.complete(0),
|
||||
MockProcess.succeeding(),
|
||||
);
|
||||
final List<String> output = await runCapturingPrint(
|
||||
runner, <String>['publish-check', '--machine']);
|
||||
@ -261,7 +254,7 @@ void main() {
|
||||
createFakePlugin('no_publish_b', packagesDir, version: '0.2.0');
|
||||
|
||||
processRunner.processesToReturn.add(
|
||||
MockProcess()..exitCodeCompleter.complete(0),
|
||||
MockProcess.succeeding(),
|
||||
);
|
||||
|
||||
final List<String> output = await runCapturingPrint(
|
||||
@ -334,7 +327,7 @@ void main() {
|
||||
await plugin1Dir.childFile('pubspec.yaml').writeAsString('bad-yaml');
|
||||
|
||||
processRunner.processesToReturn.add(
|
||||
MockProcess()..exitCodeCompleter.complete(0),
|
||||
MockProcess.succeeding(),
|
||||
);
|
||||
|
||||
bool hasError = false;
|
||||
|
Reference in New Issue
Block a user