Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(574)

Side by Side Diff: tools/testing/dart/test_progress.dart

Issue 8845001: Add --time option to dart test scripts. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Runtime test script Created 9 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « tools/testing/dart/test_options.dart ('k') | tools/testing/dart/test_runner.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 #import("test_suite.dart"); 8 #import("test_suite.dart");
9 9
10 class ProgressIndicator { 10 class ProgressIndicator {
11 ProgressIndicator(this._startTime); 11 ProgressIndicator(this._startTime, this._printTiming) : _tests = [];
12 12
13 factory ProgressIndicator.fromName(String name, Date startTime) { 13 factory ProgressIndicator.fromName(String name,
14 Date startTime,
15 bool printTiming) {
14 switch (name) { 16 switch (name) {
15 case 'compact': 17 case 'compact':
16 return new CompactProgressIndicator(startTime); 18 return new CompactProgressIndicator(startTime, printTiming);
17 case 'color': 19 case 'color':
18 return new ColorProgressIndicator(startTime); 20 return new ColorProgressIndicator(startTime, printTiming);
19 case 'line': 21 case 'line':
20 return new LineProgressIndicator(startTime); 22 return new LineProgressIndicator(startTime, printTiming);
21 case 'verbose': 23 case 'verbose':
22 return new VerboseProgressIndicator(startTime); 24 return new VerboseProgressIndicator(startTime, printTiming);
23 case 'status': 25 case 'status':
24 return new StatusProgressIndicator(startTime); 26 return new StatusProgressIndicator(startTime, printTiming);
25 case 'buildbot': 27 case 'buildbot':
26 return new BuildbotProgressIndicator(startTime); 28 return new BuildbotProgressIndicator(startTime, printTiming);
27 default: 29 default:
28 assert(false); 30 assert(false);
29 break; 31 break;
30 } 32 }
31 } 33 }
32 34
33 void testAdded() => _foundTests++; 35 void testAdded() => _foundTests++;
34 36
35 void start(TestCase test) { 37 void start(TestCase test) {
36 _printStartProgress(test); 38 _printStartProgress(test);
37 } 39 }
38 40
39 void done(TestCase test) { 41 void done(TestCase test) {
40 if (test.output.unexpectedOutput) { 42 if (test.output.unexpectedOutput) {
41 _failedTests++; 43 _failedTests++;
42 _printFailureOutput(test); 44 _printFailureOutput(test);
43 } else { 45 } else {
44 _passedTests++; 46 _passedTests++;
45 } 47 }
46 _printDoneProgress(test); 48 _printDoneProgress(test);
49 // If we need to print timing information we hold on to all completed
50 // tests.
51 if (_printTiming) _tests.add(test);
47 } 52 }
48 53
49 void allTestsKnown() { 54 void allTestsKnown() {
50 if (!_allTestsKnown) SummaryReport.printReport(); 55 if (!_allTestsKnown) SummaryReport.printReport();
51 _allTestsKnown = true; 56 _allTestsKnown = true;
52 } 57 }
53 58
54 abstract allDone(); 59 void _printTimingInformation() {
60 if (_printTiming) {
61 Duration d = (new Date.now()).difference(_startTime);
62 print('\n--- Total time: ${_timeString(d)} ---');
63 _tests.sort((a, b) {
64 Duration aDuration = a.output.time;
65 Duration bDuration = b.output.time;
66 return bDuration.inMilliseconds - aDuration.inMilliseconds;
67 });
68 for (int i = 0; i < 20 && i < _tests.length; i++) {
69 var name = _tests[i].displayName;
70 var duration = _tests[i].output.time;
71 print('${duration} - $name');
72 }
73 }
74 }
75
76 void allDone() {
77 _printStatus();
78 _printTimingInformation();
79 exit(_failedTests > 0 ? 1 : 0);
80 }
81
55 abstract _printStartProgress(); 82 abstract _printStartProgress();
56 abstract _printDoneProgress(); 83 abstract _printDoneProgress();
57 84
58 String _pad(String s, int length) { 85 String _pad(String s, int length) {
59 StringBuffer buffer = new StringBuffer(); 86 StringBuffer buffer = new StringBuffer();
60 for (int i = s.length; i < length; i++) { 87 for (int i = s.length; i < length; i++) {
61 buffer.add(' '); 88 buffer.add(' ');
62 } 89 }
63 buffer.add(s); 90 buffer.add(s);
64 return buffer.toString(); 91 return buffer.toString();
65 } 92 }
66 93
67 String _padTime(int time) { 94 String _padTime(int time) {
68 if (time == 0) { 95 if (time == 0) {
69 return '00'; 96 return '00';
70 } else if (time < 10) { 97 } else if (time < 10) {
71 return '0$time'; 98 return '0$time';
72 } else { 99 } else {
73 return '$time'; 100 return '$time';
74 } 101 }
75 } 102 }
76 103
77 String _timeString() { 104 String _timeString(Duration d) {
78 Duration d = (new Date.now()).difference(_startTime);
79 var min = d.inMinutes; 105 var min = d.inMinutes;
80 var sec = d.inSeconds % 60; 106 var sec = d.inSeconds % 60;
81 return '${_padTime(min)}:${_padTime(sec)}'; 107 return '${_padTime(min)}:${_padTime(sec)}';
82 } 108 }
83 109
84 void _printFailureOutput(TestCase test) { 110 void _printFailureOutput(TestCase test) {
85 print('\nFAILED: ${test.displayName}'); 111 print('\nFAILED: ${test.displayName}');
86 StringBuffer expected = new StringBuffer(); 112 StringBuffer expected = new StringBuffer();
87 expected.add('Expected: '); 113 expected.add('Expected: ');
88 for (var expectation in test.expectedOutcomes) { 114 for (var expectation in test.expectedOutcomes) {
(...skipping 25 matching lines...) Expand all
114 } 140 }
115 } 141 }
116 142
117 int _completedTests() => _passedTests + _failedTests; 143 int _completedTests() => _passedTests + _failedTests;
118 144
119 int _foundTests = 0; 145 int _foundTests = 0;
120 int _passedTests = 0; 146 int _passedTests = 0;
121 int _failedTests = 0; 147 int _failedTests = 0;
122 bool _allTestsKnown = false; 148 bool _allTestsKnown = false;
123 Date _startTime; 149 Date _startTime;
150 bool _printTiming;
151 List<TestCase> _tests;
124 } 152 }
125 153
126 154
127 class CompactIndicator extends ProgressIndicator { 155 class CompactIndicator extends ProgressIndicator {
128 CompactIndicator(Date startTime) : super(startTime); 156 CompactIndicator(Date startTime, bool printTiming)
157 : super(startTime, printTiming);
129 158
130 void allDone() { 159 void allDone() {
131 stdout.write('\n'.charCodes()); 160 stdout.write('\n'.charCodes());
161 _printTimingInformation();
132 stdout.close(); 162 stdout.close();
133 exit(_failedTests > 0 ? 1 : 0); 163 exit(_failedTests > 0 ? 1 : 0);
134 } 164 }
135 165
136 void _printStartProgress(TestCase test) => _printProgress(); 166 void _printStartProgress(TestCase test) => _printProgress();
137 void _printDoneProgress(TestCase test) => _printProgress(); 167 void _printDoneProgress(TestCase test) => _printProgress();
138 168
139 String _nextSpinner() { 169 String _nextSpinner() {
140 _spinnerIndex = (_spinnerIndex + 1) % 4; 170 _spinnerIndex = (_spinnerIndex + 1) % 4;
141 return _spinners[_spinnerIndex]; 171 return _spinners[_spinnerIndex];
142 } 172 }
143 173
144 static int _spinnerIndex = 0; 174 static int _spinnerIndex = 0;
145 static List<String> _spinners = const ['- ', '\\ ', '| ', '/ ']; 175 static List<String> _spinners = const ['- ', '\\ ', '| ', '/ '];
146 } 176 }
147 177
148 178
149 class CompactProgressIndicator extends CompactIndicator { 179 class CompactProgressIndicator extends CompactIndicator {
150 CompactProgressIndicator(Date startTime) : super(startTime); 180 CompactProgressIndicator(Date startTime, bool printTiming)
181 : super(startTime, printTiming);
151 182
152 void _printProgress() { 183 void _printProgress() {
153 var percent = ((_completedTests() / _foundTests) * 100).floor().toString(); 184 var percent = ((_completedTests() / _foundTests) * 100).floor().toString();
154 var progressPadded = _pad(_allTestsKnown ? percent : _nextSpinner(), 5); 185 var progressPadded = _pad(_allTestsKnown ? percent : _nextSpinner(), 5);
155 var passedPadded = _pad(_passedTests.toString(), 5); 186 var passedPadded = _pad(_passedTests.toString(), 5);
156 var failedPadded = _pad(_failedTests.toString(), 5); 187 var failedPadded = _pad(_failedTests.toString(), 5);
188 Duration d = (new Date.now()).difference(_startTime);
157 var progressLine = 189 var progressLine =
158 '\r[${_timeString()} | $progressPadded% | ' + 190 '\r[${_timeString(d)} | $progressPadded% | ' +
159 '+$passedPadded | -$failedPadded]'; 191 '+$passedPadded | -$failedPadded]';
160 stdout.write(progressLine.charCodes()); 192 stdout.write(progressLine.charCodes());
161 } 193 }
162 } 194 }
163 195
164 196
165 class ColorProgressIndicator extends CompactIndicator { 197 class ColorProgressIndicator extends CompactIndicator {
166 ColorProgressIndicator(Date startTime) : super(startTime); 198 ColorProgressIndicator(Date startTime, bool printTiming)
199 : super(startTime, printTiming);
167 200
168 static int GREEN = 32; 201 static int GREEN = 32;
169 static int RED = 31; 202 static int RED = 31;
170 static int NONE = 0; 203 static int NONE = 0;
171 204
172 addColorWrapped(List<int> codes, String string, int color) { 205 addColorWrapped(List<int> codes, String string, int color) {
173 codes.add(27); 206 codes.add(27);
174 codes.addAll('[${color}m'.charCodes()); 207 codes.addAll('[${color}m'.charCodes());
175 codes.addAll(string.charCodes()); 208 codes.addAll(string.charCodes());
176 codes.add(27); 209 codes.add(27);
177 codes.addAll('[0m'.charCodes()); 210 codes.addAll('[0m'.charCodes());
178 } 211 }
179 212
180 void _printProgress() { 213 void _printProgress() {
181 var percent = ((_completedTests() / _foundTests) * 100).floor().toString(); 214 var percent = ((_completedTests() / _foundTests) * 100).floor().toString();
182 var progressPadded = _pad(_allTestsKnown ? percent : _nextSpinner(), 5); 215 var progressPadded = _pad(_allTestsKnown ? percent : _nextSpinner(), 5);
183 var passedPadded = _pad(_passedTests.toString(), 5); 216 var passedPadded = _pad(_passedTests.toString(), 5);
184 var failedPadded = _pad(_failedTests.toString(), 5); 217 var failedPadded = _pad(_failedTests.toString(), 5);
218 Duration d = (new Date.now()).difference(_startTime);
185 var progressLine = []; 219 var progressLine = [];
186 progressLine.addAll('\r[${_timeString()} | $progressPadded% | '.charCodes()) ; 220 progressLine.addAll('\r[${_timeString(d)} | $progressPadded% | '.charCodes() );
187 addColorWrapped(progressLine, '+$passedPadded ', GREEN); 221 addColorWrapped(progressLine, '+$passedPadded ', GREEN);
188 progressLine.addAll('| '.charCodes()); 222 progressLine.addAll('| '.charCodes());
189 var failedColor = (_failedTests != 0) ? RED : NONE; 223 var failedColor = (_failedTests != 0) ? RED : NONE;
190 addColorWrapped(progressLine, '-$failedPadded', failedColor); 224 addColorWrapped(progressLine, '-$failedPadded', failedColor);
191 progressLine.addAll(']'.charCodes()); 225 progressLine.addAll(']'.charCodes());
192 stdout.write(progressLine); 226 stdout.write(progressLine);
193 } 227 }
194 } 228 }
195 229
196 230
197 class LineProgressIndicator extends ProgressIndicator { 231 class LineProgressIndicator extends ProgressIndicator {
198 LineProgressIndicator(Date startTime) : super(startTime); 232 LineProgressIndicator(Date startTime, bool printTiming)
199 233 : super(startTime, printTiming);
200 void allDone() {
201 _printStatus();
202 exit(_failedTests > 0 ? 1 : 0);
203 }
204 234
205 void _printStartProgress(TestCase test) { 235 void _printStartProgress(TestCase test) {
206 } 236 }
207 237
208 void _printDoneProgress(TestCase test) { 238 void _printDoneProgress(TestCase test) {
209 var status = 'pass'; 239 var status = 'pass';
210 if (test.output.unexpectedOutput) { 240 if (test.output.unexpectedOutput) {
211 status = 'fail'; 241 status = 'fail';
212 } 242 }
213 print('Done ${test.displayName}: $status'); 243 print('Done ${test.displayName}: $status');
214 } 244 }
215 } 245 }
216 246
217 247
218 class VerboseProgressIndicator extends ProgressIndicator { 248 class VerboseProgressIndicator extends ProgressIndicator {
219 VerboseProgressIndicator(Date startTime) : super(startTime); 249 VerboseProgressIndicator(Date startTime, bool printTiming)
220 250 : super(startTime, bool printTiming);
ahe 2011/12/08 12:17:39 ../tools/testing/dart/test_progress.dart:242:31: E
Mads Ager (google) 2011/12/08 12:22:49 Whoops! Fixed.
221 void allDone() {
222 _printStatus();
223 exit(_failedTests > 0 ? 1 : 0);
224 }
225 251
226 void _printStartProgress(TestCase test) { 252 void _printStartProgress(TestCase test) {
227 print('Starting ${test.displayName}...'); 253 print('Starting ${test.displayName}...');
228 } 254 }
229 255
230 void _printDoneProgress(TestCase test) { 256 void _printDoneProgress(TestCase test) {
231 var status = 'pass'; 257 var status = 'pass';
232 if (test.output.unexpectedOutput) { 258 if (test.output.unexpectedOutput) {
233 status = 'fail'; 259 status = 'fail';
234 } 260 }
235 print('Done ${test.displayName}: $status'); 261 print('Done ${test.displayName}: $status');
236 } 262 }
237 } 263 }
238 264
239 265
240 class StatusProgressIndicator extends ProgressIndicator { 266 class StatusProgressIndicator extends ProgressIndicator {
241 StatusProgressIndicator(Date startTime) : super(startTime); 267 StatusProgressIndicator(Date startTime, bool printTiming)
242 268 : super(startTime, printTiming);
243 void allDone() {
244 _printStatus();
245 exit(_failedTests > 0 ? 1 : 0);
246 }
247 269
248 void _printStartProgress(TestCase test) { 270 void _printStartProgress(TestCase test) {
249 } 271 }
250 272
251 void _printDoneProgress(TestCase test) { 273 void _printDoneProgress(TestCase test) {
252 } 274 }
253 } 275 }
254 276
255 277
256 class BuildbotProgressIndicator extends ProgressIndicator { 278 class BuildbotProgressIndicator extends ProgressIndicator {
257 BuildbotProgressIndicator(Date startTime) : super(startTime); 279 BuildbotProgressIndicator(Date startTime, bool printTiming)
258 280 : super(startTime, printTiming);
259 void allDone() {
260 _printStatus();
261 exit(_failedTests > 0 ? 1 : 0);
262 }
263 281
264 void _printStartProgress(TestCase test) { 282 void _printStartProgress(TestCase test) {
265 } 283 }
266 284
267 void _printDoneProgress(TestCase test) { 285 void _printDoneProgress(TestCase test) {
268 var status = 'pass'; 286 var status = 'pass';
269 if (test.output.unexpectedOutput) { 287 if (test.output.unexpectedOutput) {
270 status = 'fail'; 288 status = 'fail';
271 } 289 }
272 var percent = ((_completedTests() / _foundTests) * 100).toInt().toString(); 290 var percent = ((_completedTests() / _foundTests) * 100).toInt().toString();
273 print('Done ${test.displayName}: $status'); 291 print('Done ${test.displayName}: $status');
274 print('@@@STEP_CLEAR@@@'); 292 print('@@@STEP_CLEAR@@@');
275 print('@@@STEP_TEXT@ $percent% +$_passedTests -$_failedTests @@@'); 293 print('@@@STEP_TEXT@ $percent% +$_passedTests -$_failedTests @@@');
276 } 294 }
277 } 295 }
OLDNEW
« no previous file with comments | « tools/testing/dart/test_options.dart ('k') | tools/testing/dart/test_runner.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698