Skip to content

Commit

Permalink
move check/exception into the launcher
Browse files Browse the repository at this point in the history
  • Loading branch information
jcollins-g committed Jun 7, 2021
1 parent e6e3a4c commit 773c261
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 33 deletions.
46 changes: 17 additions & 29 deletions test/end2end/dartdoc_integration_test.dart
Expand Up @@ -91,20 +91,14 @@ void main() {
test('invalid parameters return non-zero and print a fatal-error',
() async {
var outputLines = <String>[];
var threwException = false;
// consider [expectLater] when it works reliably with coverage again.
try {
await subprocessLauncher.runStreamed(
Platform.resolvedExecutable,
[
dartdocPath,
'--nonexisting',
],
perLine: outputLines.add);
} on ProcessException {
threwException = true;
}
expect(threwException, isTrue);
await subprocessLauncher.runStreamed(
Platform.resolvedExecutable,
[
dartdocPath,
'--nonexisting',
],
perLine: outputLines.add,
expectExitCode: 64);
expect(
outputLines.firstWhere((l) => l.startsWith(' fatal')),
equals(
Expand All @@ -114,21 +108,15 @@ void main() {
test('missing a required file path prints a fatal-error', () async {
var outputLines = <String>[];
var impossiblePath = path.join(dartdocPath, 'impossible');
var threwException = false;
// consider [expectLater] when it works with coverage again.
try {
await subprocessLauncher.runStreamed(
Platform.resolvedExecutable,
[
dartdocPath,
'--input',
impossiblePath,
],
perLine: outputLines.add);
} on ProcessException {
threwException = true;
}
expect(threwException, isTrue);
await subprocessLauncher.runStreamed(
Platform.resolvedExecutable,
[
dartdocPath,
'--input',
impossiblePath,
],
perLine: outputLines.add,
expectExitCode: 64);
expect(
outputLines.firstWhere((l) => l.startsWith(' fatal')),
startsWith(
Expand Down
11 changes: 7 additions & 4 deletions tool/subprocess_launcher.dart
Expand Up @@ -75,7 +75,8 @@ class CoverageSubprocessLauncher extends SubprocessLauncher {
{String workingDirectory,
Map<String, String> environment,
bool includeParentEnvironment = true,
void Function(String) perLine}) async {
void Function(String) perLine,
int expectExitCode = 0}) async {
environment ??= {};
assert(
executable == Platform.executable ||
Expand Down Expand Up @@ -113,7 +114,8 @@ class CoverageSubprocessLauncher extends SubprocessLauncher {
environment: environment,
includeParentEnvironment: includeParentEnvironment,
workingDirectory: workingDirectory,
perLine: parsePortAsString);
perLine: parsePortAsString,
expectExitCode: expectExitCode);

if (coverageEnabled) {
await super.runStreamed('pub', [
Expand Down Expand Up @@ -172,7 +174,8 @@ class SubprocessLauncher {
{String workingDirectory,
Map<String, String> environment,
bool includeParentEnvironment = true,
void Function(String) perLine}) async {
void Function(String) perLine,
int expectExitCode = 0}) async {
environment ??= {};
environment.addAll(environmentDefaults);
List<Map> jsonObjects;
Expand Down Expand Up @@ -257,7 +260,7 @@ class SubprocessLauncher {
await Future.wait([stderrFuture, stdoutFuture, process.exitCode]);

var exitCode = await process.exitCode;
if (exitCode != 0) {
if (exitCode != expectExitCode) {
throw ProcessException(
executable,
arguments,
Expand Down

0 comments on commit 773c261

Please sign in to comment.