| 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 | 16 |
| 16 import 'unittest.dart'; | 17 import 'unittest.dart'; |
| 17 import 'vm_config.dart'; | 18 import 'vm_config.dart'; |
| 18 | 19 |
| 19 const String _GREEN = '\u001b[32m'; | 20 const String _GREEN = '\u001b[32m'; |
| 20 const String _RED = '\u001b[31m'; | 21 const String _RED = '\u001b[31m'; |
| 21 const String _NONE = '\u001b[0m'; | 22 const String _NONE = '\u001b[0m'; |
| 22 | 23 |
| 23 const int MAX_LINE = 80; | 24 const int MAX_LINE = 80; |
| 24 | 25 |
| 25 class CompactVMConfiguration extends VMConfiguration { | 26 class CompactVMConfiguration extends VMConfiguration { |
| 27 // The VM won't shut down if a receive port is open. Use this to make sure |
| 28 // we correctly wait for asynchronous tests. |
| 29 ReceivePort _receivePort; |
| 30 |
| 26 DateTime _start; | 31 DateTime _start; |
| 27 int _pass = 0; | 32 int _pass = 0; |
| 28 int _fail = 0; | 33 int _fail = 0; |
| 29 | 34 |
| 30 void onInit() { | 35 void onInit() { |
| 36 _receivePort = new ReceivePort(); |
| 31 // Override and don't call the superclass onInit() to avoid printing the | 37 // Override and don't call the superclass onInit() to avoid printing the |
| 32 // "unittest-suite-..." boilerplate. | 38 // "unittest-suite-..." boilerplate. |
| 33 } | 39 } |
| 34 | 40 |
| 35 void onStart() { | 41 void onStart() { |
| 36 _start = new DateTime.now(); | 42 _start = new DateTime.now(); |
| 37 } | 43 } |
| 38 | 44 |
| 39 void onTestStart(TestCase test) { | 45 void onTestStart(TestCase test) { |
| 40 super.onTestStart(test); | 46 super.onTestStart(test); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 57 if (test.stackTrace != null && test.stackTrace != '') { | 63 if (test.stackTrace != null && test.stackTrace != '') { |
| 58 print(_indent(test.stackTrace)); | 64 print(_indent(test.stackTrace)); |
| 59 } | 65 } |
| 60 } | 66 } |
| 61 } | 67 } |
| 62 | 68 |
| 63 void onDone(bool success) { | 69 void onDone(bool success) { |
| 64 // 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 |
| 65 // "unittest-suite-..." boilerplate. | 71 // "unittest-suite-..." boilerplate. |
| 66 Future.wait([stdout.close(), stderr.close()]).then((_) { | 72 Future.wait([stdout.close(), stderr.close()]).then((_) { |
| 73 _receivePort.close(); |
| 67 exit(success ? 0 : 1); | 74 exit(success ? 0 : 1); |
| 68 }); | 75 }); |
| 69 } | 76 } |
| 70 | 77 |
| 71 String _indent(String str) { | 78 String _indent(String str) { |
| 72 return str.split("\n").map((line) => " $line").join("\n"); | 79 return str.split("\n").map((line) => " $line").join("\n"); |
| 73 } | 80 } |
| 74 | 81 |
| 75 void onSummary(int passed, int failed, int errors, List<TestCase> results, | 82 void onSummary(int passed, int failed, int errors, List<TestCase> results, |
| 76 String uncaughtError) { | 83 String uncaughtError) { |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 187 // 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 |
| 188 // 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. |
| 189 if (Platform.environment.containsKey('BUILDBOT_BUILDERNAME')) { | 196 if (Platform.environment.containsKey('BUILDBOT_BUILDERNAME')) { |
| 190 return; | 197 return; |
| 191 } | 198 } |
| 192 | 199 |
| 193 unittestConfiguration = _singleton; | 200 unittestConfiguration = _singleton; |
| 194 } | 201 } |
| 195 | 202 |
| 196 final _singleton = new CompactVMConfiguration(); | 203 final _singleton = new CompactVMConfiguration(); |
| OLD | NEW |