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

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

Issue 12864003: Revert "Update the test runner to use the new dart:io API" (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 9 months 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) 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.write(' '); 18 buffer.add(' ');
19 } 19 }
20 buffer.write(s); 20 buffer.add(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
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.write('Expected: '); 69 expected.add('Expected: ');
70 for (var expectation in test.expectedOutcomes) { 70 for (var expectation in test.expectedOutcomes) {
71 expected.write('$expectation '); 71 expected.add('$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
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.write("$l\n"); 146 buf.add("$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 DateTime _startTime; 170 Date _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 DateTime.now()).difference(_startTime); 180 Duration d = (new Date.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
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 count = 0; 290 var tempDirs = [];
291 var systemTempDir = _tempDir(); 291 var systemTempDir = _tempDir();
292 var lister = new Directory.fromPath(systemTempDir).list().listen( 292 var lister = new Directory.fromPath(systemTempDir).list();
293 (FileSystemEntity fse) { 293 lister.onDir = (path) => tempDirs.add(path);
294 if (fse is Directory) count++; 294 lister.onDone = (_) {
295 }, 295 if (tempDirs.length > MIN_NUMBER_OF_TEMP_DIRS) {
296 onDone: () { 296 DebugLogger.warning("There are ${tempDirs.length} directories "
297 if (count > MIN_NUMBER_OF_TEMP_DIRS) { 297 "in the system tempdir ('$systemTempDir')! "
298 DebugLogger.warning("There are ${tempDirs.length} directories " 298 "Maybe left over directories?\n");
299 "in the system tempdir ('$systemTempDir')! "
300 "Maybe left over directories?\n");
301 } 299 }
302 }); 300 };
303 } 301 }
304 } 302 }
305 303
306 class LineProgressIndicator extends EventListener { 304 class LineProgressIndicator extends EventListener {
307 void done(TestCase test) { 305 void done(TestCase test) {
308 var status = 'pass'; 306 var status = 'pass';
309 if (test.lastCommandOutput.unexpectedOutput) { 307 if (test.lastCommandOutput.unexpectedOutput) {
310 status = 'fail'; 308 status = 'fail';
311 } 309 }
312 print('Done ${test.configurationString} ${test.displayName}: $status'); 310 print('Done ${test.configurationString} ${test.displayName}: $status');
(...skipping 12 matching lines...) Expand all
325 } 323 }
326 print(''); 324 print('');
327 } 325 }
328 } 326 }
329 } 327 }
330 328
331 class ProgressIndicator extends EventListener { 329 class ProgressIndicator extends EventListener {
332 ProgressIndicator(this._startTime); 330 ProgressIndicator(this._startTime);
333 331
334 factory ProgressIndicator.fromName(String name, 332 factory ProgressIndicator.fromName(String name,
335 DateTime startTime, 333 Date startTime,
336 Formatter formatter) { 334 Formatter formatter) {
337 switch (name) { 335 switch (name) {
338 case 'compact': 336 case 'compact':
339 return new CompactProgressIndicator(startTime, formatter); 337 return new CompactProgressIndicator(startTime, formatter);
340 case 'line': 338 case 'line':
341 return new LineProgressIndicator(); 339 return new LineProgressIndicator();
342 case 'verbose': 340 case 'verbose':
343 return new VerboseProgressIndicator(startTime); 341 return new VerboseProgressIndicator(startTime);
344 case 'status': 342 case 'status':
345 return new ProgressIndicator(startTime); 343 return new ProgressIndicator(startTime);
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
391 } 389 }
392 390
393 int get numFailedTests => _failedTests; 391 int get numFailedTests => _failedTests;
394 392
395 int _completedTests() => _passedTests + _failedTests; 393 int _completedTests() => _passedTests + _failedTests;
396 394
397 int _foundTests = 0; 395 int _foundTests = 0;
398 int _passedTests = 0; 396 int _passedTests = 0;
399 int _failedTests = 0; 397 int _failedTests = 0;
400 bool _allTestsKnown = false; 398 bool _allTestsKnown = false;
401 DateTime _startTime; 399 Date _startTime;
402 } 400 }
403 401
404 abstract class CompactIndicator extends ProgressIndicator { 402 abstract class CompactIndicator extends ProgressIndicator {
405 CompactIndicator(DateTime startTime) 403 CompactIndicator(Date startTime)
406 : super(startTime); 404 : super(startTime);
407 405
408 void allDone() { 406 void allDone() {
409 stdout.writeln(''); 407 stdout.write('\n'.charCodes);
410 if (_failedTests > 0) { 408 if (_failedTests > 0) {
411 // We may have printed many failure logs, so reprint the summary data. 409 // We may have printed many failure logs, so reprint the summary data.
412 _printProgress(); 410 _printProgress();
413 print(''); 411 print('');
414 } 412 }
415 stdout.close(); 413 stdout.close();
416 stderr.close(); 414 stderr.close();
417 } 415 }
418 416
419 void _printStartProgress(TestCase test) => _printProgress(); 417 void _printStartProgress(TestCase test) => _printProgress();
420 void _printDoneProgress(TestCase test) => _printProgress(); 418 void _printDoneProgress(TestCase test) => _printProgress();
421 419
422 void _printProgress(); 420 void _printProgress();
423 } 421 }
424 422
425 423
426 class CompactProgressIndicator extends CompactIndicator { 424 class CompactProgressIndicator extends CompactIndicator {
427 Formatter _formatter; 425 Formatter _formatter;
428 426
429 CompactProgressIndicator(DateTime startTime, this._formatter) 427 CompactProgressIndicator(Date startTime, this._formatter)
430 : super(startTime); 428 : super(startTime);
431 429
432 void _printProgress() { 430 void _printProgress() {
433 var percent = ((_completedTests() / _foundTests) * 100).toInt().toString(); 431 var percent = ((_completedTests() / _foundTests) * 100).toInt().toString();
434 var progressPadded = _pad(_allTestsKnown ? percent : '--', 3); 432 var progressPadded = _pad(_allTestsKnown ? percent : '--', 3);
435 var passedPadded = _pad(_passedTests.toString(), 5); 433 var passedPadded = _pad(_passedTests.toString(), 5);
436 var failedPadded = _pad(_failedTests.toString(), 5); 434 var failedPadded = _pad(_failedTests.toString(), 5);
437 Duration d = (new DateTime.now()).difference(_startTime); 435 Duration d = (new Date.now()).difference(_startTime);
438 var progressLine = 436 var progressLine =
439 '\r[${_timeString(d)} | $progressPadded% | ' 437 '\r[${_timeString(d)} | $progressPadded% | '
440 '+${_formatter.passed(passedPadded)} | ' 438 '+${_formatter.passed(passedPadded)} | '
441 '-${_formatter.failed(failedPadded)}]'; 439 '-${_formatter.failed(failedPadded)}]';
442 stdout.write(progressLine); 440 stdout.write(progressLine.charCodes);
443 } 441 }
444 } 442 }
445 443
446 444
447 class VerboseProgressIndicator extends ProgressIndicator { 445 class VerboseProgressIndicator extends ProgressIndicator {
448 VerboseProgressIndicator(DateTime startTime) 446 VerboseProgressIndicator(Date startTime)
449 : super(startTime); 447 : super(startTime);
450 448
451 void _printStartProgress(TestCase test) { 449 void _printStartProgress(TestCase test) {
452 print('Starting ${test.configurationString} ${test.displayName}...'); 450 print('Starting ${test.configurationString} ${test.displayName}...');
453 } 451 }
454 452
455 void _printDoneProgress(TestCase test) { 453 void _printDoneProgress(TestCase test) {
456 var status = 'pass'; 454 var status = 'pass';
457 if (test.lastCommandOutput.unexpectedOutput) { 455 if (test.lastCommandOutput.unexpectedOutput) {
458 status = 'fail'; 456 status = 'fail';
459 } 457 }
460 print('Done ${test.configurationString} ${test.displayName}: $status'); 458 print('Done ${test.configurationString} ${test.displayName}: $status');
461 } 459 }
462 } 460 }
463 461
464 462
465 class BuildbotProgressIndicator extends ProgressIndicator { 463 class BuildbotProgressIndicator extends ProgressIndicator {
466 static String stepName; 464 static String stepName;
467 var _failureSummary = <String>[]; 465 var _failureSummary = <String>[];
468 466
469 BuildbotProgressIndicator(DateTime startTime) : super(startTime); 467 BuildbotProgressIndicator(Date startTime) : super(startTime);
470 468
471 void done(TestCase test) { 469 void done(TestCase test) {
472 super.done(test); 470 super.done(test);
473 if (test.lastCommandOutput.unexpectedOutput) { 471 if (test.lastCommandOutput.unexpectedOutput) {
474 _failureSummary.addAll(_buildFailureOutput(test)); 472 _failureSummary.addAll(_buildFailureOutput(test));
475 } 473 }
476 } 474 }
477 475
478 void _printDoneProgress(TestCase test) { 476 void _printDoneProgress(TestCase test) {
479 var status = 'pass'; 477 var status = 'pass';
(...skipping 11 matching lines...) Expand all
491 print('@@@STEP_FAILURE@@@'); 489 print('@@@STEP_FAILURE@@@');
492 print('@@@BUILD_STEP $stepName failures@@@'); 490 print('@@@BUILD_STEP $stepName failures@@@');
493 for (String line in _failureSummary) { 491 for (String line in _failureSummary) {
494 print(line); 492 print(line);
495 } 493 }
496 print(''); 494 print('');
497 } 495 }
498 super.allDone(); 496 super.allDone();
499 } 497 }
500 } 498 }
499
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