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 "dart:io" as io; | 8 import "dart:io" as io; |
| 9 import "http_server.dart" as http_server; | 9 import "http_server.dart" as http_server; |
| 10 import "status_file_parser.dart"; | 10 import "status_file_parser.dart"; |
| 11 import "test_runner.dart"; | 11 import "test_runner.dart"; |
| 12 import "test_suite.dart"; | 12 import "test_suite.dart"; |
| 13 import "utils.dart"; | 13 import "utils.dart"; |
| 14 | 14 |
| 15 String _pad(String s, int length) { | 15 String _pad(String s, int length) { |
| 16 StringBuffer buffer = new StringBuffer(); | 16 StringBuffer buffer = new StringBuffer(); |
| 17 for (int i = s.length; i < length; i++) { | 17 for (int i = s.length; i < length; i++) { |
| 18 buffer.add(' '); | 18 buffer.write(' '); |
| 19 } | 19 } |
| 20 buffer.add(s); | 20 buffer.write(s); |
| 21 return buffer.toString(); | 21 return buffer.toString(); |
| 22 } | 22 } |
| 23 | 23 |
| 24 String _padTime(int time) { | 24 String _padTime(int time) { |
| 25 if (time == 0) { | 25 if (time == 0) { |
| 26 return '00'; | 26 return '00'; |
| 27 } else if (time < 10) { | 27 } else if (time < 10) { |
| 28 return '0$time'; | 28 return '0$time'; |
| 29 } else { | 29 } else { |
| 30 return '$time'; | 30 return '$time'; |
| (...skipping 28 matching lines...) Expand all Loading... | |
| 59 } | 59 } |
| 60 | 60 |
| 61 | 61 |
| 62 List<String> _buildFailureOutput(TestCase test, | 62 List<String> _buildFailureOutput(TestCase test, |
| 63 [Formatter formatter = const Formatter()]) { | 63 [Formatter formatter = const Formatter()]) { |
| 64 List<String> output = new List<String>(); | 64 List<String> output = new List<String>(); |
| 65 output.add(''); | 65 output.add(''); |
| 66 output.add(formatter.failed('FAILED: ${test.configurationString}' | 66 output.add(formatter.failed('FAILED: ${test.configurationString}' |
| 67 ' ${test.displayName}')); | 67 ' ${test.displayName}')); |
| 68 StringBuffer expected = new StringBuffer(); | 68 StringBuffer expected = new StringBuffer(); |
| 69 expected.add('Expected: '); | 69 expected.write('Expected: '); |
| 70 for (var expectation in test.expectedOutcomes) { | 70 for (var expectation in test.expectedOutcomes) { |
| 71 expected.add('$expectation '); | 71 expected.write('$expectation '); |
| 72 } | 72 } |
| 73 output.add(expected.toString()); | 73 output.add(expected.toString()); |
| 74 output.add('Actual: ${test.lastCommandOutput.result}'); | 74 output.add('Actual: ${test.lastCommandOutput.result}'); |
| 75 if (!test.lastCommandOutput.hasTimedOut && test.info != null) { | 75 if (!test.lastCommandOutput.hasTimedOut && test.info != null) { |
| 76 if (test.lastCommandOutput.incomplete && !test.info.hasCompileError) { | 76 if (test.lastCommandOutput.incomplete && !test.info.hasCompileError) { |
| 77 output.add('Unexpected compile-time error.'); | 77 output.add('Unexpected compile-time error.'); |
| 78 } else { | 78 } else { |
| 79 if (test.info.hasCompileError) { | 79 if (test.info.hasCompileError) { |
| 80 output.add('Compile-time error expected.'); | 80 output.add('Compile-time error expected.'); |
| 81 } | 81 } |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 136 io.exitCode = 1; | 136 io.exitCode = 1; |
| 137 } | 137 } |
| 138 } | 138 } |
| 139 } | 139 } |
| 140 | 140 |
| 141 class FlakyLogWriter extends EventListener { | 141 class FlakyLogWriter extends EventListener { |
| 142 void done(TestCase test) { | 142 void done(TestCase test) { |
| 143 if (test.isFlaky && test.lastCommandOutput.result != PASS) { | 143 if (test.isFlaky && test.lastCommandOutput.result != PASS) { |
| 144 var buf = new StringBuffer(); | 144 var buf = new StringBuffer(); |
| 145 for (var l in _buildFailureOutput(test)) { | 145 for (var l in _buildFailureOutput(test)) { |
| 146 buf.add("$l\n"); | 146 buf.write("$l\n"); |
| 147 } | 147 } |
| 148 _appendToFlakyFile(buf.toString()); | 148 _appendToFlakyFile(buf.toString()); |
| 149 } | 149 } |
| 150 } | 150 } |
| 151 | 151 |
| 152 void _appendToFlakyFile(String msg) { | 152 void _appendToFlakyFile(String msg) { |
| 153 var file = new File(TestUtils.flakyFileName()); | 153 var file = new File(TestUtils.flakyFileName()); |
| 154 var fd = file.openSync(FileMode.APPEND); | 154 var fd = file.openSync(FileMode.APPEND); |
| 155 fd.writeStringSync(msg); | 155 fd.writeStringSync(msg); |
| 156 fd.closeSync(); | 156 fd.closeSync(); |
| 157 } | 157 } |
| 158 } | 158 } |
| 159 | 159 |
| 160 class SummaryPrinter extends EventListener { | 160 class SummaryPrinter extends EventListener { |
| 161 void allTestsKnown() { | 161 void allTestsKnown() { |
| 162 if (SummaryReport.total > 0) { | 162 if (SummaryReport.total > 0) { |
| 163 SummaryReport.printReport(); | 163 SummaryReport.printReport(); |
| 164 } | 164 } |
| 165 } | 165 } |
| 166 } | 166 } |
| 167 | 167 |
| 168 class TimingPrinter extends EventListener { | 168 class TimingPrinter extends EventListener { |
| 169 List<TestCase> _tests = <TestCase>[]; | 169 List<TestCase> _tests = <TestCase>[]; |
| 170 Date _startTime; | 170 DateTime _startTime; |
| 171 | 171 |
| 172 TimingPrinter(this._startTime); | 172 TimingPrinter(this._startTime); |
| 173 | 173 |
| 174 void done(TestCase testCase) { | 174 void done(TestCase testCase) { |
| 175 _tests.add(testCase); | 175 _tests.add(testCase); |
| 176 } | 176 } |
| 177 | 177 |
| 178 void allDone() { | 178 void allDone() { |
| 179 // TODO: We should take all the commands into account | 179 // TODO: We should take all the commands into account |
| 180 Duration d = (new Date.now()).difference(_startTime); | 180 Duration d = (new DateTime.now()).difference(_startTime); |
| 181 print('\n--- Total time: ${_timeString(d)} ---'); | 181 print('\n--- Total time: ${_timeString(d)} ---'); |
| 182 _tests.sort((a, b) { | 182 _tests.sort((a, b) { |
| 183 Duration aDuration = a.lastCommandOutput.time; | 183 Duration aDuration = a.lastCommandOutput.time; |
| 184 Duration bDuration = b.lastCommandOutput.time; | 184 Duration bDuration = b.lastCommandOutput.time; |
| 185 return bDuration.inMilliseconds - aDuration.inMilliseconds; | 185 return bDuration.inMilliseconds - aDuration.inMilliseconds; |
| 186 }); | 186 }); |
| 187 for (int i = 0; i < 20 && i < _tests.length; i++) { | 187 for (int i = 0; i < 20 && i < _tests.length; i++) { |
| 188 var name = _tests[i].displayName; | 188 var name = _tests[i].displayName; |
| 189 var duration = _tests[i].lastCommandOutput.time; | 189 var duration = _tests[i].lastCommandOutput.time; |
| 190 var configuration = _tests[i].configurationString; | 190 var configuration = _tests[i].configurationString; |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 280 | 280 |
| 281 Path _tempDir() { | 281 Path _tempDir() { |
| 282 // Dir will be located in the system temporary directory. | 282 // Dir will be located in the system temporary directory. |
| 283 var dir = new Directory('').createTempSync(); | 283 var dir = new Directory('').createTempSync(); |
| 284 var path = new Path(dir.path).directoryPath; | 284 var path = new Path(dir.path).directoryPath; |
| 285 dir.deleteSync(); | 285 dir.deleteSync(); |
| 286 return path; | 286 return path; |
| 287 } | 287 } |
| 288 | 288 |
| 289 void allDone() { | 289 void allDone() { |
| 290 var tempDirs = []; | 290 var tempDirs = []; |
|
Bill Hesse
2013/03/13 12:56:41
Why not just use a counter instead of a list for t
Søren Gjesse
2013/03/13 15:17:18
Done.
| |
| 291 var systemTempDir = _tempDir(); | 291 var systemTempDir = _tempDir(); |
| 292 var lister = new Directory.fromPath(systemTempDir).list(); | 292 var lister = new Directory.fromPath(systemTempDir).list().listen( |
| 293 lister.onDir = (path) => tempDirs.add(path); | 293 (FileSystemEntity fse) { |
| 294 lister.onDone = (_) { | 294 if (fse is Directory) tempDirs.add(fse.path); |
| 295 if (tempDirs.length > MIN_NUMBER_OF_TEMP_DIRS) { | 295 }, |
| 296 DebugLogger.warning("There are ${tempDirs.length} directories " | 296 onDone: () { |
| 297 "in the system tempdir ('$systemTempDir')! " | 297 if (tempDirs.length > MIN_NUMBER_OF_TEMP_DIRS) { |
| 298 "Maybe left over directories?\n"); | 298 DebugLogger.warning("There are ${tempDirs.length} directories " |
|
ricow1
2013/03/13 13:38:41
indentation
Søren Gjesse
2013/03/13 15:17:18
Done.
| |
| 299 "in the system tempdir ('$systemTempDir')! " | |
| 300 "Maybe left over directories?\n"); | |
| 299 } | 301 } |
| 300 }; | 302 }); |
| 301 } | 303 } |
| 302 } | 304 } |
| 303 | 305 |
| 304 class LineProgressIndicator extends EventListener { | 306 class LineProgressIndicator extends EventListener { |
| 305 void done(TestCase test) { | 307 void done(TestCase test) { |
| 306 var status = 'pass'; | 308 var status = 'pass'; |
| 307 if (test.lastCommandOutput.unexpectedOutput) { | 309 if (test.lastCommandOutput.unexpectedOutput) { |
| 308 status = 'fail'; | 310 status = 'fail'; |
| 309 } | 311 } |
| 310 print('Done ${test.configurationString} ${test.displayName}: $status'); | 312 print('Done ${test.configurationString} ${test.displayName}: $status'); |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 323 } | 325 } |
| 324 print(''); | 326 print(''); |
| 325 } | 327 } |
| 326 } | 328 } |
| 327 } | 329 } |
| 328 | 330 |
| 329 class ProgressIndicator extends EventListener { | 331 class ProgressIndicator extends EventListener { |
| 330 ProgressIndicator(this._startTime); | 332 ProgressIndicator(this._startTime); |
| 331 | 333 |
| 332 factory ProgressIndicator.fromName(String name, | 334 factory ProgressIndicator.fromName(String name, |
| 333 Date startTime, | 335 DateTime startTime, |
| 334 Formatter formatter) { | 336 Formatter formatter) { |
| 335 switch (name) { | 337 switch (name) { |
| 336 case 'compact': | 338 case 'compact': |
| 337 return new CompactProgressIndicator(startTime, formatter); | 339 return new CompactProgressIndicator(startTime, formatter); |
| 338 case 'line': | 340 case 'line': |
| 339 return new LineProgressIndicator(); | 341 return new LineProgressIndicator(); |
| 340 case 'verbose': | 342 case 'verbose': |
| 341 return new VerboseProgressIndicator(startTime); | 343 return new VerboseProgressIndicator(startTime); |
| 342 case 'status': | 344 case 'status': |
| 343 return new ProgressIndicator(startTime); | 345 return new ProgressIndicator(startTime); |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 389 } | 391 } |
| 390 | 392 |
| 391 int get numFailedTests => _failedTests; | 393 int get numFailedTests => _failedTests; |
| 392 | 394 |
| 393 int _completedTests() => _passedTests + _failedTests; | 395 int _completedTests() => _passedTests + _failedTests; |
| 394 | 396 |
| 395 int _foundTests = 0; | 397 int _foundTests = 0; |
| 396 int _passedTests = 0; | 398 int _passedTests = 0; |
| 397 int _failedTests = 0; | 399 int _failedTests = 0; |
| 398 bool _allTestsKnown = false; | 400 bool _allTestsKnown = false; |
| 399 Date _startTime; | 401 DateTime _startTime; |
| 400 } | 402 } |
| 401 | 403 |
| 402 abstract class CompactIndicator extends ProgressIndicator { | 404 abstract class CompactIndicator extends ProgressIndicator { |
| 403 CompactIndicator(Date startTime) | 405 CompactIndicator(DateTime startTime) |
| 404 : super(startTime); | 406 : super(startTime); |
| 405 | 407 |
| 406 void allDone() { | 408 void allDone() { |
| 407 stdout.write('\n'.charCodes); | 409 stdout.writeln(''); |
| 408 if (_failedTests > 0) { | 410 if (_failedTests > 0) { |
| 409 // We may have printed many failure logs, so reprint the summary data. | 411 // We may have printed many failure logs, so reprint the summary data. |
| 410 _printProgress(); | 412 _printProgress(); |
| 411 print(''); | 413 print(''); |
| 412 } | 414 } |
| 413 stdout.close(); | 415 stdout.close(); |
| 414 stderr.close(); | 416 stderr.close(); |
| 415 } | 417 } |
| 416 | 418 |
| 417 void _printStartProgress(TestCase test) => _printProgress(); | 419 void _printStartProgress(TestCase test) => _printProgress(); |
| 418 void _printDoneProgress(TestCase test) => _printProgress(); | 420 void _printDoneProgress(TestCase test) => _printProgress(); |
| 419 | 421 |
| 420 void _printProgress(); | 422 void _printProgress(); |
| 421 } | 423 } |
| 422 | 424 |
| 423 | 425 |
| 424 class CompactProgressIndicator extends CompactIndicator { | 426 class CompactProgressIndicator extends CompactIndicator { |
| 425 Formatter _formatter; | 427 Formatter _formatter; |
| 426 | 428 |
| 427 CompactProgressIndicator(Date startTime, this._formatter) | 429 CompactProgressIndicator(DateTime startTime, this._formatter) |
| 428 : super(startTime); | 430 : super(startTime); |
| 429 | 431 |
| 430 void _printProgress() { | 432 void _printProgress() { |
| 431 var percent = ((_completedTests() / _foundTests) * 100).toInt().toString(); | 433 var percent = ((_completedTests() / _foundTests) * 100).toInt().toString(); |
| 432 var progressPadded = _pad(_allTestsKnown ? percent : '--', 3); | 434 var progressPadded = _pad(_allTestsKnown ? percent : '--', 3); |
| 433 var passedPadded = _pad(_passedTests.toString(), 5); | 435 var passedPadded = _pad(_passedTests.toString(), 5); |
| 434 var failedPadded = _pad(_failedTests.toString(), 5); | 436 var failedPadded = _pad(_failedTests.toString(), 5); |
| 435 Duration d = (new Date.now()).difference(_startTime); | 437 Duration d = (new DateTime.now()).difference(_startTime); |
| 436 var progressLine = | 438 var progressLine = |
| 437 '\r[${_timeString(d)} | $progressPadded% | ' | 439 '\r[${_timeString(d)} | $progressPadded% | ' |
| 438 '+${_formatter.passed(passedPadded)} | ' | 440 '+${_formatter.passed(passedPadded)} | ' |
| 439 '-${_formatter.failed(failedPadded)}]'; | 441 '-${_formatter.failed(failedPadded)}]'; |
| 440 stdout.write(progressLine.charCodes); | 442 stdout.write(progressLine); |
| 441 } | 443 } |
| 442 } | 444 } |
| 443 | 445 |
| 444 | 446 |
| 445 class VerboseProgressIndicator extends ProgressIndicator { | 447 class VerboseProgressIndicator extends ProgressIndicator { |
| 446 VerboseProgressIndicator(Date startTime) | 448 VerboseProgressIndicator(DateTime startTime) |
| 447 : super(startTime); | 449 : super(startTime); |
| 448 | 450 |
| 449 void _printStartProgress(TestCase test) { | 451 void _printStartProgress(TestCase test) { |
| 450 print('Starting ${test.configurationString} ${test.displayName}...'); | 452 print('Starting ${test.configurationString} ${test.displayName}...'); |
| 451 } | 453 } |
| 452 | 454 |
| 453 void _printDoneProgress(TestCase test) { | 455 void _printDoneProgress(TestCase test) { |
| 454 var status = 'pass'; | 456 var status = 'pass'; |
| 455 if (test.lastCommandOutput.unexpectedOutput) { | 457 if (test.lastCommandOutput.unexpectedOutput) { |
| 456 status = 'fail'; | 458 status = 'fail'; |
| 457 } | 459 } |
| 458 print('Done ${test.configurationString} ${test.displayName}: $status'); | 460 print('Done ${test.configurationString} ${test.displayName}: $status'); |
| 459 } | 461 } |
| 460 } | 462 } |
| 461 | 463 |
| 462 | 464 |
| 463 class BuildbotProgressIndicator extends ProgressIndicator { | 465 class BuildbotProgressIndicator extends ProgressIndicator { |
| 464 static String stepName; | 466 static String stepName; |
| 465 var _failureSummary = <String>[]; | 467 var _failureSummary = <String>[]; |
| 466 | 468 |
| 467 BuildbotProgressIndicator(Date startTime) : super(startTime); | 469 BuildbotProgressIndicator(DateTime startTime) : super(startTime); |
| 468 | 470 |
| 469 void done(TestCase test) { | 471 void done(TestCase test) { |
| 470 super.done(test); | 472 super.done(test); |
| 471 if (test.lastCommandOutput.unexpectedOutput) { | 473 if (test.lastCommandOutput.unexpectedOutput) { |
| 472 _failureSummary.addAll(_buildFailureOutput(test)); | 474 _failureSummary.addAll(_buildFailureOutput(test)); |
| 473 } | 475 } |
| 474 } | 476 } |
| 475 | 477 |
| 476 void _printDoneProgress(TestCase test) { | 478 void _printDoneProgress(TestCase test) { |
| 477 var status = 'pass'; | 479 var status = 'pass'; |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 489 print('@@@STEP_FAILURE@@@'); | 491 print('@@@STEP_FAILURE@@@'); |
| 490 print('@@@BUILD_STEP $stepName failures@@@'); | 492 print('@@@BUILD_STEP $stepName failures@@@'); |
| 491 for (String line in _failureSummary) { | 493 for (String line in _failureSummary) { |
| 492 print(line); | 494 print(line); |
| 493 } | 495 } |
| 494 print(''); | 496 print(''); |
| 495 } | 497 } |
| 496 super.allDone(); | 498 super.allDone(); |
| 497 } | 499 } |
| 498 } | 500 } |
| 499 | |
| OLD | NEW |