OLD | NEW |
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.compact; | 5 library test.runner.reporter.compact; |
6 | 6 |
| 7 import 'dart:async'; |
7 import 'dart:io'; | 8 import 'dart:io'; |
8 import 'dart:isolate'; | 9 import 'dart:isolate'; |
9 | 10 |
10 import '../../backend/live_test.dart'; | 11 import '../../backend/live_test.dart'; |
11 import '../../backend/state.dart'; | 12 import '../../backend/state.dart'; |
12 import '../../utils.dart'; | 13 import '../../utils.dart'; |
13 import '../engine.dart'; | 14 import '../engine.dart'; |
14 import '../load_exception.dart'; | 15 import '../load_exception.dart'; |
15 import '../load_suite.dart'; | 16 import '../load_suite.dart'; |
16 | 17 |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
57 | 58 |
58 /// Whether the path to each test's suite should be printed. | 59 /// Whether the path to each test's suite should be printed. |
59 final bool _printPath; | 60 final bool _printPath; |
60 | 61 |
61 /// Whether the platform each test is running on should be printed. | 62 /// Whether the platform each test is running on should be printed. |
62 final bool _printPlatform; | 63 final bool _printPlatform; |
63 | 64 |
64 /// A stopwatch that tracks the duration of the full run. | 65 /// A stopwatch that tracks the duration of the full run. |
65 final _stopwatch = new Stopwatch(); | 66 final _stopwatch = new Stopwatch(); |
66 | 67 |
| 68 /// A timer that triggers printing updated time information. |
| 69 Timer _timer; |
| 70 |
67 /// The size of `_engine.passed` last time a progress notification was | 71 /// The size of `_engine.passed` last time a progress notification was |
68 /// printed. | 72 /// printed. |
69 int _lastProgressPassed; | 73 int _lastProgressPassed; |
70 | 74 |
71 /// The size of `_engine.skipped` last time a progress notification was printe
d. | 75 /// The size of `_engine.skipped` last time a progress notification was printe
d. |
72 int _lastProgressSkipped; | 76 int _lastProgressSkipped; |
73 | 77 |
74 /// The size of `_engine.failed` last time a progress notification was | 78 /// The size of `_engine.failed` last time a progress notification was |
75 /// printed. | 79 /// printed. |
76 int _lastProgressFailed; | 80 int _lastProgressFailed; |
77 | 81 |
| 82 /// The duration of the test run in seconds last time a progress notification |
| 83 /// was printed. |
| 84 int _lastProgressElapsed; |
| 85 |
78 /// The message printed for the last progress notification. | 86 /// The message printed for the last progress notification. |
79 String _lastProgressMessage; | 87 String _lastProgressMessage; |
80 | 88 |
81 // Whether a newline has been printed since the last progress line. | 89 // Whether a newline has been printed since the last progress line. |
82 var _printedNewline = true; | 90 var _printedNewline = true; |
83 | 91 |
84 /// Watches the tests run by [engine] and prints their results to the | 92 /// Watches the tests run by [engine] and prints their results to the |
85 /// terminal. | 93 /// terminal. |
86 /// | 94 /// |
87 /// If [color] is `true`, this will use terminal colors; if it's `false`, it | 95 /// If [color] is `true`, this will use terminal colors; if it's `false`, it |
(...skipping 22 matching lines...) Expand all Loading... |
110 _yellow = color ? '\u001b[33m' : '', | 118 _yellow = color ? '\u001b[33m' : '', |
111 _gray = color ? '\u001b[1;30m' : '', | 119 _gray = color ? '\u001b[1;30m' : '', |
112 _bold = color ? '\u001b[1m' : '', | 120 _bold = color ? '\u001b[1m' : '', |
113 _noColor = color ? '\u001b[0m' : '' { | 121 _noColor = color ? '\u001b[0m' : '' { |
114 _engine.onTestStarted.listen(_onTestStarted); | 122 _engine.onTestStarted.listen(_onTestStarted); |
115 _engine.success.then(_onDone); | 123 _engine.success.then(_onDone); |
116 } | 124 } |
117 | 125 |
118 /// A callback called when the engine begins running [liveTest]. | 126 /// A callback called when the engine begins running [liveTest]. |
119 void _onTestStarted(LiveTest liveTest) { | 127 void _onTestStarted(LiveTest liveTest) { |
120 if (!_stopwatch.isRunning) _stopwatch.start(); | 128 if (_timer == null) { |
| 129 _stopwatch.start(); |
| 130 /// Keep updating the time even when nothing else is happening. |
| 131 _timer = new Timer.periodic(new Duration(seconds: 1), |
| 132 (_) => _progressLine(_lastProgressMessage)); |
| 133 } |
121 | 134 |
122 // If this is the first test to start, print a progress line so the user | 135 // If this is the first test to start, print a progress line so the user |
123 // knows what's running. It's possible that the active test may not be | 136 // knows what's running. It's possible that the active test may not be |
124 // [liveTest] because the engine doesn't always surface load tests. | 137 // [liveTest] because the engine doesn't always surface load tests. |
125 if (_engine.active.length == 1 && _engine.active.first == liveTest) { | 138 if (_engine.active.length == 1 && _engine.active.first == liveTest) { |
126 _progressLine(_description(liveTest)); | 139 _progressLine(_description(liveTest)); |
127 } | 140 } |
128 _printedNewline = false; | 141 _printedNewline = false; |
129 | 142 |
130 liveTest.onStateChange.listen((state) => _onStateChange(liveTest, state)); | 143 liveTest.onStateChange.listen((state) => _onStateChange(liveTest, state)); |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
188 error.innerError is! String) { | 201 error.innerError is! String) { |
189 print(indent(terseChain(stackTrace).toString())); | 202 print(indent(terseChain(stackTrace).toString())); |
190 } | 203 } |
191 } | 204 } |
192 | 205 |
193 /// A callback called when the engine is finished running tests. | 206 /// A callback called when the engine is finished running tests. |
194 /// | 207 /// |
195 /// [success] will be `true` if all tests passed, `false` if some tests | 208 /// [success] will be `true` if all tests passed, `false` if some tests |
196 /// failed, and `null` if the engine was closed prematurely. | 209 /// failed, and `null` if the engine was closed prematurely. |
197 void _onDone(bool success) { | 210 void _onDone(bool success) { |
| 211 _timer.cancel(); |
| 212 _timer = null; |
| 213 _stopwatch.stop(); |
| 214 |
198 // A null success value indicates that the engine was closed before the | 215 // A null success value indicates that the engine was closed before the |
199 // tests finished running, probably because of a signal from the user. We | 216 // tests finished running, probably because of a signal from the user. We |
200 // shouldn't print summary information, we should just make sure the | 217 // shouldn't print summary information, we should just make sure the |
201 // terminal cursor is on its own line. | 218 // terminal cursor is on its own line. |
202 if (success == null) { | 219 if (success == null) { |
203 if (!_printedNewline) print(""); | 220 if (!_printedNewline) print(""); |
204 _printedNewline = true; | 221 _printedNewline = true; |
205 return; | 222 return; |
206 } | 223 } |
207 | 224 |
(...skipping 16 matching lines...) Expand all Loading... |
224 print(''); | 241 print(''); |
225 } | 242 } |
226 } | 243 } |
227 | 244 |
228 /// Prints a line representing the current state of the tests. | 245 /// Prints a line representing the current state of the tests. |
229 /// | 246 /// |
230 /// [message] goes after the progress report, and may be truncated to fit the | 247 /// [message] goes after the progress report, and may be truncated to fit the |
231 /// entire line within [_lineLength]. If [color] is passed, it's used as the | 248 /// entire line within [_lineLength]. If [color] is passed, it's used as the |
232 /// color for [message]. | 249 /// color for [message]. |
233 bool _progressLine(String message, {String color}) { | 250 bool _progressLine(String message, {String color}) { |
| 251 var elapsed = _stopwatch.elapsed.inSeconds; |
| 252 |
234 // Print nothing if nothing has changed since the last progress line. | 253 // Print nothing if nothing has changed since the last progress line. |
235 if (_engine.passed.length == _lastProgressPassed && | 254 if (_engine.passed.length == _lastProgressPassed && |
236 _engine.skipped.length == _lastProgressSkipped && | 255 _engine.skipped.length == _lastProgressSkipped && |
237 _engine.failed.length == _lastProgressFailed && | 256 _engine.failed.length == _lastProgressFailed && |
| 257 elapsed == _lastProgressElapsed && |
238 message == _lastProgressMessage) { | 258 message == _lastProgressMessage) { |
239 return false; | 259 return false; |
240 } | 260 } |
241 | 261 |
242 _lastProgressPassed = _engine.passed.length; | 262 _lastProgressPassed = _engine.passed.length; |
243 _lastProgressSkipped = _engine.skipped.length; | 263 _lastProgressSkipped = _engine.skipped.length; |
244 _lastProgressFailed = _engine.failed.length; | 264 _lastProgressFailed = _engine.failed.length; |
| 265 _lastProgressElapsed = elapsed; |
245 _lastProgressMessage = message; | 266 _lastProgressMessage = message; |
246 | 267 |
247 if (color == null) color = ''; | 268 if (color == null) color = ''; |
248 var duration = _stopwatch.elapsed; | 269 var duration = _stopwatch.elapsed; |
249 var buffer = new StringBuffer(); | 270 var buffer = new StringBuffer(); |
250 | 271 |
251 // \r moves back to the beginning of the current line. | 272 // \r moves back to the beginning of the current line. |
252 buffer.write('\r${_timeString(duration)} '); | 273 buffer.write('\r${_timeString(duration)} '); |
253 buffer.write(_green); | 274 buffer.write(_green); |
254 buffer.write('+'); | 275 buffer.write('+'); |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
304 | 325 |
305 if (_printPlatform && liveTest.suite.platform != null) { | 326 if (_printPlatform && liveTest.suite.platform != null) { |
306 name = "[${liveTest.suite.platform}] $name"; | 327 name = "[${liveTest.suite.platform}] $name"; |
307 } | 328 } |
308 | 329 |
309 if (liveTest.suite is LoadSuite) name = "$_bold$_gray$name$_noColor"; | 330 if (liveTest.suite is LoadSuite) name = "$_bold$_gray$name$_noColor"; |
310 | 331 |
311 return name; | 332 return name; |
312 } | 333 } |
313 } | 334 } |
OLD | NEW |