Skip to content

Commit

Permalink
Merge pull request #303 from Workiva/fix-exit-code-when-test-task-fails
Browse files Browse the repository at this point in the history
Fix result when test task fails so that correct exit code is returned
  • Loading branch information
rmconsole4-wk authored Jun 14, 2019
2 parents bf14803 + 1b0fa8e commit a5d089d
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 14 deletions.
9 changes: 8 additions & 1 deletion lib/src/reporter.dart
Original file line number Diff line number Diff line change
Expand Up @@ -87,19 +87,26 @@ class Reporter {
}

void error(String message, {bool shout: false}) {
message = message ?? 'An error was encountered running the task.';
_log(stderr, colorRed(message), shout: shout);
}

void success(String message, {bool shout: false}) {
if (message == null) {
return;
}
log(colorGreen(message), shout: shout);
}

void warning(String message, {bool shout: false}) {
if (message == null) {
return;
}
_log(stderr, colorYellow(message), shout: shout);
}

String _colorMessage(AnsiPen pen, String message) =>
color && message.isNotEmpty ? pen(message) : message;
color && message != null && message.isNotEmpty ? pen(message) : message;

void _log(IOSink sink, String message, {bool shout: false}) {
if (quiet && !shout) return;
Expand Down
12 changes: 11 additions & 1 deletion lib/src/tasks/test/api.dart
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ TestTask test({
List<String> presets: const [],
List<String> testArgs: const [],
List<String> tests: const [],
List<String> buildArgs: const [],
}) {
final executable = 'pub';
final args = <String>[];
Expand All @@ -48,8 +49,9 @@ TestTask test({
'run',
'build_runner',
'test',
'--',
]);
args.addAll(buildArgs);
args.add('--');
} else {
args.addAll(['run', 'test']);
}
Expand Down Expand Up @@ -102,6 +104,14 @@ TestTask test({
process.exitCode.then((code) {
if (task.successful == null) {
task.successful = code <= 0;

if (!task.successful) {
task.testSummary = 'An error was encountered when running tests.';
}

if (!outputProcessed.isCompleted) {
outputProcessed.complete();
}
}
});

Expand Down
14 changes: 2 additions & 12 deletions lib/src/tasks/test/cli.dart
Original file line number Diff line number Diff line change
Expand Up @@ -196,17 +196,6 @@ class TestCli extends TaskCli {
buildArgs.add('--delete-conflicting-outputs');
}

if (dartMajorVersion == 2 && hasImmediateDependency('build_test')) {
var args = ['run', 'build_runner', 'build']..addAll(buildArgs);
final buildProcess = new TaskProcess('pub', args);
reporter.logGroup('pub run build_runner build',
outputStream: buildProcess.stdout, errorStream: buildProcess.stderr);
final buildExitCode = await buildProcess.exitCode;
if (buildExitCode != 0) {
return new CliResult.fail('Build failed - cannot run tests.');
}
}

PubServeTask pubServeTask;

if (pubServe) {
Expand Down Expand Up @@ -270,7 +259,8 @@ A pub serve instance will not be started.''');
concurrency: concurrency,
platforms: platforms,
presets: presets,
testArgs: testArgs);
testArgs: testArgs,
buildArgs: buildArgs);
reporter.logGroup(task.testCommand, outputStream: task.testOutput);

await task.done;
Expand Down

0 comments on commit a5d089d

Please sign in to comment.