| OLD | NEW |
| (Empty) | |
| 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 |
| 3 // BSD-style license that can be found in the LICENSE file. |
| 4 |
| 5 #library("test_progress"); |
| 6 |
| 7 #import("test_runner.dart"); |
| 8 |
| 9 class ProgressIndicator { |
| 10 ProgressIndicator() : _startTime = new Date.now(); |
| 11 |
| 12 void testAdded() => _foundTests++; |
| 13 |
| 14 void start(TestCase test) { |
| 15 _printProgress(); |
| 16 } |
| 17 |
| 18 void done(TestCase test) { |
| 19 if (test.output.unexpectedOutput) { |
| 20 _failedTests++; |
| 21 _printFailureOutput(test); |
| 22 } else { |
| 23 _passedTests++; |
| 24 } |
| 25 _printProgress(); |
| 26 } |
| 27 |
| 28 abstract _printProgress(); |
| 29 |
| 30 String _pad(String s, int length) { |
| 31 StringBuffer buffer = new StringBuffer(); |
| 32 for (int i = s.length; i < length; i++) { |
| 33 buffer.add(' '); |
| 34 } |
| 35 buffer.add(s); |
| 36 return buffer.toString(); |
| 37 } |
| 38 |
| 39 String _padTime(int time) { |
| 40 if (time == 0) { |
| 41 return '00'; |
| 42 } else if (time < 10) { |
| 43 return '0$time'; |
| 44 } else { |
| 45 return '$time'; |
| 46 } |
| 47 } |
| 48 |
| 49 String _timeString() { |
| 50 Duration d = (new Date.now()).difference(_startTime); |
| 51 var min = d.inMinutes; |
| 52 var sec = d.inSeconds; |
| 53 return '${_padTime(min)}:${_padTime(sec)}'; |
| 54 } |
| 55 |
| 56 void _printFailureOutput(TestCase test) { |
| 57 print('FAILED: ${test.displayName}'); |
| 58 if (!test.output.stdout.isEmpty()) { |
| 59 print('\nstdout:'); |
| 60 test.output.stdout.forEach((s) => print(s)); |
| 61 } |
| 62 if (!test.output.stderr.isEmpty()) { |
| 63 print('\nstderr:'); |
| 64 test.output.stderr.forEach((s) => print(s)); |
| 65 } |
| 66 print('\nCommand line: ${test.commandLine}'); |
| 67 } |
| 68 |
| 69 int _completedTests() => _passedTests + _failedTests; |
| 70 |
| 71 int _foundTests = 0; |
| 72 int _passedTests = 0; |
| 73 int _failedTests = 0; |
| 74 Date _startTime; |
| 75 } |
| 76 |
| 77 |
| 78 class CompactProgressIndicator extends ProgressIndicator { |
| 79 void _printProgress() { |
| 80 var percent = ((_completedTests() / _foundTests) * 100).floor().toString(); |
| 81 var percentPadded = _pad(percent, 5); |
| 82 var passedPadded = _pad(_passedTests.toString(), 5); |
| 83 var failedPadded = _pad(_failedTests.toString(), 5); |
| 84 var progressLine = |
| 85 '[${_timeString()} | $percentPadded% | +$passedPadded | -$failedPadded]'; |
| 86 // TODO(ager): Instead of using print we should write this to |
| 87 // stdout and use \r to reuse the same line. |
| 88 print(progressLine); |
| 89 } |
| 90 } |
| 91 |
| OLD | NEW |