[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:
stuartmorgan
2021-07-02 10:49:04 -07:00
committed by GitHub
parent 6fe9a8ef82
commit d2761ab1de
14 changed files with 557 additions and 220 deletions

View File

@ -52,8 +52,7 @@ void main() {
];
final String output = '''[${devices.join(',')}]''';
final MockProcess mockDevicesProcess = MockProcess();
mockDevicesProcess.exitCodeCompleter.complete(0);
final MockProcess mockDevicesProcess = MockProcess.succeeding();
mockDevicesProcess.stdoutController.close(); // ignore: unawaited_futures
processRunner.mockProcessesForExecutable['flutter'] = <io.Process>[
mockDevicesProcess
@ -115,12 +114,10 @@ void main() {
});
test('fails for iOS if getting devices fails', () async {
setMockFlutterDevicesOutput(hasIosDevice: false);
// Simulate failure from `flutter devices`.
final MockProcess mockProcess = MockProcess();
mockProcess.exitCodeCompleter.complete(1);
processRunner.processToReturn = mockProcess;
processRunner.mockProcessesForExecutable['flutter'] = <io.Process>[
MockProcess.failing()
];
Error? commandError;
final List<String> output = await runCapturingPrint(
@ -935,9 +932,11 @@ void main() {
);
// Simulate failure from `flutter drive`.
final MockProcess mockDriveProcess = MockProcess();
mockDriveProcess.exitCodeCompleter.complete(1);
processRunner.processToReturn = mockDriveProcess;
processRunner.mockProcessesForExecutable['flutter'] = <io.Process>[
// No mock for 'devices', since it's running for macOS.
MockProcess.failing(), // 'drive' #1
MockProcess.failing(), // 'drive' #2
];
Error? commandError;
final List<String> output =