| OLD | NEW |
| 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, 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 | 8 |
| 9 class ProgressIndicator { | 9 class ProgressIndicator { |
| 10 ProgressIndicator() : _startTime = new Date.now(); | 10 ProgressIndicator() : _startTime = new Date.now(); |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 47 } | 47 } |
| 48 | 48 |
| 49 String _timeString() { | 49 String _timeString() { |
| 50 Duration d = (new Date.now()).difference(_startTime); | 50 Duration d = (new Date.now()).difference(_startTime); |
| 51 var min = d.inMinutes; | 51 var min = d.inMinutes; |
| 52 var sec = d.inSeconds; | 52 var sec = d.inSeconds; |
| 53 return '${_padTime(min)}:${_padTime(sec)}'; | 53 return '${_padTime(min)}:${_padTime(sec)}'; |
| 54 } | 54 } |
| 55 | 55 |
| 56 void _printFailureOutput(TestCase test) { | 56 void _printFailureOutput(TestCase test) { |
| 57 print('FAILED: ${test.displayName}'); | 57 print('\nFAILED: ${test.displayName}'); |
| 58 StringBuffer expected = new StringBuffer(); |
| 59 expected.add('Expected: '); |
| 60 for (var expectation in test.expectedOutcomes) { |
| 61 expected.add('$expectation '); |
| 62 } |
| 63 print(expected.toString()); |
| 64 print('Actual: ${test.output.result}'); |
| 58 if (!test.output.stdout.isEmpty()) { | 65 if (!test.output.stdout.isEmpty()) { |
| 59 print('\nstdout:'); | 66 print('\nstdout:'); |
| 60 test.output.stdout.forEach((s) => print(s)); | 67 test.output.stdout.forEach((s) => print(s)); |
| 61 } | 68 } |
| 62 if (!test.output.stderr.isEmpty()) { | 69 if (!test.output.stderr.isEmpty()) { |
| 63 print('\nstderr:'); | 70 print('\nstderr:'); |
| 64 test.output.stderr.forEach((s) => print(s)); | 71 test.output.stderr.forEach((s) => print(s)); |
| 65 } | 72 } |
| 66 print('\nCommand line: ${test.commandLine}'); | 73 print('\nCommand line: ${test.commandLine}'); |
| 67 } | 74 } |
| 68 | 75 |
| 69 int _completedTests() => _passedTests + _failedTests; | 76 int _completedTests() => _passedTests + _failedTests; |
| 70 | 77 |
| 71 int _foundTests = 0; | 78 int _foundTests = 0; |
| 72 int _passedTests = 0; | 79 int _passedTests = 0; |
| 73 int _failedTests = 0; | 80 int _failedTests = 0; |
| 74 Date _startTime; | 81 Date _startTime; |
| 75 } | 82 } |
| 76 | 83 |
| 77 | 84 |
| 78 class CompactProgressIndicator extends ProgressIndicator { | 85 class CompactProgressIndicator extends ProgressIndicator { |
| 79 void _printProgress() { | 86 void _printProgress() { |
| 80 var percent = ((_completedTests() / _foundTests) * 100).floor().toString(); | 87 var percent = ((_completedTests() / _foundTests) * 100).floor().toString(); |
| 81 var percentPadded = _pad(percent, 5); | 88 var percentPadded = _pad(percent, 5); |
| 82 var passedPadded = _pad(_passedTests.toString(), 5); | 89 var passedPadded = _pad(_passedTests.toString(), 5); |
| 83 var failedPadded = _pad(_failedTests.toString(), 5); | 90 var failedPadded = _pad(_failedTests.toString(), 5); |
| 84 var progressLine = | 91 var progressLine = |
| 85 '[${_timeString()} | $percentPadded% | +$passedPadded | -$failedPadded]'; | 92 '\r[${_timeString()} | $percentPadded% | ' + |
| 86 // TODO(ager): Instead of using print we should write this to | 93 '+$passedPadded | -$failedPadded]'; |
| 87 // stdout and use \r to reuse the same line. | 94 stdout.write(progressLine.charCodes()); |
| 88 print(progressLine); | |
| 89 } | 95 } |
| 90 } | 96 } |
| 91 | 97 |
| OLD | NEW |