| 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 simple unit test library for running tests on the VM. | 6 * A simple unit test library for running tests on the VM. |
| 7 */ | 7 */ |
| 8 library unittest_vm_config; | 8 library unittest_vm_config; |
| 9 | 9 |
| 10 import 'dart:io'; | 10 import 'dart:io'; |
| 11 import 'unittest.dart'; | 11 import 'unittest.dart'; |
| 12 | 12 |
| 13 class VMConfiguration extends Configuration { | 13 class VMConfiguration extends Configuration { |
| 14 // Color constants used for generating messages. |
| 15 final String GREEN_COLOR = '\u001b[32m'; |
| 16 final String RED_COLOR = '\u001b[31m'; |
| 17 final String MAGENTA_COLOR = '\u001b[35m'; |
| 18 final String NO_COLOR = '\u001b[0m'; |
| 19 |
| 20 // We make this public so the user can turn it off if they want. |
| 21 bool useColor; |
| 22 |
| 23 VMConfiguration() : |
| 24 super(), useColor = stdioType(stdout) == StdioType.TERMINAL; |
| 25 |
| 26 String formatResult(TestCase testCase) { |
| 27 String result = super.formatResult(testCase); |
| 28 if (useColor) { |
| 29 if (testCase.result == PASS) { |
| 30 return "${GREEN_COLOR}${result}${NO_COLOR}"; |
| 31 } else if (testCase.result == FAIL) { |
| 32 return "${RED_COLOR}${result}${NO_COLOR}"; |
| 33 } else if (testCase.result == ERROR) { |
| 34 return "${MAGENTA_COLOR}${result}${NO_COLOR}"; |
| 35 } |
| 36 } |
| 37 return result; |
| 38 } |
| 39 |
| 14 void onDone(bool success) { | 40 void onDone(bool success) { |
| 15 try { | 41 try { |
| 16 super.onDone(success); | 42 super.onDone(success); |
| 17 exit(0); | 43 exit(0); |
| 18 } catch (ex) { | 44 } catch (ex) { |
| 19 // A non-zero exit code is used by the test infrastructure to detect | 45 // A non-zero exit code is used by the test infrastructure to detect |
| 20 // failure. | 46 // failure. |
| 21 exit(1); | 47 exit(1); |
| 22 } | 48 } |
| 23 } | 49 } |
| 24 } | 50 } |
| 25 | 51 |
| 26 void useVMConfiguration() { | 52 void useVMConfiguration() { |
| 27 unittestConfiguration = _singleton; | 53 unittestConfiguration = _singleton; |
| 28 } | 54 } |
| 29 | 55 |
| 30 final _singleton = new VMConfiguration(); | 56 final _singleton = new VMConfiguration(); |
| OLD | NEW |