Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2)

Unified Diff: lib/src/runner/reporter/compact.dart

Issue 1044953004: Gracefully handle tests that print. (Closed) Base URL: git@github.com:dart-lang/unittest@master
Patch Set: Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « lib/src/runner/browser/iframe_test.dart ('k') | lib/src/runner/reporter/no_io_compact.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/src/runner/reporter/compact.dart
diff --git a/lib/src/runner/reporter/compact.dart b/lib/src/runner/reporter/compact.dart
index 0a75d7c68f751f01e6a1b9eeda5dc879690c46a4..49817ac7b3e66bf924b4dda161c50299285eb703 100644
--- a/lib/src/runner/reporter/compact.dart
+++ b/lib/src/runner/reporter/compact.dart
@@ -72,6 +72,8 @@ class CompactReporter {
_green = color ? '\u001b[32m' : '',
_red = color ? '\u001b[31m' : '',
_noColor = color ? '\u001b[0m' : '' {
+ // Whether a newline has been printed since the last progress line.
+ var printedNewline = false;
_engine.onTestStarted.listen((liveTest) {
_progressLine(_description(liveTest));
liveTest.onStateChange.listen((state) {
@@ -83,16 +85,27 @@ class CompactReporter {
_failed.add(liveTest);
}
_progressLine(_description(liveTest));
+ printedNewline = false;
});
liveTest.onError.listen((error) {
if (liveTest.state.status != Status.complete) return;
_progressLine(_description(liveTest));
- print('');
+ if (!printedNewline) print('');
+ printedNewline = true;
+
print(indent(error.error.toString()));
print(indent(terseChain(error.stackTrace).toString()));
});
+
+ liveTest.onPrint.listen((line) {
+ _progressLine(_description(liveTest));
+ if (!printedNewline) print('');
+ printedNewline = true;
+
+ print(line);
+ });
});
}
@@ -134,12 +147,12 @@ class CompactReporter {
/// [message] goes after the progress report, and may be truncated to fit the
/// entire line within [_lineLength]. If [color] is passed, it's used as the
/// color for [message].
- void _progressLine(String message, {String color}) {
+ bool _progressLine(String message, {String color}) {
// Print nothing if nothing has changed since the last progress line.
if (_passed.length == _lastProgressPassed &&
_failed.length == _lastProgressFailed &&
message == _lastProgressMessage) {
- return;
+ return false;
}
_lastProgressPassed = _passed.length;
@@ -180,6 +193,7 @@ class CompactReporter {
length = buffer.length - nonVisible - _noColor.length;
buffer.write(' ' * (_lineLength - length));
stdout.write(buffer.toString());
+ return true;
}
/// Returns a representation of [duration] as `MM:SS`.
« no previous file with comments | « lib/src/runner/browser/iframe_test.dart ('k') | lib/src/runner/reporter/no_io_compact.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698