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(); |
11 | 11 |
12 factory ProgressIndicator.fromName(String name) { | |
13 switch (name) { | |
14 case 'compact': | |
15 return new CompactProgressIndicator(); | |
16 case 'line': | |
17 return new LineProgressIndicator(); | |
18 case 'verbose': | |
19 return new VerboseProgressIndicator(); | |
20 case 'status': | |
21 return new StatusProgressIndicator(); | |
22 case 'buildbot': | |
23 return new BuildbotProgressIndicator(); | |
24 default: | |
25 assert(false); | |
Bill Hesse
2011/11/14 16:17:17
I think we want to throw here, not just throw in c
| |
26 break; | |
27 } | |
28 } | |
29 | |
12 void testAdded() => _foundTests++; | 30 void testAdded() => _foundTests++; |
13 | 31 |
14 void start(TestCase test) { | 32 void start(TestCase test) { |
15 _printProgress(); | 33 _printStartProgress(test); |
16 } | 34 } |
17 | 35 |
18 void done(TestCase test) { | 36 void done(TestCase test) { |
19 if (test.output.unexpectedOutput) { | 37 if (test.output.unexpectedOutput) { |
20 _failedTests++; | 38 _failedTests++; |
21 _printFailureOutput(test); | 39 _printFailureOutput(test); |
22 } else { | 40 } else { |
23 _passedTests++; | 41 _passedTests++; |
24 } | 42 } |
25 _printProgress(); | 43 _printDoneProgress(test); |
26 } | 44 } |
27 | 45 |
28 abstract _printProgress(); | 46 abstract allDone(); |
47 abstract _printStartProgress(); | |
48 abstract _printDoneProgress(); | |
29 | 49 |
30 String _pad(String s, int length) { | 50 String _pad(String s, int length) { |
31 StringBuffer buffer = new StringBuffer(); | 51 StringBuffer buffer = new StringBuffer(); |
32 for (int i = s.length; i < length; i++) { | 52 for (int i = s.length; i < length; i++) { |
33 buffer.add(' '); | 53 buffer.add(' '); |
34 } | 54 } |
35 buffer.add(s); | 55 buffer.add(s); |
36 return buffer.toString(); | 56 return buffer.toString(); |
37 } | 57 } |
38 | 58 |
(...skipping 27 matching lines...) Expand all Loading... | |
66 print('\nstdout:'); | 86 print('\nstdout:'); |
67 test.output.stdout.forEach((s) => print(s)); | 87 test.output.stdout.forEach((s) => print(s)); |
68 } | 88 } |
69 if (!test.output.stderr.isEmpty()) { | 89 if (!test.output.stderr.isEmpty()) { |
70 print('\nstderr:'); | 90 print('\nstderr:'); |
71 test.output.stderr.forEach((s) => print(s)); | 91 test.output.stderr.forEach((s) => print(s)); |
72 } | 92 } |
73 print('\nCommand line: ${test.commandLine}'); | 93 print('\nCommand line: ${test.commandLine}'); |
74 } | 94 } |
75 | 95 |
96 void _printStatus() { | |
97 if (_failedTests == 0) { | |
98 print('\n==='); | |
99 print('=== All tests succeeded'); | |
100 print('===\n'); | |
101 } else { | |
102 var pluralSuffix = _failedTests != 1 ? 's' : ''; | |
103 print('\n==='); | |
104 print('=== ${_failedTests} test$pluralSuffix failed'); | |
105 print('===\n'); | |
106 } | |
107 } | |
108 | |
76 int _completedTests() => _passedTests + _failedTests; | 109 int _completedTests() => _passedTests + _failedTests; |
77 | 110 |
78 int _foundTests = 0; | 111 int _foundTests = 0; |
79 int _passedTests = 0; | 112 int _passedTests = 0; |
80 int _failedTests = 0; | 113 int _failedTests = 0; |
81 Date _startTime; | 114 Date _startTime; |
82 } | 115 } |
83 | 116 |
84 | 117 |
85 class CompactProgressIndicator extends ProgressIndicator { | 118 class CompactProgressIndicator extends ProgressIndicator { |
119 void allDone() { | |
120 } | |
121 | |
86 void _printProgress() { | 122 void _printProgress() { |
87 var percent = ((_completedTests() / _foundTests) * 100).floor().toString(); | 123 var percent = ((_completedTests() / _foundTests) * 100).floor().toString(); |
88 var percentPadded = _pad(percent, 5); | 124 var percentPadded = _pad(percent, 5); |
89 var passedPadded = _pad(_passedTests.toString(), 5); | 125 var passedPadded = _pad(_passedTests.toString(), 5); |
90 var failedPadded = _pad(_failedTests.toString(), 5); | 126 var failedPadded = _pad(_failedTests.toString(), 5); |
91 var progressLine = | 127 var progressLine = |
92 '\r[${_timeString()} | $percentPadded% | ' + | 128 '\r[${_timeString()} | $percentPadded% | ' + |
93 '+$passedPadded | -$failedPadded]'; | 129 '+$passedPadded | -$failedPadded]'; |
94 stdout.write(progressLine.charCodes()); | 130 stdout.write(progressLine.charCodes()); |
95 } | 131 } |
132 | |
133 void _printStartProgress(TestCase test) => _printProgress(); | |
134 void _printDoneProgress(TestCase test) => _printProgress(); | |
96 } | 135 } |
97 | 136 |
137 | |
138 class LineProgressIndicator extends ProgressIndicator { | |
139 void allDone() { | |
140 _printStatus(); | |
141 } | |
142 | |
143 void _printStartProgress(TestCase test) { | |
144 } | |
145 | |
146 void _printDoneProgress(TestCase test) { | |
147 var status = 'pass'; | |
148 if (test.output.unexpectedOutput) { | |
149 status = 'fail'; | |
150 } | |
151 print('Done ${test.displayName}: $status'); | |
152 } | |
153 } | |
154 | |
155 | |
156 class VerboseProgressIndicator extends ProgressIndicator { | |
157 void allDone() { | |
158 _printStatus(); | |
159 } | |
160 | |
161 void _printStartProgress(TestCase test) { | |
162 print('Starting ${test.displayName}...'); | |
163 } | |
164 | |
165 void _printDoneProgress(TestCase test) { | |
166 var status = 'pass'; | |
167 if (test.output.unexpectedOutput) { | |
168 status = 'fail'; | |
169 } | |
170 print('Done ${test.displayName}: $status'); | |
171 } | |
172 } | |
173 | |
174 | |
175 class StatusProgressIndicator extends ProgressIndicator { | |
176 void allDone() { | |
177 _printStatus(); | |
178 } | |
179 | |
180 void _printStartProgress(TestCase test) { | |
181 } | |
182 | |
183 void _printDoneProgress(TestCase test) { | |
184 } | |
185 } | |
186 | |
187 | |
188 class BuildbotProgressIndicator extends ProgressIndicator { | |
189 void allDone() { | |
190 _printStatus(); | |
191 } | |
192 | |
193 void _printStartProgress(TestCase test) { | |
194 } | |
195 | |
196 void _printDoneProgress(TestCase test) { | |
197 var status = 'pass'; | |
198 if (test.output.unexpectedOutput) { | |
199 status = 'fail'; | |
200 } | |
201 var percent = ((_completedTests() / _foundTests) * 100).toInt().toString(); | |
202 print('Done ${test.displayName}: $status'); | |
203 print('@@@STEP_CLEAR@@@'); | |
204 print('@@@STEP_TEXT@ $percent% +$_passedTests -$_failedTests @@@'); | |
205 } | |
206 } | |
OLD | NEW |