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 'package:unittest/unittest.dart'; | 14 import 'unittest.dart'; |
| 15 import 'vm_config.dart'; |
15 | 16 |
16 const String _GREEN = '\u001b[32m'; | 17 const String _GREEN = '\u001b[32m'; |
17 const String _RED = '\u001b[31m'; | 18 const String _RED = '\u001b[31m'; |
18 const String _NONE = '\u001b[0m'; | 19 const String _NONE = '\u001b[0m'; |
19 const int MAX_LINE = 80; | 20 const int MAX_LINE = 80; |
20 | 21 |
21 class CompactVMConfiguration extends Configuration { | 22 class CompactVMConfiguration extends VMConfiguration { |
22 Date _start; | 23 Date _start; |
23 int _pass = 0; | 24 int _pass = 0; |
24 int _fail = 0; | 25 int _fail = 0; |
25 | 26 |
26 void onInit() { | 27 void onInit() { |
27 super.onInit(); | 28 super.onInit(); |
28 } | 29 } |
29 | 30 |
30 void onStart() { | 31 void onStart() { |
31 super.onStart(); | 32 super.onStart(); |
(...skipping 21 matching lines...) Expand all Loading... |
53 if (test.stackTrace != null && test.stackTrace != '') { | 54 if (test.stackTrace != null && test.stackTrace != '') { |
54 print(_indent(test.stackTrace)); | 55 print(_indent(test.stackTrace)); |
55 } | 56 } |
56 } | 57 } |
57 } | 58 } |
58 | 59 |
59 String _indent(String str) { | 60 String _indent(String str) { |
60 return str.split("\n").mappedBy((line) => " $line").join("\n"); | 61 return str.split("\n").mappedBy((line) => " $line").join("\n"); |
61 } | 62 } |
62 | 63 |
63 void onDone(int passed, int failed, int errors, List<TestCase> results, | 64 void onSummary(int passed, int failed, int errors, List<TestCase> results, |
64 String uncaughtError) { | 65 String uncaughtError) { |
65 var success = false; | 66 var success = false; |
66 if (passed == 0 && failed == 0 && errors == 0) { | 67 if (passed == 0 && failed == 0 && errors == 0) { |
67 print('\nNo tests ran.'); | 68 print('\nNo tests ran.'); |
68 } else if (failed == 0 && errors == 0 && uncaughtError == null) { | 69 } else if (failed == 0 && errors == 0 && uncaughtError == null) { |
69 _progressLine(_start, _pass, _fail, 'All tests pass', _GREEN); | 70 _progressLine(_start, _pass, _fail, 'All tests pass', _GREEN); |
70 print('\nAll $passed tests passed.'); | 71 print('\nAll $passed tests passed.'); |
71 success = true; | 72 success = true; |
72 } else { | 73 } else { |
73 _progressLine(_start, _pass, _fail, 'Some tests fail', _RED); | 74 _progressLine(_start, _pass, _fail, 'Some tests fail', _RED); |
74 print(''); | 75 print(''); |
75 if (uncaughtError != null) { | 76 if (uncaughtError != null) { |
76 print('Top-level uncaught error: $uncaughtError'); | 77 print('Top-level uncaught error: $uncaughtError'); |
77 } | 78 } |
78 print('$passed PASSED, $failed FAILED, $errors ERRORS'); | 79 print('$passed PASSED, $failed FAILED, $errors ERRORS'); |
79 } | 80 } |
80 | |
81 if (!success) exit(1); | |
82 } | 81 } |
83 | 82 |
84 int _lastLength = 0; | 83 int _lastLength = 0; |
85 | 84 |
86 final int _nonVisiblePrefix = 1 + _GREEN.length + _NONE.length; | 85 final int _nonVisiblePrefix = 1 + _GREEN.length + _NONE.length; |
87 | 86 |
88 void _progressLine(Date startTime, int passed, int failed, String message, | 87 void _progressLine(Date startTime, int passed, int failed, String message, |
89 [String color = _NONE]) { | 88 [String color = _NONE]) { |
90 var duration = (new Date.now()).difference(startTime); | 89 var duration = (new Date.now()).difference(startTime); |
91 var buffer = new StringBuffer(); | 90 var buffer = new StringBuffer(); |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
159 | 158 |
160 // Otherwise truncate to return the trailing text, but attempt to start at | 159 // Otherwise truncate to return the trailing text, but attempt to start at |
161 // the beginning of a word. | 160 // the beginning of a word. |
162 var res = text.substring(text.length - maxLength + 4); | 161 var res = text.substring(text.length - maxLength + 4); |
163 var firstSpace = res.indexOf(' '); | 162 var firstSpace = res.indexOf(' '); |
164 if (firstSpace > 0) { | 163 if (firstSpace > 0) { |
165 res = res.substring(firstSpace); | 164 res = res.substring(firstSpace); |
166 } | 165 } |
167 return '...$res'; | 166 return '...$res'; |
168 } | 167 } |
| 168 |
| 169 void notifyController(String msg) {} |
169 } | 170 } |
170 | 171 |
171 void useCompactVMConfiguration() { | 172 void useCompactVMConfiguration() { |
172 configure(new CompactVMConfiguration()); | 173 configure(new CompactVMConfiguration()); |
173 } | 174 } |
OLD | NEW |