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:async'; | 13 import 'dart:async'; |
14 import 'dart:io'; | 14 import 'dart:io'; |
15 import 'dart:isolate'; | 15 import 'dart:isolate'; |
16 | 16 |
17 import 'unittest.dart'; | 17 import 'unittest.dart'; |
18 import 'src/utils.dart'; | |
19 import 'vm_config.dart'; | 18 import 'vm_config.dart'; |
20 | 19 |
21 const String _GREEN = '\u001b[32m'; | 20 const String _GREEN = '\u001b[32m'; |
22 const String _RED = '\u001b[31m'; | 21 const String _RED = '\u001b[31m'; |
23 const String _NONE = '\u001b[0m'; | 22 const String _NONE = '\u001b[0m'; |
24 | 23 |
25 const int MAX_LINE = 80; | 24 const int MAX_LINE = 80; |
26 | 25 |
27 class CompactVMConfiguration extends VMConfiguration { | 26 class CompactVMConfiguration extends VMConfiguration { |
28 // The VM won't shut down if a receive port is open. Use this to make sure | 27 // The VM won't shut down if a receive port is open. Use this to make sure |
(...skipping 22 matching lines...) Expand all Loading... |
51 void onTestResult(TestCase test) { | 50 void onTestResult(TestCase test) { |
52 super.onTestResult(test); | 51 super.onTestResult(test); |
53 if (test.result == PASS) { | 52 if (test.result == PASS) { |
54 _pass++; | 53 _pass++; |
55 _progressLine(_start, _pass, _fail, test.description); | 54 _progressLine(_start, _pass, _fail, test.description); |
56 } else { | 55 } else { |
57 _fail++; | 56 _fail++; |
58 _progressLine(_start, _pass, _fail, test.description); | 57 _progressLine(_start, _pass, _fail, test.description); |
59 print(''); | 58 print(''); |
60 if (test.message != '') { | 59 if (test.message != '') { |
61 print(indent(test.message)); | 60 print(_indent(test.message)); |
62 } | 61 } |
63 | 62 |
64 if (test.stackTrace != null) { | 63 if (test.stackTrace != null && test.stackTrace != '') { |
65 print(indent(test.stackTrace.toString())); | 64 print(_indent(test.stackTrace)); |
66 } | 65 } |
67 } | 66 } |
68 } | 67 } |
69 | 68 |
70 void onDone(bool success) { | 69 void onDone(bool success) { |
71 // Override and don't call the superclass onDone() to avoid printing the | 70 // Override and don't call the superclass onDone() to avoid printing the |
72 // "unittest-suite-..." boilerplate. | 71 // "unittest-suite-..." boilerplate. |
73 Future.wait([stdout.close(), stderr.close()]).then((_) { | 72 Future.wait([stdout.close(), stderr.close()]).then((_) { |
74 _receivePort.close(); | 73 _receivePort.close(); |
75 exit(success ? 0 : 1); | 74 exit(success ? 0 : 1); |
76 }); | 75 }); |
77 } | 76 } |
78 | 77 |
| 78 String _indent(String str) { |
| 79 return str.split("\n").map((line) => " $line").join("\n"); |
| 80 } |
| 81 |
79 void onSummary(int passed, int failed, int errors, List<TestCase> results, | 82 void onSummary(int passed, int failed, int errors, List<TestCase> results, |
80 String uncaughtError) { | 83 String uncaughtError) { |
81 var success = false; | 84 var success = false; |
82 if (passed == 0 && failed == 0 && errors == 0 && uncaughtError == null) { | 85 if (passed == 0 && failed == 0 && errors == 0 && uncaughtError == null) { |
83 print('\nNo tests ran.'); | 86 print('\nNo tests ran.'); |
84 } else if (failed == 0 && errors == 0 && uncaughtError == null) { | 87 } else if (failed == 0 && errors == 0 && uncaughtError == null) { |
85 _progressLine(_start, _pass, _fail, 'All tests passed!', _NONE); | 88 _progressLine(_start, _pass, _fail, 'All tests passed!', _NONE); |
86 print(''); | 89 print(''); |
87 success = true; | 90 success = true; |
88 } else { | 91 } else { |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
191 // If the test is running on the Dart buildbots, we don't want to use this | 194 // If the test is running on the Dart buildbots, we don't want to use this |
192 // config since it's output may not be what the bots expect. | 195 // config since it's output may not be what the bots expect. |
193 if (Platform.environment.containsKey('BUILDBOT_BUILDERNAME')) { | 196 if (Platform.environment.containsKey('BUILDBOT_BUILDERNAME')) { |
194 return; | 197 return; |
195 } | 198 } |
196 | 199 |
197 unittestConfiguration = _singleton; | 200 unittestConfiguration = _singleton; |
198 } | 201 } |
199 | 202 |
200 final _singleton = new CompactVMConfiguration(); | 203 final _singleton = new CompactVMConfiguration(); |
OLD | NEW |