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

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

Issue 11364129: Added support for logging the output of failed flaky tests. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 1 month 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
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("test_runner.dart"); 8 #import("test_runner.dart");
9 #import("test_suite.dart"); 9 #import("test_suite.dart");
10 #import("status_file_parser.dart");
10 11
11 class ProgressIndicator { 12 class ProgressIndicator {
12 ProgressIndicator(this._startTime, this._printTiming) 13 ProgressIndicator(this._startTime, this._printTiming)
13 : _tests = [], _failureSummary = []; 14 : _tests = [], _failureSummary = [];
14 15
15 factory ProgressIndicator.fromName(String name, 16 factory ProgressIndicator.fromName(String name,
16 Date startTime, 17 Date startTime,
17 bool printTiming) { 18 bool printTiming) {
18 switch (name) { 19 switch (name) {
19 case 'compact': 20 case 'compact':
(...skipping 18 matching lines...) Expand all
38 } 39 }
39 } 40 }
40 41
41 void testAdded() { _foundTests++; } 42 void testAdded() { _foundTests++; }
42 43
43 void start(TestCase test) { 44 void start(TestCase test) {
44 _printStartProgress(test); 45 _printStartProgress(test);
45 } 46 }
46 47
47 void done(TestCase test) { 48 void done(TestCase test) {
49 if (test.isFlaky && test.output.result != PASS) {
50 var buf = new StringBuffer();
51 for (var l in _buildFailureOutput(test)) {
52 buf.add("$l\n");
53 }
54 _appendToFlakyFile(buf.toString());
55 }
56
48 if (test.output.unexpectedOutput) { 57 if (test.output.unexpectedOutput) {
49 _failedTests++; 58 _failedTests++;
50 _printFailureOutput(test); 59 _printFailureOutput(test);
51 } else { 60 } else {
52 _passedTests++; 61 _passedTests++;
53 } 62 }
54 _printDoneProgress(test); 63 _printDoneProgress(test);
55 // If we need to print timing information we hold on to all completed 64 // If we need to print timing information we hold on to all completed
56 // tests. 65 // tests.
57 if (_printTiming) _tests.add(test); 66 if (_printTiming) _tests.add(test);
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
113 122
114 String _timeString(Duration d) { 123 String _timeString(Duration d) {
115 var min = d.inMinutes; 124 var min = d.inMinutes;
116 var sec = d.inSeconds % 60; 125 var sec = d.inSeconds % 60;
117 return '${_padTime(min)}:${_padTime(sec)}'; 126 return '${_padTime(min)}:${_padTime(sec)}';
118 } 127 }
119 128
120 String _header(String header) => header; 129 String _header(String header) => header;
121 130
122 void _printFailureOutput(TestCase test) { 131 void _printFailureOutput(TestCase test) {
132 var failureOutput = _buildFailureOutput(test);
133 for (var line in failureOutput) {
134 print(line);
135 }
136 _failureSummary.addAll(failureOutput);
137 }
138
139 List<String> _buildFailureOutput(TestCase test) {
123 List<String> output = new List<String>(); 140 List<String> output = new List<String>();
124 output.add(''); 141 output.add('');
125 output.add(_header('FAILED: ${test.configurationString}' 142 output.add(_header('FAILED: ${test.configurationString}'
126 ' ${test.displayName}')); 143 ' ${test.displayName}'));
127 StringBuffer expected = new StringBuffer(); 144 StringBuffer expected = new StringBuffer();
128 expected.add('Expected: '); 145 expected.add('Expected: ');
129 for (var expectation in test.expectedOutcomes) { 146 for (var expectation in test.expectedOutcomes) {
130 expected.add('$expectation '); 147 expected.add('$expectation ');
131 } 148 }
132 output.add(expected.toString()); 149 output.add(expected.toString());
(...skipping 30 matching lines...) Expand all
163 for (var s in test.output.stderr) { 180 for (var s in test.output.stderr) {
164 output.add(s); 181 output.add(s);
165 } 182 }
166 } 183 }
167 for (Command c in test.commands) { 184 for (Command c in test.commands) {
168 output.add(''); 185 output.add('');
169 String message = (c == test.commands.last 186 String message = (c == test.commands.last
170 ? "Command line" : "Compilation command"); 187 ? "Command line" : "Compilation command");
171 output.add('$message: ${c.commandLine}'); 188 output.add('$message: ${c.commandLine}');
172 } 189 }
173 for (String line in output) { 190 return output;
174 print(line);
175 }
176 _failureSummary.addAll(output);
177 } 191 }
178 192
179 void _printFailureSummary() { 193 void _printFailureSummary() {
180 for (String line in _failureSummary) { 194 for (String line in _failureSummary) {
181 print(line); 195 print(line);
182 } 196 }
183 print(''); 197 print('');
184 } 198 }
185 199
186 void _printStatus() { 200 void _printStatus() {
187 if (_failedTests == 0) { 201 if (_failedTests == 0) {
188 print('\n==='); 202 print('\n===');
189 print('=== All tests succeeded'); 203 print('=== All tests succeeded');
190 print('===\n'); 204 print('===\n');
191 } else { 205 } else {
192 var pluralSuffix = _failedTests != 1 ? 's' : ''; 206 var pluralSuffix = _failedTests != 1 ? 's' : '';
193 print('\n==='); 207 print('\n===');
194 print('=== ${_failedTests} test$pluralSuffix failed'); 208 print('=== ${_failedTests} test$pluralSuffix failed');
195 print('===\n'); 209 print('===\n');
196 } 210 }
197 } 211 }
198 212
213 void _appendToFlakyFile(String msg) {
214 var file = new File(TestUtils.flakyFileName());
215 var fd = file.openSync(FileMode.APPEND);
216 fd.writeStringSync(msg);
217 fd.closeSync();
218 }
219
199 int get numFailedTests => _failedTests; 220 int get numFailedTests => _failedTests;
200 221
201 int _completedTests() => _passedTests + _failedTests; 222 int _completedTests() => _passedTests + _failedTests;
202 223
203 int _foundTests = 0; 224 int _foundTests = 0;
204 int _passedTests = 0; 225 int _passedTests = 0;
205 int _failedTests = 0; 226 int _failedTests = 0;
206 bool _allTestsKnown = false; 227 bool _allTestsKnown = false;
207 Date _startTime; 228 Date _startTime;
208 bool _printTiming; 229 bool _printTiming;
(...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after
441 print(''); 462 print('');
442 print('$config:'); 463 print('$config:');
443 statuses.sort((a, b) => a.compareTo(b)); 464 statuses.sort((a, b) => a.compareTo(b));
444 for (String status in statuses) { 465 for (String status in statuses) {
445 print(' $status'); 466 print(' $status');
446 } 467 }
447 }); 468 });
448 _printStatus(); 469 _printStatus();
449 } 470 }
450 } 471 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698