OLD | NEW |
(Empty) | |
| 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 |
| 3 // BSD-style license that can be found in the LICENSE file. |
| 4 |
| 5 /// A simple unit test library for running tests on the VM. |
| 6 library unittest.vm_config; |
| 7 |
| 8 import 'dart:async'; |
| 9 import 'dart:io'; |
| 10 import 'unittest.dart'; |
| 11 |
| 12 class VMConfiguration extends SimpleConfiguration { |
| 13 // Color constants used for generating messages. |
| 14 final String GREEN_COLOR = '\u001b[32m'; |
| 15 final String RED_COLOR = '\u001b[31m'; |
| 16 final String MAGENTA_COLOR = '\u001b[35m'; |
| 17 final String NO_COLOR = '\u001b[0m'; |
| 18 |
| 19 // We make this public so the user can turn it off if they want. |
| 20 bool useColor; |
| 21 |
| 22 VMConfiguration() |
| 23 : super(), |
| 24 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 |
| 40 void onInit() { |
| 41 super.onInit(); |
| 42 filterStacks = formatStacks = true; |
| 43 } |
| 44 |
| 45 void onDone(bool success) { |
| 46 int status; |
| 47 try { |
| 48 super.onDone(success); |
| 49 status = 0; |
| 50 } catch (ex) { |
| 51 // A non-zero exit code is used by the test infrastructure to detect |
| 52 // failure. |
| 53 status = 1; |
| 54 } |
| 55 Future.wait([stdout.close(), stderr.close()]).then((_) { |
| 56 exit(status); |
| 57 }); |
| 58 } |
| 59 } |
| 60 |
| 61 void useVMConfiguration() { |
| 62 unittestConfiguration = _singleton; |
| 63 } |
| 64 |
| 65 final _singleton = new VMConfiguration(); |
OLD | NEW |