Skip to content

Commit a5d089d

Browse files
Merge pull request #303 from Workiva/fix-exit-code-when-test-task-fails
Fix result when test task fails so that correct exit code is returned
2 parents bf14803 + 1b0fa8e commit a5d089d

File tree

3 files changed

+21
-14
lines changed

3 files changed

+21
-14
lines changed

lib/src/reporter.dart

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,19 +87,26 @@ class Reporter {
8787
}
8888

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

9394
void success(String message, {bool shout: false}) {
95+
if (message == null) {
96+
return;
97+
}
9498
log(colorGreen(message), shout: shout);
9599
}
96100

97101
void warning(String message, {bool shout: false}) {
102+
if (message == null) {
103+
return;
104+
}
98105
_log(stderr, colorYellow(message), shout: shout);
99106
}
100107

101108
String _colorMessage(AnsiPen pen, String message) =>
102-
color && message.isNotEmpty ? pen(message) : message;
109+
color && message != null && message.isNotEmpty ? pen(message) : message;
103110

104111
void _log(IOSink sink, String message, {bool shout: false}) {
105112
if (quiet && !shout) return;

lib/src/tasks/test/api.dart

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ TestTask test({
3030
List<String> presets: const [],
3131
List<String> testArgs: const [],
3232
List<String> tests: const [],
33+
List<String> buildArgs: const [],
3334
}) {
3435
final executable = 'pub';
3536
final args = <String>[];
@@ -48,8 +49,9 @@ TestTask test({
4849
'run',
4950
'build_runner',
5051
'test',
51-
'--',
5252
]);
53+
args.addAll(buildArgs);
54+
args.add('--');
5355
} else {
5456
args.addAll(['run', 'test']);
5557
}
@@ -102,6 +104,14 @@ TestTask test({
102104
process.exitCode.then((code) {
103105
if (task.successful == null) {
104106
task.successful = code <= 0;
107+
108+
if (!task.successful) {
109+
task.testSummary = 'An error was encountered when running tests.';
110+
}
111+
112+
if (!outputProcessed.isCompleted) {
113+
outputProcessed.complete();
114+
}
105115
}
106116
});
107117

lib/src/tasks/test/cli.dart

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -196,17 +196,6 @@ class TestCli extends TaskCli {
196196
buildArgs.add('--delete-conflicting-outputs');
197197
}
198198

199-
if (dartMajorVersion == 2 && hasImmediateDependency('build_test')) {
200-
var args = ['run', 'build_runner', 'build']..addAll(buildArgs);
201-
final buildProcess = new TaskProcess('pub', args);
202-
reporter.logGroup('pub run build_runner build',
203-
outputStream: buildProcess.stdout, errorStream: buildProcess.stderr);
204-
final buildExitCode = await buildProcess.exitCode;
205-
if (buildExitCode != 0) {
206-
return new CliResult.fail('Build failed - cannot run tests.');
207-
}
208-
}
209-
210199
PubServeTask pubServeTask;
211200

212201
if (pubServe) {
@@ -270,7 +259,8 @@ A pub serve instance will not be started.''');
270259
concurrency: concurrency,
271260
platforms: platforms,
272261
presets: presets,
273-
testArgs: testArgs);
262+
testArgs: testArgs,
263+
buildArgs: buildArgs);
274264
reporter.logGroup(task.testCommand, outputStream: task.testOutput);
275265

276266
await task.done;

0 commit comments

Comments
 (0)