Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012, 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("dart:io"); | 7 #import("dart:io"); |
| 8 #import("test_runner.dart"); | 8 #import("test_runner.dart"); |
| 9 #import("test_suite.dart"); | 9 #import("test_suite.dart"); |
| 10 #import("status_file_parser.dart"); | |
| 11 | |
| 12 const FAILED_FLAKY_TESTS_LOGFILE = ".flaky.log"; | |
|
ricow1
2012/11/08 09:49:13
Add comment stating explicitly what this is used f
kustermann
2012/11/08 10:24:41
Done.
| |
| 10 | 13 |
| 11 class ProgressIndicator { | 14 class ProgressIndicator { |
| 12 ProgressIndicator(this._startTime, this._printTiming) | 15 ProgressIndicator(this._startTime, this._printTiming) |
| 13 : _tests = [], _failureSummary = []; | 16 : _tests = [], _failureSummary = []; |
| 14 | 17 |
| 15 factory ProgressIndicator.fromName(String name, | 18 factory ProgressIndicator.fromName(String name, |
| 16 Date startTime, | 19 Date startTime, |
| 17 bool printTiming) { | 20 bool printTiming) { |
| 18 switch (name) { | 21 switch (name) { |
| 19 case 'compact': | 22 case 'compact': |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 38 } | 41 } |
| 39 } | 42 } |
| 40 | 43 |
| 41 void testAdded() { _foundTests++; } | 44 void testAdded() { _foundTests++; } |
| 42 | 45 |
| 43 void start(TestCase test) { | 46 void start(TestCase test) { |
| 44 _printStartProgress(test); | 47 _printStartProgress(test); |
| 45 } | 48 } |
| 46 | 49 |
| 47 void done(TestCase test) { | 50 void done(TestCase test) { |
| 51 if (test.isFlaky && test.output.result != PASS) { | |
| 52 var buf = new StringBuffer(); | |
| 53 for (var l in _buildFailureOutput(test)) { | |
|
ricow1
2012/11/08 09:49:13
alternatively some thing like
var buf = _buildFail
kustermann
2012/11/08 10:24:41
I think that this would not improve readability.
| |
| 54 buf.add("${l}\n"); | |
| 55 } | |
| 56 _appendToFlakyFile(buf.toString()); | |
| 57 } | |
| 58 | |
| 48 if (test.output.unexpectedOutput) { | 59 if (test.output.unexpectedOutput) { |
| 49 _failedTests++; | 60 _failedTests++; |
| 50 _printFailureOutput(test); | 61 _printFailureOutput(test); |
| 51 } else { | 62 } else { |
| 52 _passedTests++; | 63 _passedTests++; |
| 53 } | 64 } |
| 54 _printDoneProgress(test); | 65 _printDoneProgress(test); |
| 55 // If we need to print timing information we hold on to all completed | 66 // If we need to print timing information we hold on to all completed |
| 56 // tests. | 67 // tests. |
| 57 if (_printTiming) _tests.add(test); | 68 if (_printTiming) _tests.add(test); |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 113 | 124 |
| 114 String _timeString(Duration d) { | 125 String _timeString(Duration d) { |
| 115 var min = d.inMinutes; | 126 var min = d.inMinutes; |
| 116 var sec = d.inSeconds % 60; | 127 var sec = d.inSeconds % 60; |
| 117 return '${_padTime(min)}:${_padTime(sec)}'; | 128 return '${_padTime(min)}:${_padTime(sec)}'; |
| 118 } | 129 } |
| 119 | 130 |
| 120 String _header(String header) => header; | 131 String _header(String header) => header; |
| 121 | 132 |
| 122 void _printFailureOutput(TestCase test) { | 133 void _printFailureOutput(TestCase test) { |
| 134 var failureOutput = _buildFailureOutput(test); | |
| 135 | |
| 136 for (var line in failureOutput) { | |
| 137 print(line); | |
| 138 } | |
| 139 | |
|
ricow1
2012/11/08 09:49:13
remove whitespaces
kustermann
2012/11/08 10:24:41
Done.
| |
| 140 _failureSummary.addAll(failureOutput); | |
| 141 } | |
| 142 | |
|
ricow1
2012/11/08 09:49:13
remove whitespaces
kustermann
2012/11/08 10:24:41
Done.
| |
| 143 List<String> _buildFailureOutput(TestCase test) { | |
| 123 List<String> output = new List<String>(); | 144 List<String> output = new List<String>(); |
| 124 output.add(''); | 145 output.add(''); |
| 125 output.add(_header('FAILED: ${test.configurationString}' | 146 output.add(_header('FAILED: ${test.configurationString}' |
| 126 ' ${test.displayName}')); | 147 ' ${test.displayName}')); |
| 127 StringBuffer expected = new StringBuffer(); | 148 StringBuffer expected = new StringBuffer(); |
| 128 expected.add('Expected: '); | 149 expected.add('Expected: '); |
| 129 for (var expectation in test.expectedOutcomes) { | 150 for (var expectation in test.expectedOutcomes) { |
| 130 expected.add('$expectation '); | 151 expected.add('$expectation '); |
| 131 } | 152 } |
| 132 output.add(expected.toString()); | 153 output.add(expected.toString()); |
| (...skipping 30 matching lines...) Expand all Loading... | |
| 163 for (var s in test.output.stderr) { | 184 for (var s in test.output.stderr) { |
| 164 output.add(s); | 185 output.add(s); |
| 165 } | 186 } |
| 166 } | 187 } |
| 167 for (Command c in test.commands) { | 188 for (Command c in test.commands) { |
| 168 output.add(''); | 189 output.add(''); |
| 169 String message = (c == test.commands.last | 190 String message = (c == test.commands.last |
| 170 ? "Command line" : "Compilation command"); | 191 ? "Command line" : "Compilation command"); |
| 171 output.add('$message: ${c.commandLine}'); | 192 output.add('$message: ${c.commandLine}'); |
| 172 } | 193 } |
| 173 for (String line in output) { | 194 return output; |
| 174 print(line); | |
| 175 } | |
| 176 _failureSummary.addAll(output); | |
| 177 } | 195 } |
| 178 | 196 |
| 179 void _printFailureSummary() { | 197 void _printFailureSummary() { |
| 180 for (String line in _failureSummary) { | 198 for (String line in _failureSummary) { |
| 181 print(line); | 199 print(line); |
| 182 } | 200 } |
| 183 print(''); | 201 print(''); |
| 184 } | 202 } |
| 185 | 203 |
| 186 void _printStatus() { | 204 void _printStatus() { |
| 187 if (_failedTests == 0) { | 205 if (_failedTests == 0) { |
| 188 print('\n==='); | 206 print('\n==='); |
| 189 print('=== All tests succeeded'); | 207 print('=== All tests succeeded'); |
| 190 print('===\n'); | 208 print('===\n'); |
| 191 } else { | 209 } else { |
| 192 var pluralSuffix = _failedTests != 1 ? 's' : ''; | 210 var pluralSuffix = _failedTests != 1 ? 's' : ''; |
| 193 print('\n==='); | 211 print('\n==='); |
| 194 print('=== ${_failedTests} test$pluralSuffix failed'); | 212 print('=== ${_failedTests} test$pluralSuffix failed'); |
| 195 print('===\n'); | 213 print('===\n'); |
| 196 } | 214 } |
| 197 } | 215 } |
| 198 | 216 |
| 217 void _appendToFlakyFile(String msg) { | |
| 218 var file = new File(FAILED_FLAKY_TESTS_LOGFILE); | |
| 219 var fd = file.openSync(FileMode.APPEND); | |
| 220 fd.writeStringSync(msg); | |
| 221 fd.closeSync(); | |
| 222 } | |
| 223 | |
| 199 int get numFailedTests => _failedTests; | 224 int get numFailedTests => _failedTests; |
| 200 | 225 |
| 201 int _completedTests() => _passedTests + _failedTests; | 226 int _completedTests() => _passedTests + _failedTests; |
| 202 | 227 |
| 203 int _foundTests = 0; | 228 int _foundTests = 0; |
| 204 int _passedTests = 0; | 229 int _passedTests = 0; |
| 205 int _failedTests = 0; | 230 int _failedTests = 0; |
| 206 bool _allTestsKnown = false; | 231 bool _allTestsKnown = false; |
| 207 Date _startTime; | 232 Date _startTime; |
| 208 bool _printTiming; | 233 bool _printTiming; |
| (...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 441 print(''); | 466 print(''); |
| 442 print('$config:'); | 467 print('$config:'); |
| 443 statuses.sort((a, b) => a.compareTo(b)); | 468 statuses.sort((a, b) => a.compareTo(b)); |
| 444 for (String status in statuses) { | 469 for (String status in statuses) { |
| 445 print(' $status'); | 470 print(' $status'); |
| 446 } | 471 } |
| 447 }); | 472 }); |
| 448 _printStatus(); | 473 _printStatus(); |
| 449 } | 474 } |
| 450 } | 475 } |
| OLD | NEW |