mirror of
https://github.com/flutter/packages.git
synced 2025-05-31 21:48:04 +08:00

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.
61 lines
1.5 KiB
Dart
61 lines
1.5 KiB
Dart
// Copyright 2013 The Flutter Authors. All rights reserved.
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
// found in the LICENSE file.
|
|
|
|
import 'dart:async';
|
|
import 'dart:io' as io;
|
|
|
|
import 'package:file/file.dart';
|
|
import 'package:mockito/mockito.dart';
|
|
import 'package:platform/platform.dart';
|
|
|
|
class MockPlatform extends Mock implements Platform {
|
|
MockPlatform({this.isMacOS = false});
|
|
|
|
@override
|
|
bool isMacOS;
|
|
}
|
|
|
|
class MockProcess extends Mock implements io.Process {
|
|
MockProcess();
|
|
|
|
/// A mock process that terminates with exitCode 0.
|
|
MockProcess.succeeding() {
|
|
exitCodeCompleter.complete(0);
|
|
}
|
|
|
|
/// A mock process that terminates with exitCode 1.
|
|
MockProcess.failing() {
|
|
exitCodeCompleter.complete(1);
|
|
}
|
|
|
|
final Completer<int> exitCodeCompleter = Completer<int>();
|
|
final StreamController<List<int>> stdoutController =
|
|
StreamController<List<int>>();
|
|
final StreamController<List<int>> stderrController =
|
|
StreamController<List<int>>();
|
|
final MockIOSink stdinMock = MockIOSink();
|
|
|
|
@override
|
|
int get pid => 99;
|
|
|
|
@override
|
|
Future<int> get exitCode => exitCodeCompleter.future;
|
|
|
|
@override
|
|
Stream<List<int>> get stdout => stdoutController.stream;
|
|
|
|
@override
|
|
Stream<List<int>> get stderr => stderrController.stream;
|
|
|
|
@override
|
|
IOSink get stdin => stdinMock;
|
|
}
|
|
|
|
class MockIOSink extends Mock implements IOSink {
|
|
List<String> lines = <String>[];
|
|
|
|
@override
|
|
void writeln([Object? obj = '']) => lines.add(obj.toString());
|
|
}
|