Chromium Code Reviews| 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 library command_line_config; | 5 library command_line_config; |
| 6 | 6 |
| 7 import 'dart:io'; | 7 import 'dart:io'; |
| 8 | 8 |
| 9 import '../../../pkg/path/lib/path.dart' as path; | 9 import '../../../pkg/path/lib/path.dart' as path; |
| 10 import '../../../pkg/unittest/lib/unittest.dart'; | 10 import '../../../pkg/unittest/lib/unittest.dart'; |
| 11 import '../../pub/utils.dart'; | 11 import '../../pub/utils.dart'; |
| 12 | 12 |
| 13 const _GREEN = '\u001b[32m'; | 13 /// Gets a "special" string (ANSI escape or Unicode). On Windows, returns |
| 14 const _RED = '\u001b[31m'; | 14 /// something else since those aren't supported. |
| 15 const _MAGENTA = '\u001b[35m'; | 15 String _getSpecial(String color, [String onWindows = '']) { |
| 16 const _NONE = '\u001b[0m'; | 16 // No ANSI escapes on windows. |
| 17 if (Platform.operatingSystem == 'windows') return onWindows; | |
| 18 return color; | |
| 19 } | |
| 17 | 20 |
| 18 /// Pretty Unicode characters! | 21 /// Pretty Unicode characters! |
| 19 const _CHECKBOX = '\u2713'; | 22 final _checkBox = _getSpecial('\u2713', 'PASS'); |
|
nweiz
2013/02/05 03:26:14
Style nit: "_checkbox"
Bob Nystrom
2013/02/05 04:21:53
Done.
| |
| 20 const _BALLOT_X = '\u2717'; | 23 final _ballotX = _getSpecial('\u2717', 'FAIL'); |
| 21 const _LAMBDA = '\u03bb'; | 24 final _lambda = _getSpecial('\u03bb', '<fn>'); |
| 25 | |
| 26 final _green = _getSpecial('\u001b[32m'); | |
| 27 final _red = _getSpecial('\u001b[31m'); | |
| 28 final _magenta = _getSpecial('\u001b[35m'); | |
| 29 final _none = _getSpecial('\u001b[0m'); | |
| 22 | 30 |
| 23 /// A custom unittest configuration for running the pub tests from the | 31 /// A custom unittest configuration for running the pub tests from the |
| 24 /// command-line and generating human-friendly output. | 32 /// command-line and generating human-friendly output. |
| 25 class CommandLineConfiguration extends Configuration { | 33 class CommandLineConfiguration extends Configuration { |
| 26 void onInit() { | 34 void onInit() { |
| 27 // Do nothing. Overridden to prevent the base class from printing. | 35 // Do nothing. Overridden to prevent the base class from printing. |
| 28 } | 36 } |
| 29 | 37 |
| 30 void onTestResult(TestCase testCase) { | 38 void onTestResult(TestCase testCase) { |
| 31 var result; | 39 var result; |
| 32 switch (testCase.result) { | 40 switch (testCase.result) { |
| 33 case PASS: result = '$_GREEN$_CHECKBOX$_NONE'; break; | 41 case PASS: result = '$_green$_checkBox$_none'; break; |
| 34 case FAIL: result = '$_RED$_BALLOT_X$_NONE'; break; | 42 case FAIL: result = '$_red$_ballotX$_none'; break; |
| 35 case ERROR: result = '$_MAGENTA?$_NONE'; break; | 43 case ERROR: result = '$_magenta?$_none'; break; |
| 36 } | 44 } |
| 37 print('$result ${testCase.description}'); | 45 print('$result ${testCase.description}'); |
| 38 | 46 |
| 39 if (testCase.message != '') { | 47 if (testCase.message != '') { |
| 40 print(_indent(testCase.message)); | 48 print(_indent(testCase.message)); |
| 41 } | 49 } |
| 42 | 50 |
| 43 _printStackTrace(testCase.stackTrace); | 51 _printStackTrace(testCase.stackTrace); |
| 44 | 52 |
| 45 currentTestCase = null; | 53 currentTestCase = null; |
| 46 } | 54 } |
| 47 | 55 |
| 48 void onSummary(int passed, int failed, int errors, List<TestCase> results, | 56 void onSummary(int passed, int failed, int errors, List<TestCase> results, |
| 49 String uncaughtError) { | 57 String uncaughtError) { |
| 50 var success = false; | 58 var success = false; |
| 51 if (uncaughtError != null) { | 59 if (uncaughtError != null) { |
| 52 print('Top-level uncaught error: $uncaughtError'); | 60 print('Top-level uncaught error: $uncaughtError'); |
| 53 } else if (errors != 0) { | 61 } else if (errors != 0) { |
| 54 print('${_GREEN}$passed${_NONE} passed, ${_RED}$failed${_NONE} failed, ' | 62 print('${_green}$passed${_none} passed, ${_red}$failed${_none} failed, ' |
| 55 '${_MAGENTA}$errors${_NONE} errors.'); | 63 '${_magenta}$errors${_none} errors.'); |
| 56 } else if (failed != 0) { | 64 } else if (failed != 0) { |
| 57 print('${_GREEN}$passed${_NONE} passed, ${_RED}$failed${_NONE} ' | 65 print('${_green}$passed${_none} passed, ${_red}$failed${_none} ' |
| 58 'failed.'); | 66 'failed.'); |
| 59 } else if (passed == 0) { | 67 } else if (passed == 0) { |
| 60 print('No tests found.'); | 68 print('No tests found.'); |
| 61 } else { | 69 } else { |
| 62 print('All ${_GREEN}$passed${_NONE} tests passed!'); | 70 print('All ${_green}$passed${_none} tests passed!'); |
| 63 success = true; | 71 success = true; |
| 64 } | 72 } |
| 65 } | 73 } |
| 66 | 74 |
| 67 void onDone(bool success) { | 75 void onDone(bool success) { |
| 68 if (!success) exit(1); | 76 if (!success) exit(1); |
| 69 } | 77 } |
| 70 | 78 |
| 71 void _printStackTrace(String stackTrace) { | 79 void _printStackTrace(String stackTrace) { |
| 72 if (stackTrace == null || stackTrace == '') return; | 80 if (stackTrace == null || stackTrace == '') return; |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 147 if (match == null) throw "Couldn't parse stack trace line '$text'."; | 155 if (match == null) throw "Couldn't parse stack trace line '$text'."; |
| 148 isCore = true; | 156 isCore = true; |
| 149 } | 157 } |
| 150 | 158 |
| 151 var library = match[2]; | 159 var library = match[2]; |
| 152 if (!isCore) { | 160 if (!isCore) { |
| 153 // Make the library path relative to the entrypoint. | 161 // Make the library path relative to the entrypoint. |
| 154 library = path.relative(library); | 162 library = path.relative(library); |
| 155 } | 163 } |
| 156 | 164 |
| 157 var member = match[1].replaceAll("<anonymous closure>", _LAMBDA); | 165 var member = match[1].replaceAll("<anonymous closure>", _lambda); |
| 158 return new _StackFrame._(isCore, library, match[3], match[4], member); | 166 return new _StackFrame._(isCore, library, match[3], match[4], member); |
| 159 } | 167 } |
| 160 } | 168 } |
| OLD | NEW |