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 |
14 import 'unittest.dart'; | 15 import 'unittest.dart'; |
| 16 import 'src/utils.dart'; |
15 import 'vm_config.dart'; | 17 import 'vm_config.dart'; |
16 | 18 |
17 const String _GREEN = '\u001b[32m'; | 19 const String _GREEN = '\u001b[32m'; |
18 const String _RED = '\u001b[31m'; | 20 const String _RED = '\u001b[31m'; |
19 const String _NONE = '\u001b[0m'; | 21 const String _NONE = '\u001b[0m'; |
20 const int MAX_LINE = 80; | 22 const int MAX_LINE = 80; |
21 | 23 |
22 class CompactVMConfiguration extends VMConfiguration { | 24 class CompactVMConfiguration extends VMConfiguration { |
23 DateTime _start; | 25 DateTime _start; |
24 int _pass = 0; | 26 int _pass = 0; |
(...skipping 16 matching lines...) Expand all Loading... |
41 void onTestResult(TestCase test) { | 43 void onTestResult(TestCase test) { |
42 super.onTestResult(test); | 44 super.onTestResult(test); |
43 if (test.result == PASS) { | 45 if (test.result == PASS) { |
44 _pass++; | 46 _pass++; |
45 _progressLine(_start, _pass, _fail, test.description); | 47 _progressLine(_start, _pass, _fail, test.description); |
46 } else { | 48 } else { |
47 _fail++; | 49 _fail++; |
48 _progressLine(_start, _pass, _fail, test.description); | 50 _progressLine(_start, _pass, _fail, test.description); |
49 print(''); | 51 print(''); |
50 if (test.message != '') { | 52 if (test.message != '') { |
51 print(_indent(test.message)); | 53 print(indent(test.message)); |
52 } | 54 } |
53 | 55 |
54 if (test.stackTrace != null && test.stackTrace != '') { | 56 if (test.stackTrace != null) { |
55 print(_indent(test.stackTrace)); | 57 print(indent(test.stackTrace.toString())); |
56 } | 58 } |
57 } | 59 } |
58 } | 60 } |
59 | 61 |
60 String _indent(String str) { | |
61 return str.split("\n").map((line) => " $line").join("\n"); | |
62 } | |
63 | |
64 void onSummary(int passed, int failed, int errors, List<TestCase> results, | 62 void onSummary(int passed, int failed, int errors, List<TestCase> results, |
65 String uncaughtError) { | 63 String uncaughtError) { |
66 var success = false; | 64 var success = false; |
67 if (passed == 0 && failed == 0 && errors == 0 && uncaughtError == null) { | 65 if (passed == 0 && failed == 0 && errors == 0 && uncaughtError == null) { |
68 print('\nNo tests ran.'); | 66 print('\nNo tests ran.'); |
69 } else if (failed == 0 && errors == 0 && uncaughtError == null) { | 67 } else if (failed == 0 && errors == 0 && uncaughtError == null) { |
70 _progressLine(_start, _pass, _fail, 'All tests pass', _GREEN); | 68 _progressLine(_start, _pass, _fail, 'All tests pass', _GREEN); |
71 print('\nAll $passed tests passed.'); | 69 print('\nAll $passed tests passed.'); |
72 success = true; | 70 success = true; |
73 } else { | 71 } else { |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
168 } | 166 } |
169 return '...$res'; | 167 return '...$res'; |
170 } | 168 } |
171 } | 169 } |
172 | 170 |
173 void useCompactVMConfiguration() { | 171 void useCompactVMConfiguration() { |
174 unittestConfiguration = _singleton; | 172 unittestConfiguration = _singleton; |
175 } | 173 } |
176 | 174 |
177 final _singleton = new CompactVMConfiguration(); | 175 final _singleton = new CompactVMConfiguration(); |
OLD | NEW |