| 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 | 10 |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 136 output.add('Unexpected compile-time error.'); | 136 output.add('Unexpected compile-time error.'); |
| 137 } else { | 137 } else { |
| 138 if (test.info.hasCompileError) { | 138 if (test.info.hasCompileError) { |
| 139 output.add('Compile-time error expected.'); | 139 output.add('Compile-time error expected.'); |
| 140 } | 140 } |
| 141 if (test.info.hasRuntimeError) { | 141 if (test.info.hasRuntimeError) { |
| 142 output.add('Runtime error expected.'); | 142 output.add('Runtime error expected.'); |
| 143 } | 143 } |
| 144 } | 144 } |
| 145 } | 145 } |
| 146 if (!test.output.diagnostics.isEmpty()) { | 146 if (!test.output.diagnostics.isEmpty) { |
| 147 String prefix = 'diagnostics:'; | 147 String prefix = 'diagnostics:'; |
| 148 for (var s in test.output.diagnostics) { | 148 for (var s in test.output.diagnostics) { |
| 149 output.add('$prefix ${s}'); | 149 output.add('$prefix ${s}'); |
| 150 prefix = ' '; | 150 prefix = ' '; |
| 151 } | 151 } |
| 152 } | 152 } |
| 153 if (!test.output.stdout.isEmpty()) { | 153 if (!test.output.stdout.isEmpty) { |
| 154 output.add(''); | 154 output.add(''); |
| 155 output.add('stdout:'); | 155 output.add('stdout:'); |
| 156 for (var s in test.output.stdout) { | 156 for (var s in test.output.stdout) { |
| 157 output.add(s); | 157 output.add(s); |
| 158 } | 158 } |
| 159 } | 159 } |
| 160 if (!test.output.stderr.isEmpty()) { | 160 if (!test.output.stderr.isEmpty) { |
| 161 output.add(''); | 161 output.add(''); |
| 162 output.add('stderr:'); | 162 output.add('stderr:'); |
| 163 for (var s in test.output.stderr) { | 163 for (var s in test.output.stderr) { |
| 164 output.add(s); | 164 output.add(s); |
| 165 } | 165 } |
| 166 } | 166 } |
| 167 for (Command c in test.commands) { | 167 for (Command c in test.commands) { |
| 168 output.add(''); | 168 output.add(''); |
| 169 String message = (c == test.commands.last() | 169 String message = (c == test.commands.last |
| 170 ? "Command line" : "Compilation command"); | 170 ? "Command line" : "Compilation command"); |
| 171 output.add('$message: ${c.commandLine}'); | 171 output.add('$message: ${c.commandLine}'); |
| 172 } | 172 } |
| 173 for (String line in output) { | 173 for (String line in output) { |
| 174 print(line); | 174 print(line); |
| 175 } | 175 } |
| 176 _failureSummary.addAll(output); | 176 _failureSummary.addAll(output); |
| 177 } | 177 } |
| 178 | 178 |
| 179 void _printFailureSummary() { | 179 void _printFailureSummary() { |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 221 void _printDoneProgress(TestCase test) { } | 221 void _printDoneProgress(TestCase test) { } |
| 222 void allTestsKnown() { } | 222 void allTestsKnown() { } |
| 223 void allDone() { } | 223 void allDone() { } |
| 224 } | 224 } |
| 225 | 225 |
| 226 abstract class CompactIndicator extends ProgressIndicator { | 226 abstract class CompactIndicator extends ProgressIndicator { |
| 227 CompactIndicator(Date startTime, bool printTiming) | 227 CompactIndicator(Date startTime, bool printTiming) |
| 228 : super(startTime, printTiming); | 228 : super(startTime, printTiming); |
| 229 | 229 |
| 230 void allDone() { | 230 void allDone() { |
| 231 stdout.write('\n'.charCodes()); | 231 stdout.write('\n'.charCodes); |
| 232 _printFailureSummary(); | 232 _printFailureSummary(); |
| 233 _printTimingInformation(); | 233 _printTimingInformation(); |
| 234 if (_failedTests > 0) { | 234 if (_failedTests > 0) { |
| 235 // We may have printed many failure logs, so reprint the summary data. | 235 // We may have printed many failure logs, so reprint the summary data. |
| 236 _printProgress(); | 236 _printProgress(); |
| 237 print(''); | 237 print(''); |
| 238 } | 238 } |
| 239 stdout.close(); | 239 stdout.close(); |
| 240 stderr.close(); | 240 stderr.close(); |
| 241 if (_failedTests > 0) exit(1); | 241 if (_failedTests > 0) exit(1); |
| 242 } | 242 } |
| 243 | 243 |
| 244 void allTestsKnown() { | 244 void allTestsKnown() { |
| 245 if (!_allTestsKnown && SummaryReport.total > 0) { | 245 if (!_allTestsKnown && SummaryReport.total > 0) { |
| 246 // Clear progress indicator before printing summary report. | 246 // Clear progress indicator before printing summary report. |
| 247 stdout.write( | 247 stdout.write( |
| 248 '\r \r'.charCodes()); | 248 '\r \r'.charCodes); |
| 249 SummaryReport.printReport(); | 249 SummaryReport.printReport(); |
| 250 } | 250 } |
| 251 _allTestsKnown = true; | 251 _allTestsKnown = true; |
| 252 } | 252 } |
| 253 | 253 |
| 254 void _printStartProgress(TestCase test) => _printProgress(); | 254 void _printStartProgress(TestCase test) => _printProgress(); |
| 255 void _printDoneProgress(TestCase test) => _printProgress(); | 255 void _printDoneProgress(TestCase test) => _printProgress(); |
| 256 | 256 |
| 257 void _printProgress(); | 257 void _printProgress(); |
| 258 } | 258 } |
| 259 | 259 |
| 260 | 260 |
| 261 class CompactProgressIndicator extends CompactIndicator { | 261 class CompactProgressIndicator extends CompactIndicator { |
| 262 CompactProgressIndicator(Date startTime, bool printTiming) | 262 CompactProgressIndicator(Date startTime, bool printTiming) |
| 263 : super(startTime, printTiming); | 263 : super(startTime, printTiming); |
| 264 | 264 |
| 265 void _printProgress() { | 265 void _printProgress() { |
| 266 var percent = ((_completedTests() / _foundTests) * 100).toInt().toString(); | 266 var percent = ((_completedTests() / _foundTests) * 100).toInt().toString(); |
| 267 var progressPadded = _pad(_allTestsKnown ? percent : '--', 3); | 267 var progressPadded = _pad(_allTestsKnown ? percent : '--', 3); |
| 268 var passedPadded = _pad(_passedTests.toString(), 5); | 268 var passedPadded = _pad(_passedTests.toString(), 5); |
| 269 var failedPadded = _pad(_failedTests.toString(), 5); | 269 var failedPadded = _pad(_failedTests.toString(), 5); |
| 270 Duration d = (new Date.now()).difference(_startTime); | 270 Duration d = (new Date.now()).difference(_startTime); |
| 271 var progressLine = | 271 var progressLine = |
| 272 '\r[${_timeString(d)} | $progressPadded% | ' | 272 '\r[${_timeString(d)} | $progressPadded% | ' |
| 273 '+$passedPadded | -$failedPadded]'; | 273 '+$passedPadded | -$failedPadded]'; |
| 274 stdout.write(progressLine.charCodes()); | 274 stdout.write(progressLine.charCodes); |
| 275 } | 275 } |
| 276 } | 276 } |
| 277 | 277 |
| 278 | 278 |
| 279 class ColorProgressIndicator extends CompactIndicator { | 279 class ColorProgressIndicator extends CompactIndicator { |
| 280 ColorProgressIndicator(Date startTime, bool printTiming) | 280 ColorProgressIndicator(Date startTime, bool printTiming) |
| 281 : super(startTime, printTiming); | 281 : super(startTime, printTiming); |
| 282 | 282 |
| 283 static int BOLD = 1; | 283 static int BOLD = 1; |
| 284 static int GREEN = 32; | 284 static int GREEN = 32; |
| 285 static int RED = 31; | 285 static int RED = 31; |
| 286 static int NONE = 0; | 286 static int NONE = 0; |
| 287 | 287 |
| 288 addColorWrapped(List<int> codes, String string, int color) { | 288 addColorWrapped(List<int> codes, String string, int color) { |
| 289 codes.add(27); | 289 codes.add(27); |
| 290 codes.addAll('[${color}m'.charCodes()); | 290 codes.addAll('[${color}m'.charCodes); |
| 291 codes.addAll(string.charCodes()); | 291 codes.addAll(string.charCodes); |
| 292 codes.add(27); | 292 codes.add(27); |
| 293 codes.addAll('[0m'.charCodes()); | 293 codes.addAll('[0m'.charCodes); |
| 294 } | 294 } |
| 295 | 295 |
| 296 void _printProgress() { | 296 void _printProgress() { |
| 297 var percent = ((_completedTests() / _foundTests) * 100).toInt().toString(); | 297 var percent = ((_completedTests() / _foundTests) * 100).toInt().toString(); |
| 298 var progressPadded = _pad(_allTestsKnown ? percent : '--', 3); | 298 var progressPadded = _pad(_allTestsKnown ? percent : '--', 3); |
| 299 var passedPadded = _pad(_passedTests.toString(), 5); | 299 var passedPadded = _pad(_passedTests.toString(), 5); |
| 300 var failedPadded = _pad(_failedTests.toString(), 5); | 300 var failedPadded = _pad(_failedTests.toString(), 5); |
| 301 Duration d = (new Date.now()).difference(_startTime); | 301 Duration d = (new Date.now()).difference(_startTime); |
| 302 var progressLine = []; | 302 var progressLine = []; |
| 303 progressLine.addAll('\r[${_timeString(d)} | $progressPadded% | '.charCodes()
); | 303 progressLine.addAll('\r[${_timeString(d)} | $progressPadded% | '.charCodes); |
| 304 addColorWrapped(progressLine, '+$passedPadded ', GREEN); | 304 addColorWrapped(progressLine, '+$passedPadded ', GREEN); |
| 305 progressLine.addAll('| '.charCodes()); | 305 progressLine.addAll('| '.charCodes); |
| 306 var failedColor = (_failedTests != 0) ? RED : NONE; | 306 var failedColor = (_failedTests != 0) ? RED : NONE; |
| 307 addColorWrapped(progressLine, '-$failedPadded', failedColor); | 307 addColorWrapped(progressLine, '-$failedPadded', failedColor); |
| 308 progressLine.addAll(']'.charCodes()); | 308 progressLine.addAll(']'.charCodes); |
| 309 stdout.write(progressLine); | 309 stdout.write(progressLine); |
| 310 } | 310 } |
| 311 | 311 |
| 312 String _header(String header) { | 312 String _header(String header) { |
| 313 var result = []; | 313 var result = []; |
| 314 addColorWrapped(result, header, BOLD); | 314 addColorWrapped(result, header, BOLD); |
| 315 return new String.fromCharCodes(result); | 315 return new String.fromCharCodes(result); |
| 316 } | 316 } |
| 317 } | 317 } |
| 318 | 318 |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 378 if (test.output.unexpectedOutput) { | 378 if (test.output.unexpectedOutput) { |
| 379 status = 'fail'; | 379 status = 'fail'; |
| 380 } | 380 } |
| 381 var percent = ((_completedTests() / _foundTests) * 100).toInt().toString(); | 381 var percent = ((_completedTests() / _foundTests) * 100).toInt().toString(); |
| 382 print('Done ${test.configurationString} ${test.displayName}: $status'); | 382 print('Done ${test.configurationString} ${test.displayName}: $status'); |
| 383 print('@@@STEP_CLEAR@@@'); | 383 print('@@@STEP_CLEAR@@@'); |
| 384 print('@@@STEP_TEXT@ $percent% +$_passedTests -$_failedTests @@@'); | 384 print('@@@STEP_TEXT@ $percent% +$_passedTests -$_failedTests @@@'); |
| 385 } | 385 } |
| 386 | 386 |
| 387 void _printFailureSummary() { | 387 void _printFailureSummary() { |
| 388 if (!_failureSummary.isEmpty()) { | 388 if (!_failureSummary.isEmpty) { |
| 389 print('@@@STEP_FAILURE@@@'); | 389 print('@@@STEP_FAILURE@@@'); |
| 390 print('@@@BUILD_STEP $stepName failures@@@'); | 390 print('@@@BUILD_STEP $stepName failures@@@'); |
| 391 } | 391 } |
| 392 super._printFailureSummary(); | 392 super._printFailureSummary(); |
| 393 } | 393 } |
| 394 } | 394 } |
| 395 | 395 |
| 396 class DiffProgressIndicator extends ColorProgressIndicator { | 396 class DiffProgressIndicator extends ColorProgressIndicator { |
| 397 Map<String, List<String>> statusToConfigs = new Map<String, List<String>>(); | 397 Map<String, List<String>> statusToConfigs = new Map<String, List<String>>(); |
| 398 | 398 |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 441 print(''); | 441 print(''); |
| 442 print('$config:'); | 442 print('$config:'); |
| 443 statuses.sort((a, b) => a.compareTo(b)); | 443 statuses.sort((a, b) => a.compareTo(b)); |
| 444 for (String status in statuses) { | 444 for (String status in statuses) { |
| 445 print(' $status'); | 445 print(' $status'); |
| 446 } | 446 } |
| 447 }); | 447 }); |
| 448 _printStatus(); | 448 _printStatus(); |
| 449 } | 449 } |
| 450 } | 450 } |
| OLD | NEW |