OLD | NEW |
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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 /** | 5 /** |
6 * A test configuration that generates a compact 1-line progress bar. The bar is | 6 * A test configuration that generates a compact 1-line progress bar. The bar is |
7 * updated in-place before and after each test is executed. If all test pass, | 7 * updated in-place before and after each test is executed. If all test pass, |
8 * you should only see a couple lines in the terminal. If a test fails, the | 8 * you should only see a couple lines in the terminal. If a test fails, the |
9 * failure is shown and the progress bar continues to be updated below it. | 9 * failure is shown and the progress bar continues to be updated below it. |
10 */ | 10 */ |
11 library compact_vm_config; | 11 library compact_vm_config; |
12 | 12 |
13 import 'dart:io'; | 13 import 'dart:io'; |
14 import 'unittest.dart'; | 14 import 'unittest.dart'; |
15 import 'vm_config.dart'; | 15 import 'vm_config.dart'; |
16 | 16 |
17 const String _GREEN = '\u001b[32m'; | 17 const String _GREEN = '\u001b[32m'; |
18 const String _RED = '\u001b[31m'; | 18 const String _RED = '\u001b[31m'; |
19 const String _NONE = '\u001b[0m'; | 19 const String _NONE = '\u001b[0m'; |
20 const int MAX_LINE = 80; | 20 const int MAX_LINE = 80; |
21 | 21 |
22 class CompactVMConfiguration extends VMConfiguration { | 22 class CompactVMConfiguration extends VMConfiguration { |
23 Date _start; | 23 DateTime _start; |
24 int _pass = 0; | 24 int _pass = 0; |
25 int _fail = 0; | 25 int _fail = 0; |
26 | 26 |
27 void onInit() { | 27 void onInit() { |
28 super.onInit(); | 28 super.onInit(); |
29 } | 29 } |
30 | 30 |
31 void onStart() { | 31 void onStart() { |
32 super.onStart(); | 32 super.onStart(); |
33 _start = new Date.now(); | 33 _start = new DateTime.now(); |
34 } | 34 } |
35 | 35 |
36 void onTestStart(TestCase test) { | 36 void onTestStart(TestCase test) { |
37 super.onTestStart(test); | 37 super.onTestStart(test); |
38 _progressLine(_start, _pass, _fail, test.description); | 38 _progressLine(_start, _pass, _fail, test.description); |
39 } | 39 } |
40 | 40 |
41 void onTestResult(TestCase test) { | 41 void onTestResult(TestCase test) { |
42 super.onTestResult(test); | 42 super.onTestResult(test); |
43 if (test.result == PASS) { | 43 if (test.result == PASS) { |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
77 print('Top-level uncaught error: $uncaughtError'); | 77 print('Top-level uncaught error: $uncaughtError'); |
78 } | 78 } |
79 print('$passed PASSED, $failed FAILED, $errors ERRORS'); | 79 print('$passed PASSED, $failed FAILED, $errors ERRORS'); |
80 } | 80 } |
81 } | 81 } |
82 | 82 |
83 int _lastLength = 0; | 83 int _lastLength = 0; |
84 | 84 |
85 final int _nonVisiblePrefix = 1 + _GREEN.length + _NONE.length; | 85 final int _nonVisiblePrefix = 1 + _GREEN.length + _NONE.length; |
86 | 86 |
87 void _progressLine(Date startTime, int passed, int failed, String message, | 87 void _progressLine(DateTime startTime, int passed, int failed, String message, |
88 [String color = _NONE]) { | 88 [String color = _NONE]) { |
89 var duration = (new Date.now()).difference(startTime); | 89 var duration = (new DateTime.now()).difference(startTime); |
90 var buffer = new StringBuffer(); | 90 var buffer = new StringBuffer(); |
91 // \r moves back to the beginnig of the current line. | 91 // \r moves back to the beginnig of the current line. |
92 buffer.add('\r${_timeString(duration)} '); | 92 buffer.add('\r${_timeString(duration)} '); |
93 buffer.add(_GREEN); | 93 buffer.add(_GREEN); |
94 buffer.add('+'); | 94 buffer.add('+'); |
95 buffer.add(passed); | 95 buffer.add(passed); |
96 buffer.add(_NONE); | 96 buffer.add(_NONE); |
97 if (failed != 0) buffer.add(_RED); | 97 if (failed != 0) buffer.add(_RED); |
98 buffer.add(' -'); | 98 buffer.add(' -'); |
99 buffer.add(failed); | 99 buffer.add(failed); |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
164 res = res.substring(firstSpace); | 164 res = res.substring(firstSpace); |
165 } | 165 } |
166 return '...$res'; | 166 return '...$res'; |
167 } | 167 } |
168 } | 168 } |
169 | 169 |
170 void useCompactVMConfiguration() { | 170 void useCompactVMConfiguration() { |
171 if (config != null) return; | 171 if (config != null) return; |
172 configure(new CompactVMConfiguration()); | 172 configure(new CompactVMConfiguration()); |
173 } | 173 } |
OLD | NEW |