| OLD | NEW |
| 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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("test_progress"); | 5 #library("test_progress"); |
| 6 | 6 |
| 7 #import("test_runner.dart"); | 7 #import("test_runner.dart"); |
| 8 #import("test_suite.dart"); | 8 #import("test_suite.dart"); |
| 9 | 9 |
| 10 class ProgressIndicator { | 10 class ProgressIndicator { |
| 11 ProgressIndicator(this._startTime, this._printTiming) : _tests = []; | 11 ProgressIndicator(this._startTime, this._printTiming) |
| 12 : _tests = [], _failureSummary = []; |
| 12 | 13 |
| 13 factory ProgressIndicator.fromName(String name, | 14 factory ProgressIndicator.fromName(String name, |
| 14 Date startTime, | 15 Date startTime, |
| 15 bool printTiming) { | 16 bool printTiming) { |
| 16 switch (name) { | 17 switch (name) { |
| 17 case 'compact': | 18 case 'compact': |
| 18 return new CompactProgressIndicator(startTime, printTiming); | 19 return new CompactProgressIndicator(startTime, printTiming); |
| 19 case 'color': | 20 case 'color': |
| 20 return new ColorProgressIndicator(startTime, printTiming); | 21 return new ColorProgressIndicator(startTime, printTiming); |
| 21 case 'line': | 22 case 'line': |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 67 }); | 68 }); |
| 68 for (int i = 0; i < 20 && i < _tests.length; i++) { | 69 for (int i = 0; i < 20 && i < _tests.length; i++) { |
| 69 var name = _tests[i].displayName; | 70 var name = _tests[i].displayName; |
| 70 var duration = _tests[i].output.time; | 71 var duration = _tests[i].output.time; |
| 71 print('${duration} - $name'); | 72 print('${duration} - $name'); |
| 72 } | 73 } |
| 73 } | 74 } |
| 74 } | 75 } |
| 75 | 76 |
| 76 void allDone() { | 77 void allDone() { |
| 78 _printFailureSummary(); |
| 77 _printStatus(); | 79 _printStatus(); |
| 78 _printTimingInformation(); | 80 _printTimingInformation(); |
| 79 exit(_failedTests > 0 ? 1 : 0); | 81 exit(_failedTests > 0 ? 1 : 0); |
| 80 } | 82 } |
| 81 | 83 |
| 82 abstract _printStartProgress(TestCase test); | 84 abstract _printStartProgress(TestCase test); |
| 83 abstract _printDoneProgress(TestCase test); | 85 abstract _printDoneProgress(TestCase test); |
| 84 | 86 |
| 85 String _pad(String s, int length) { | 87 String _pad(String s, int length) { |
| 86 StringBuffer buffer = new StringBuffer(); | 88 StringBuffer buffer = new StringBuffer(); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 101 } | 103 } |
| 102 } | 104 } |
| 103 | 105 |
| 104 String _timeString(Duration d) { | 106 String _timeString(Duration d) { |
| 105 var min = d.inMinutes; | 107 var min = d.inMinutes; |
| 106 var sec = d.inSeconds % 60; | 108 var sec = d.inSeconds % 60; |
| 107 return '${_padTime(min)}:${_padTime(sec)}'; | 109 return '${_padTime(min)}:${_padTime(sec)}'; |
| 108 } | 110 } |
| 109 | 111 |
| 110 void _printFailureOutput(TestCase test) { | 112 void _printFailureOutput(TestCase test) { |
| 111 print('\nFAILED: ${test.displayName}'); | 113 List<String> output = new List<String>(); |
| 114 output.add(''); |
| 115 output.add('FAILED: ${test.displayName}'); |
| 112 StringBuffer expected = new StringBuffer(); | 116 StringBuffer expected = new StringBuffer(); |
| 113 expected.add('Expected: '); | 117 expected.add('Expected: '); |
| 114 for (var expectation in test.expectedOutcomes) { | 118 for (var expectation in test.expectedOutcomes) { |
| 115 expected.add('$expectation '); | 119 expected.add('$expectation '); |
| 116 } | 120 } |
| 117 print(expected.toString()); | 121 output.add(expected.toString()); |
| 118 print('Actual: ${test.output.result}'); | 122 output.add('Actual: ${test.output.result}'); |
| 119 if (!test.output.stdout.isEmpty()) { | 123 if (!test.output.stdout.isEmpty()) { |
| 120 print('\nstdout:'); | 124 output.add(''); |
| 121 test.output.stdout.forEach((s) => print(s)); | 125 output.add('stdout:'); |
| 126 for (var s in test.output.stdout) { |
| 127 output.add(s); |
| 128 } |
| 122 } | 129 } |
| 123 if (!test.output.stderr.isEmpty()) { | 130 if (!test.output.stderr.isEmpty()) { |
| 124 print('\nstderr:'); | 131 output.add(''); |
| 125 test.output.stderr.forEach((s) => print(s)); | 132 output.add('stderr:'); |
| 133 for (var s in test.output.stderr) { |
| 134 output.add(s); |
| 135 } |
| 126 } | 136 } |
| 127 if (test is BrowserTestCase && test.dynamic.compilerPath != null) { | 137 if (test is BrowserTestCase && test.dynamic.compilerPath != null) { |
| 128 print('\nCompilation command: ${test.dynamic.compilerPath} ' + | 138 output.add(''); |
| 129 Strings.join(test.dynamic.compilerArguments, ' ')); | 139 output.add('Compilation command: ${test.dynamic.compilerPath} ' + |
| 140 Strings.join(test.dynamic.compilerArguments, ' ')); |
| 130 } | 141 } |
| 131 print('\nCommand line: ${test.commandLine}'); | 142 output.add(''); |
| 143 output.add('Command line: ${test.commandLine}'); |
| 144 |
| 145 for (String line in output) { |
| 146 print(line); |
| 147 } |
| 148 _failureSummary.addAll(output); |
| 149 } |
| 150 |
| 151 void _printFailureSummary() { |
| 152 for (String line in _failureSummary) { |
| 153 print(line); |
| 154 } |
| 155 print(''); |
| 132 } | 156 } |
| 133 | 157 |
| 134 void _printStatus() { | 158 void _printStatus() { |
| 135 if (_failedTests == 0) { | 159 if (_failedTests == 0) { |
| 136 print('\n==='); | 160 print('\n==='); |
| 137 print('=== All tests succeeded'); | 161 print('=== All tests succeeded'); |
| 138 print('===\n'); | 162 print('===\n'); |
| 139 } else { | 163 } else { |
| 140 var pluralSuffix = _failedTests != 1 ? 's' : ''; | 164 var pluralSuffix = _failedTests != 1 ? 's' : ''; |
| 141 print('\n==='); | 165 print('\n==='); |
| 142 print('=== ${_failedTests} test$pluralSuffix failed'); | 166 print('=== ${_failedTests} test$pluralSuffix failed'); |
| 143 print('===\n'); | 167 print('===\n'); |
| 144 } | 168 } |
| 145 } | 169 } |
| 146 | 170 |
| 147 int _completedTests() => _passedTests + _failedTests; | 171 int _completedTests() => _passedTests + _failedTests; |
| 148 | 172 |
| 149 int _foundTests = 0; | 173 int _foundTests = 0; |
| 150 int _passedTests = 0; | 174 int _passedTests = 0; |
| 151 int _failedTests = 0; | 175 int _failedTests = 0; |
| 152 bool _allTestsKnown = false; | 176 bool _allTestsKnown = false; |
| 153 Date _startTime; | 177 Date _startTime; |
| 154 bool _printTiming; | 178 bool _printTiming; |
| 155 List<TestCase> _tests; | 179 List<TestCase> _tests; |
| 180 List<String> _failureSummary; |
| 156 } | 181 } |
| 157 | 182 |
| 158 | 183 |
| 159 class CompactIndicator extends ProgressIndicator { | 184 class CompactIndicator extends ProgressIndicator { |
| 160 CompactIndicator(Date startTime, bool printTiming) | 185 CompactIndicator(Date startTime, bool printTiming) |
| 161 : super(startTime, printTiming); | 186 : super(startTime, printTiming); |
| 162 | 187 |
| 163 void allDone() { | 188 void allDone() { |
| 164 stdout.write('\n'.charCodes()); | 189 stdout.write('\n'.charCodes()); |
| 190 _printFailureSummary(); |
| 165 _printTimingInformation(); | 191 _printTimingInformation(); |
| 192 if (_failedTests > 0) { |
| 193 // We may have printed many failure logs, so reprint the summary data. |
| 194 _printProgress(); |
| 195 print(''); |
| 196 } |
| 166 stdout.close(); | 197 stdout.close(); |
| 167 exit(_failedTests > 0 ? 1 : 0); | 198 exit(_failedTests > 0 ? 1 : 0); |
| 168 } | 199 } |
| 169 | 200 |
| 170 void allTestsKnown() { | 201 void allTestsKnown() { |
| 171 if (!_allTestsKnown) { | 202 if (!_allTestsKnown) { |
| 172 // Clear progress indicator before printing summary report. | 203 // Clear progress indicator before printing summary report. |
| 173 stdout.write( | 204 stdout.write( |
| 174 '\r \r'.charCodes()); | 205 '\r \r'.charCodes()); |
| 175 SummaryReport.printReport(); | 206 SummaryReport.printReport(); |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 294 var status = 'pass'; | 325 var status = 'pass'; |
| 295 if (test.output.unexpectedOutput) { | 326 if (test.output.unexpectedOutput) { |
| 296 status = 'fail'; | 327 status = 'fail'; |
| 297 } | 328 } |
| 298 var percent = ((_completedTests() / _foundTests) * 100).toInt().toString(); | 329 var percent = ((_completedTests() / _foundTests) * 100).toInt().toString(); |
| 299 print('Done ${test.displayName}: $status'); | 330 print('Done ${test.displayName}: $status'); |
| 300 print('@@@STEP_CLEAR@@@'); | 331 print('@@@STEP_CLEAR@@@'); |
| 301 print('@@@STEP_TEXT@ $percent% +$_passedTests -$_failedTests @@@'); | 332 print('@@@STEP_TEXT@ $percent% +$_passedTests -$_failedTests @@@'); |
| 302 } | 333 } |
| 303 } | 334 } |
| OLD | NEW |