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 */ |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
49 } | 49 } |
50 | 50 |
51 void onTestResult(TestCase test) { | 51 void onTestResult(TestCase test) { |
52 super.onTestResult(test); | 52 super.onTestResult(test); |
53 if (test.result == PASS) { | 53 if (test.result == PASS) { |
54 _pass++; | 54 _pass++; |
55 _progressLine(_start, _pass, _fail, test.description); | 55 _progressLine(_start, _pass, _fail, test.description); |
56 } else { | 56 } else { |
57 _fail++; | 57 _fail++; |
58 _progressLine(_start, _pass, _fail, test.description); | 58 _progressLine(_start, _pass, _fail, test.description); |
59 stdout.write('\n'); | 59 _print(); |
60 if (test.message != '') { | 60 if (test.message != '') { |
61 print(indent(test.message)); | 61 _print(indent(test.message)); |
62 } | 62 } |
63 | 63 |
64 if (test.stackTrace != null) { | 64 if (test.stackTrace != null) { |
65 print(indent(test.stackTrace.toString())); | 65 _print(indent(test.stackTrace.toString())); |
66 } | 66 } |
67 } | 67 } |
68 } | 68 } |
69 | 69 |
70 void onTestResultChanged(TestCase test) { | 70 void onTestResultChanged(TestCase test) { |
71 _pass--; | 71 _pass--; |
72 _fail++; | 72 _fail++; |
73 _progressLine(_start, _pass, _fail, test.description); | 73 _progressLine(_start, _pass, _fail, test.description); |
74 stdout.write('\n'); | 74 _print(); |
75 if (test.message != '') { | 75 if (test.message != '') { |
76 print(indent(test.message)); | 76 _print(indent(test.message)); |
77 } | 77 } |
78 | 78 |
79 if (test.stackTrace != null) { | 79 if (test.stackTrace != null) { |
80 print(indent(test.stackTrace.toString())); | 80 _print(indent(test.stackTrace.toString())); |
81 } | 81 } |
82 } | 82 } |
83 | 83 |
84 void onDone(bool success) { | 84 void onDone(bool success) { |
85 // Override and don't call the superclass onDone() to avoid printing the | 85 // Override and don't call the superclass onDone() to avoid printing the |
86 // "unittest-suite-..." boilerplate. | 86 // "unittest-suite-..." boilerplate. |
87 Future.wait([stdout.close(), stderr.close()]).then((_) { | 87 Future.wait([stdout.close(), stderr.close()]).then((_) { |
88 _receivePort.close(); | 88 _receivePort.close(); |
89 exit(success ? 0 : 1); | 89 exit(success ? 0 : 1); |
90 }); | 90 }); |
91 } | 91 } |
92 | 92 |
93 void onSummary(int passed, int failed, int errors, List<TestCase> results, | 93 void onSummary(int passed, int failed, int errors, List<TestCase> results, |
94 String uncaughtError) { | 94 String uncaughtError) { |
95 var success = false; | 95 var success = false; |
96 if (passed == 0 && failed == 0 && errors == 0 && uncaughtError == null) { | 96 if (passed == 0 && failed == 0 && errors == 0 && uncaughtError == null) { |
97 print('\nNo tests ran.'); | 97 _print('\nNo tests ran.'); |
98 } else if (failed == 0 && errors == 0 && uncaughtError == null) { | 98 } else if (failed == 0 && errors == 0 && uncaughtError == null) { |
99 _progressLine(_start, _pass, _fail, 'All tests passed!', _NONE); | 99 _progressLine(_start, _pass, _fail, 'All tests passed!', _NONE); |
100 stdout.write('\n'); | 100 _print(); |
101 success = true; | 101 success = true; |
102 } else { | 102 } else { |
103 _progressLine(_start, _pass, _fail, 'Some tests failed.', _RED); | 103 _progressLine(_start, _pass, _fail, 'Some tests failed.', _RED); |
104 stdout.write('\n'); | 104 _print(); |
105 if (uncaughtError != null) { | 105 if (uncaughtError != null) { |
106 print('Top-level uncaught error: $uncaughtError'); | 106 _print('Top-level uncaught error: $uncaughtError'); |
107 } | 107 } |
108 print('$passed PASSED, $failed FAILED, $errors ERRORS'); | 108 _print('$passed PASSED, $failed FAILED, $errors ERRORS'); |
109 } | 109 } |
110 } | 110 } |
111 | 111 |
112 int _lastLength = 0; | 112 int _lastLength = 0; |
113 | 113 |
114 final int _nonVisiblePrefix = 1 + _GREEN.length + _NONE.length; | 114 final int _nonVisiblePrefix = 1 + _GREEN.length + _NONE.length; |
115 | 115 |
116 void _progressLine(DateTime startTime, int passed, int failed, String message, | 116 void _progressLine(DateTime startTime, int passed, int failed, String message, |
117 [String color = _NONE]) { | 117 [String color = _NONE]) { |
118 var duration = (new DateTime.now()).difference(startTime); | 118 var duration = (new DateTime.now()).difference(startTime); |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
194 // the beginning of a word. | 194 // the beginning of a word. |
195 var res = text.substring(text.length - maxLength + 4); | 195 var res = text.substring(text.length - maxLength + 4); |
196 var firstSpace = res.indexOf(' '); | 196 var firstSpace = res.indexOf(' '); |
197 if (firstSpace > 0) { | 197 if (firstSpace > 0) { |
198 res = res.substring(firstSpace); | 198 res = res.substring(firstSpace); |
199 } | 199 } |
200 return '...$res'; | 200 return '...$res'; |
201 } | 201 } |
202 } | 202 } |
203 | 203 |
| 204 // TODO(sigmund): delete when dartbug.com/17269 is fixed (use `print` instead). |
| 205 _print([value = '']) => stdout.write('$value\n'); |
| 206 |
204 void useCompactVMConfiguration() { | 207 void useCompactVMConfiguration() { |
205 // If the test is running on the Dart buildbots, we don't want to use this | 208 // If the test is running on the Dart buildbots, we don't want to use this |
206 // config since it's output may not be what the bots expect. | 209 // config since it's output may not be what the bots expect. |
207 if (Platform.environment['LOGNAME'] == 'chrome-bot') { | 210 if (Platform.environment['LOGNAME'] == 'chrome-bot') { |
208 return; | 211 return; |
209 } | 212 } |
210 | 213 |
211 unittestConfiguration = _singleton; | 214 unittestConfiguration = _singleton; |
212 } | 215 } |
213 | 216 |
214 final _singleton = new CompactVMConfiguration(); | 217 final _singleton = new CompactVMConfiguration(); |
OLD | NEW |