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

Unified Diff: lib/src/runner/console_reporter.dart

Issue 961003005: Add a flag to control the use of color in the test runner. (Closed) Base URL: git@github.com:dart-lang/unittest@master
Patch Set: Code review changes Created 5 years, 10 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 | « bin/unittest.dart ('k') | lib/src/util/io.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/src/runner/console_reporter.dart
diff --git a/lib/src/runner/console_reporter.dart b/lib/src/runner/console_reporter.dart
index e5eaa311326cdcec1e986bf85f9106bc8c00528f..4680146b2dbe922d058740e25d5f603422f13703 100644
--- a/lib/src/runner/console_reporter.dart
+++ b/lib/src/runner/console_reporter.dart
@@ -10,22 +10,9 @@ import 'dart:io';
import '../backend/live_test.dart';
import '../backend/state.dart';
import '../backend/suite.dart';
-import '../util/io.dart';
import '../utils.dart';
import 'engine.dart';
-/// The terminal escape for green text, or the empty string if this is Windows
-/// or not outputting to a terminal.
-final _green = getSpecial('\u001b[32m');
-
-/// The terminal escape for red text, or the empty string if this is Windows or
-/// not outputting to a terminal.
-final _red = getSpecial('\u001b[31m');
-
-/// The terminal escape for removing test coloring, or the empty string if this
-/// is Windows or not outputting to a terminal.
-final _noColor = getSpecial('\u001b[0m');
-
/// The maximum console line length.
///
/// Lines longer than this will be cropped.
@@ -34,6 +21,18 @@ const _lineLength = 100;
/// A reporter that prints test results to the console in a single
/// continuously-updating line.
class ConsoleReporter {
+ /// The terminal escape for green text, or the empty string if this is Windows
+ /// or not outputting to a terminal.
+ final String _green;
+
+ /// The terminal escape for red text, or the empty string if this is Windows
+ /// or not outputting to a terminal.
+ final String _red;
+
+ /// The terminal escape for removing test coloring, or the empty string if
+ /// this is Windows or not outputting to a terminal.
+ final String _noColor;
+
/// The engine used to run the tests.
final Engine _engine;
@@ -59,10 +58,15 @@ class ConsoleReporter {
String _lastProgressMessage;
/// Creates a [ConsoleReporter] that will run all tests in [suites].
- ConsoleReporter(Iterable<Suite> suites)
+ ///
+ /// If [color] is `true`, this will use terminal colors; if it's `false`, it
+ /// won't.
+ ConsoleReporter(Iterable<Suite> suites, {bool color: true})
: _multipleSuites = suites.length > 1,
- _engine = new Engine(suites) {
-
+ _engine = new Engine(suites),
+ _green = color ? '\u001b[32m' : '',
+ _red = color ? '\u001b[31m' : '',
+ _noColor = color ? '\u001b[0m' : '' {
_engine.onTestStarted.listen((liveTest) {
_progressLine(_description(liveTest));
liveTest.onStateChange.listen((state) {
« no previous file with comments | « bin/unittest.dart ('k') | lib/src/util/io.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698