Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix result when test task fails so that correct exit code is returned #303

Merged
merged 4 commits into from
Jun 14, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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