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

Side by Side Diff: lib/src/runner/reporter/expanded.dart

Issue 1196413003: Add a LoadSuite class. (Closed) Base URL: git@github.com:dart-lang/test@master
Patch Set: Created 5 years, 6 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 unified diff | Download patch
OLDNEW
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 library test.runner.reporter.no_io_compact; 5 library test.runner.reporter.no_io_compact;
6 6
7 import 'dart:isolate'; 7 import 'dart:isolate';
8 8
9 import '../../backend/live_test.dart'; 9 import '../../backend/live_test.dart';
10 import '../../backend/state.dart'; 10 import '../../backend/state.dart';
11 import '../../utils.dart'; 11 import '../../utils.dart';
12 import '../engine.dart'; 12 import '../engine.dart';
13 import '../load_exception.dart'; 13 import '../load_exception.dart';
14 import '../load_suite.dart';
14 15
15 /// The maximum console line length. 16 /// The maximum console line length.
16 /// 17 ///
17 /// Lines longer than this will be cropped. 18 /// Lines longer than this will be cropped.
18 const _lineLength = 100; 19 const _lineLength = 100;
19 20
20 /// A reporter that prints each test on its own line. 21 /// A reporter that prints each test on its own line.
21 /// 22 ///
22 /// This is currently used in place of [CompactReporter] by `lib/test.dart`, 23 /// This is currently used in place of [CompactReporter] by `lib/test.dart`,
23 /// which can't transitively import `dart:io` but still needs access to a runner 24 /// which can't transitively import `dart:io` but still needs access to a runner
24 /// so that test files can be run directly. This means that until issue 6943 is 25 /// so that test files can be run directly. This means that until issue 6943 is
25 /// fixed, this must not import `dart:io`. 26 /// fixed, this must not import `dart:io`.
26 class ExpandedReporter { 27 class ExpandedReporter {
27 /// Whether the reporter should emit terminal color escapes. 28 /// Whether the reporter should emit terminal color escapes.
28 final bool _color; 29 final bool _color;
29 30
30 /// The terminal escape for green text, or the empty string if this is Windows 31 /// The terminal escape for green text, or the empty string if this is Windows
31 /// or not outputting to a terminal. 32 /// or not outputting to a terminal.
32 final String _green; 33 final String _green;
33 34
34 /// The terminal escape for red text, or the empty string if this is Windows 35 /// The terminal escape for red text, or the empty string if this is Windows
35 /// or not outputting to a terminal. 36 /// or not outputting to a terminal.
36 final String _red; 37 final String _red;
37 38
38 /// The terminal escape for yellow text, or the empty string if this is 39 /// The terminal escape for yellow text, or the empty string if this is
39 /// Windows or not outputting to a terminal. 40 /// Windows or not outputting to a terminal.
40 final String _yellow; 41 final String _yellow;
41 42
43 /// The terminal escape for gray text, or the empty string if this is
44 /// Windows or not outputting to a terminal.
45 final String _gray;
46
47 /// The terminal escape for bold text, or the empty string if this is
48 /// Windows or not outputting to a terminal.
49 final String _bold;
50
42 /// The terminal escape for removing test coloring, or the empty string if 51 /// The terminal escape for removing test coloring, or the empty string if
43 /// this is Windows or not outputting to a terminal. 52 /// this is Windows or not outputting to a terminal.
44 final String _noColor; 53 final String _noColor;
45 54
46 /// Whether to use verbose stack traces. 55 /// Whether to use verbose stack traces.
47 final bool _verboseTrace; 56 final bool _verboseTrace;
48 57
49 /// The engine used to run the tests. 58 /// The engine used to run the tests.
50 final Engine _engine; 59 final Engine _engine;
51 60
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
93 102
94 ExpandedReporter._(this._engine, {bool color: true, bool verboseTrace: false, 103 ExpandedReporter._(this._engine, {bool color: true, bool verboseTrace: false,
95 bool printPath: true, bool printPlatform: true}) 104 bool printPath: true, bool printPlatform: true})
96 : _verboseTrace = verboseTrace, 105 : _verboseTrace = verboseTrace,
97 _printPath = printPath, 106 _printPath = printPath,
98 _printPlatform = printPlatform, 107 _printPlatform = printPlatform,
99 _color = color, 108 _color = color,
100 _green = color ? '\u001b[32m' : '', 109 _green = color ? '\u001b[32m' : '',
101 _red = color ? '\u001b[31m' : '', 110 _red = color ? '\u001b[31m' : '',
102 _yellow = color ? '\u001b[33m' : '', 111 _yellow = color ? '\u001b[33m' : '',
112 _gray = color ? '\u001b[1;30m' : '',
113 _bold = color ? '\u001b[1m' : '',
103 _noColor = color ? '\u001b[0m' : '' { 114 _noColor = color ? '\u001b[0m' : '' {
104 _engine.onTestStarted.listen(_onTestStarted); 115 _engine.onTestStarted.listen(_onTestStarted);
105 _engine.success.then(_onDone); 116 _engine.success.then(_onDone);
106 } 117 }
107 118
108 /// A callback called when the engine begins running [liveTest]. 119 /// A callback called when the engine begins running [liveTest].
109 void _onTestStarted(LiveTest liveTest) { 120 void _onTestStarted(LiveTest liveTest) {
110 if (!_stopwatch.isRunning) _stopwatch.start(); 121 if (liveTest.suite is! LoadSuite) {
122 if (!_stopwatch.isRunning) _stopwatch.start();
111 123
112 // If this is the first test to start, print a progress line so 124 // If this is the first non-load test to start, print a progress line so
113 // the user knows what's running. 125 // the user knows what's running.
114 if (_engine.active.length == 1) _progressLine(_description(liveTest)); 126 if (_engine.active.length == 1) _progressLine(_description(liveTest));
115 127
116 liveTest.onStateChange.listen((state) => _onStateChange(liveTest, state)); 128 // The engine surfaces load tests when there are no other tests running,
129 // but because the expanded reporter's output is always visible, we don't
130 // emit information about them unless they fail.
131 liveTest.onStateChange.listen((state) => _onStateChange(liveTest, state));
132 } else if (_engine.active.length == 1 &&
133 _engine.active.first == liveTest &&
134 liveTest.test.name.startsWith("compiling ")) {
135 // Print a progress line for load tests that come from compiling JS, since
136 // that takes a long time.
137 _progressLine(_description(liveTest));
138 }
117 139
118 liveTest.onError.listen((error) => 140 liveTest.onError.listen((error) =>
119 _onError(liveTest, error.error, error.stackTrace)); 141 _onError(liveTest, error.error, error.stackTrace));
120 142
121 liveTest.onPrint.listen((line) { 143 liveTest.onPrint.listen((line) {
122 _progressLine(_description(liveTest)); 144 _progressLine(_description(liveTest));
123 print(line); 145 print(line);
124 }); 146 });
125 } 147 }
126 148
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
227 buffer.write(_engine.failed.length); 249 buffer.write(_engine.failed.length);
228 buffer.write(_noColor); 250 buffer.write(_noColor);
229 } 251 }
230 252
231 buffer.write(': '); 253 buffer.write(': ');
232 buffer.write(color); 254 buffer.write(color);
233 255
234 // Ensure the line fits within [_lineLength]. [buffer] includes the color 256 // Ensure the line fits within [_lineLength]. [buffer] includes the color
235 // escape sequences too. Because these sequences are not visible characters, 257 // escape sequences too. Because these sequences are not visible characters,
236 // we make sure they are not counted towards the limit. 258 // we make sure they are not counted towards the limit.
237 var nonVisible = 1 + _green.length + _noColor.length + color.length + 259 var length = withoutColors(buffer.toString()).length;
238 (_engine.failed.isEmpty ? 0 : _red.length + _noColor.length);
239 var length = buffer.length - nonVisible;
240 buffer.write(truncate(message, _lineLength - length)); 260 buffer.write(truncate(message, _lineLength - length));
241 buffer.write(_noColor); 261 buffer.write(_noColor);
242 262
243 print(buffer.toString()); 263 print(buffer.toString());
244 } 264 }
245 265
246 /// Returns a representation of [duration] as `MM:SS`. 266 /// Returns a representation of [duration] as `MM:SS`.
247 String _timeString(Duration duration) { 267 String _timeString(Duration duration) {
248 return "${duration.inMinutes.toString().padLeft(2, '0')}:" 268 return "${duration.inMinutes.toString().padLeft(2, '0')}:"
249 "${(duration.inSeconds % 60).toString().padLeft(2, '0')}"; 269 "${(duration.inSeconds % 60).toString().padLeft(2, '0')}";
250 } 270 }
251 271
252 /// Returns a description of [liveTest]. 272 /// Returns a description of [liveTest].
253 /// 273 ///
254 /// This differs from the test's own description in that it may also include 274 /// This differs from the test's own description in that it may also include
255 /// the suite's name. 275 /// the suite's name.
256 String _description(LiveTest liveTest) { 276 String _description(LiveTest liveTest) {
257 var name = liveTest.test.name; 277 var name = liveTest.test.name;
258 278
259 if (_printPath && liveTest.suite.path != null) { 279 if (_printPath && liveTest.suite.path != null) {
260 name = "${liveTest.suite.path}: $name"; 280 name = "${liveTest.suite.path}: $name";
261 } 281 }
262 282
263 if (_printPlatform && liveTest.suite.platform != null) { 283 if (_printPlatform && liveTest.suite.platform != null) {
264 name = "[${liveTest.suite.platform}] $name"; 284 name = "[${liveTest.suite.platform}] $name";
265 } 285 }
266 286
287 if (liveTest.suite is LoadSuite) name = "$_bold$_gray$name$_noColor";
288
267 return name; 289 return name;
268 } 290 }
269 } 291 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698