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

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

Issue 8776049: Do not show percentages when we don't know what they are in test progress indication. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: 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 {
(...skipping 28 matching lines...) Expand all
39 void done(TestCase test) { 39 void done(TestCase test) {
40 if (test.output.unexpectedOutput) { 40 if (test.output.unexpectedOutput) {
41 _failedTests++; 41 _failedTests++;
42 _printFailureOutput(test); 42 _printFailureOutput(test);
43 } else { 43 } else {
44 _passedTests++; 44 _passedTests++;
45 } 45 }
46 _printDoneProgress(test); 46 _printDoneProgress(test);
47 } 47 }
48 48
49 void allTestsKnown() {
50 if (!_allTestsKnown) SummaryReport.printReport();
51 _allTestsKnown = true;
52 }
53
49 abstract allDone(); 54 abstract allDone();
50 abstract _printStartProgress(); 55 abstract _printStartProgress();
51 abstract _printDoneProgress(); 56 abstract _printDoneProgress();
52 57
53 String _pad(String s, int length) { 58 String _pad(String s, int length) {
54 StringBuffer buffer = new StringBuffer(); 59 StringBuffer buffer = new StringBuffer();
55 for (int i = s.length; i < length; i++) { 60 for (int i = s.length; i < length; i++) {
56 buffer.add(' '); 61 buffer.add(' ');
57 } 62 }
58 buffer.add(s); 63 buffer.add(s);
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
107 print('=== ${_failedTests} test$pluralSuffix failed'); 112 print('=== ${_failedTests} test$pluralSuffix failed');
108 print('===\n'); 113 print('===\n');
109 } 114 }
110 } 115 }
111 116
112 int _completedTests() => _passedTests + _failedTests; 117 int _completedTests() => _passedTests + _failedTests;
113 118
114 int _foundTests = 0; 119 int _foundTests = 0;
115 int _passedTests = 0; 120 int _passedTests = 0;
116 int _failedTests = 0; 121 int _failedTests = 0;
122 bool _allTestsKnown = false;
117 Date _startTime; 123 Date _startTime;
118 } 124 }
119 125
120 126
121 class CompactProgressIndicator extends ProgressIndicator { 127 class CompactIndicator extends ProgressIndicator {
122 CompactProgressIndicator(Date startTime) : super(startTime); 128 CompactIndicator(Date startTime) : super(startTime);
123 129
124 void allDone() { 130 void allDone() {
125 SummaryReport.printReport();
126 stdout.write('\n'.charCodes()); 131 stdout.write('\n'.charCodes());
127 stdout.close(); 132 stdout.close();
128 } 133 exit(_failedTests > 0 ? 1 : 0);
129
130 void _printProgress() {
131 var percent = ((_completedTests() / _foundTests) * 100).floor().toString();
132 var percentPadded = _pad(percent, 5);
133 var passedPadded = _pad(_passedTests.toString(), 5);
134 var failedPadded = _pad(_failedTests.toString(), 5);
135 var progressLine =
136 '\r[${_timeString()} | $percentPadded% | ' +
137 '+$passedPadded | -$failedPadded]';
138 stdout.write(progressLine.charCodes());
139 } 134 }
140 135
141 void _printStartProgress(TestCase test) => _printProgress(); 136 void _printStartProgress(TestCase test) => _printProgress();
142 void _printDoneProgress(TestCase test) => _printProgress(); 137 void _printDoneProgress(TestCase test) => _printProgress();
138
139 String _nextSpinner() {
140 _spinnerIndex = (_spinnerIndex + 1) % 4;
141 return _spinners[_spinnerIndex];
142 }
143
144 static int _spinnerIndex = 0;
145 static List<String> _spinners = const ['- ', '\\ ', '| ', '/ '];
143 } 146 }
144 147
145 148
146 class ColorProgressIndicator extends ProgressIndicator { 149 class CompactProgressIndicator extends CompactIndicator {
150 CompactProgressIndicator(Date startTime) : super(startTime);
151
152 void _printProgress() {
153 var percent = ((_completedTests() / _foundTests) * 100).floor().toString();
154 var progressPadded = _pad(_allTestsKnown ? percent : _nextSpinner(), 5);
155 var passedPadded = _pad(_passedTests.toString(), 5);
156 var failedPadded = _pad(_failedTests.toString(), 5);
157 var progressLine =
158 '\r[${_timeString()} | $progressPadded% | ' +
159 '+$passedPadded | -$failedPadded]';
160 stdout.write(progressLine.charCodes());
161 }
162 }
163
164
165 class ColorProgressIndicator extends CompactIndicator {
147 ColorProgressIndicator(Date startTime) : super(startTime); 166 ColorProgressIndicator(Date startTime) : super(startTime);
148 167
149 void allDone() {
150 SummaryReport.printReport();
151 stdout.write('\n'.charCodes());
152 stdout.close();
153 }
154
155 static int GREEN = 32; 168 static int GREEN = 32;
156 static int RED = 31; 169 static int RED = 31;
157 static int NONE = 0; 170 static int NONE = 0;
158 171
159 addColorWrapped(List<int> codes, String string, int color) { 172 addColorWrapped(List<int> codes, String string, int color) {
160 codes.add(27); 173 codes.add(27);
161 codes.addAll('[${color}m'.charCodes()); 174 codes.addAll('[${color}m'.charCodes());
162 codes.addAll(string.charCodes()); 175 codes.addAll(string.charCodes());
163 codes.add(27); 176 codes.add(27);
164 codes.addAll('[0m'.charCodes()); 177 codes.addAll('[0m'.charCodes());
165 } 178 }
166 179
167 void _printProgress() { 180 void _printProgress() {
168 var percent = ((_completedTests() / _foundTests) * 100).floor().toString(); 181 var percent = ((_completedTests() / _foundTests) * 100).floor().toString();
169 var percentPadded = _pad(percent, 5); 182 var progressPadded = _pad(_allTestsKnown ? percent : _nextSpinner(), 5);
170 var passedPadded = _pad(_passedTests.toString(), 5); 183 var passedPadded = _pad(_passedTests.toString(), 5);
171 var failedPadded = _pad(_failedTests.toString(), 5); 184 var failedPadded = _pad(_failedTests.toString(), 5);
172 var progressLine = []; 185 var progressLine = [];
173 progressLine.addAll('\r[${_timeString()} | $percentPadded% | '.charCodes()); 186 progressLine.addAll('\r[${_timeString()} | $progressPadded% | '.charCodes()) ;
174 addColorWrapped(progressLine, '+$passedPadded ', GREEN); 187 addColorWrapped(progressLine, '+$passedPadded ', GREEN);
175 progressLine.addAll('| '.charCodes()); 188 progressLine.addAll('| '.charCodes());
176 var failedColor = (_failedTests != 0) ? RED : NONE; 189 var failedColor = (_failedTests != 0) ? RED : NONE;
177 addColorWrapped(progressLine, '-$failedPadded', failedColor); 190 addColorWrapped(progressLine, '-$failedPadded', failedColor);
178 progressLine.addAll(']'.charCodes()); 191 progressLine.addAll(']'.charCodes());
179 stdout.write(progressLine); 192 stdout.write(progressLine);
180 } 193 }
181
182 void _printStartProgress(TestCase test) => _printProgress();
183 void _printDoneProgress(TestCase test) => _printProgress();
184 } 194 }
185 195
186 196
187
188 class LineProgressIndicator extends ProgressIndicator { 197 class LineProgressIndicator extends ProgressIndicator {
189 LineProgressIndicator(Date startTime) : super(startTime); 198 LineProgressIndicator(Date startTime) : super(startTime);
190 199
191 void allDone() { 200 void allDone() {
192 _printStatus(); 201 _printStatus();
193 SummaryReport.printReport(); 202 exit(_failedTests > 0 ? 1 : 0);
194 } 203 }
195 204
196 void _printStartProgress(TestCase test) { 205 void _printStartProgress(TestCase test) {
197 } 206 }
198 207
199 void _printDoneProgress(TestCase test) { 208 void _printDoneProgress(TestCase test) {
200 var status = 'pass'; 209 var status = 'pass';
201 if (test.output.unexpectedOutput) { 210 if (test.output.unexpectedOutput) {
202 status = 'fail'; 211 status = 'fail';
203 } 212 }
204 print('Done ${test.displayName}: $status'); 213 print('Done ${test.displayName}: $status');
205 } 214 }
206 } 215 }
207 216
208 217
209 class VerboseProgressIndicator extends ProgressIndicator { 218 class VerboseProgressIndicator extends ProgressIndicator {
210 VerboseProgressIndicator(Date startTime) : super(startTime); 219 VerboseProgressIndicator(Date startTime) : super(startTime);
211 220
212 void allDone() { 221 void allDone() {
213 _printStatus(); 222 _printStatus();
214 SummaryReport.printReport(); 223 exit(_failedTests > 0 ? 1 : 0);
215 } 224 }
216 225
217 void _printStartProgress(TestCase test) { 226 void _printStartProgress(TestCase test) {
218 print('Starting ${test.displayName}...'); 227 print('Starting ${test.displayName}...');
219 } 228 }
220 229
221 void _printDoneProgress(TestCase test) { 230 void _printDoneProgress(TestCase test) {
222 var status = 'pass'; 231 var status = 'pass';
223 if (test.output.unexpectedOutput) { 232 if (test.output.unexpectedOutput) {
224 status = 'fail'; 233 status = 'fail';
225 } 234 }
226 print('Done ${test.displayName}: $status'); 235 print('Done ${test.displayName}: $status');
227 } 236 }
228 } 237 }
229 238
230 239
231 class StatusProgressIndicator extends ProgressIndicator { 240 class StatusProgressIndicator extends ProgressIndicator {
232 StatusProgressIndicator(Date startTime) : super(startTime); 241 StatusProgressIndicator(Date startTime) : super(startTime);
233 242
234 void allDone() { 243 void allDone() {
235 _printStatus(); 244 _printStatus();
236 SummaryReport.printReport(); 245 exit(_failedTests > 0 ? 1 : 0);
237 } 246 }
238 247
239 void _printStartProgress(TestCase test) { 248 void _printStartProgress(TestCase test) {
240 } 249 }
241 250
242 void _printDoneProgress(TestCase test) { 251 void _printDoneProgress(TestCase test) {
243 } 252 }
244 } 253 }
245 254
246 255
247 class BuildbotProgressIndicator extends ProgressIndicator { 256 class BuildbotProgressIndicator extends ProgressIndicator {
248 BuildbotProgressIndicator(Date startTime) : super(startTime); 257 BuildbotProgressIndicator(Date startTime) : super(startTime);
249 258
250 void allDone() { 259 void allDone() {
251 _printStatus(); 260 _printStatus();
261 exit(_failedTests > 0 ? 1 : 0);
252 } 262 }
253 263
254 void _printStartProgress(TestCase test) { 264 void _printStartProgress(TestCase test) {
255 } 265 }
256 266
257 void _printDoneProgress(TestCase test) { 267 void _printDoneProgress(TestCase test) {
258 var status = 'pass'; 268 var status = 'pass';
259 if (test.output.unexpectedOutput) { 269 if (test.output.unexpectedOutput) {
260 status = 'fail'; 270 status = 'fail';
261 } 271 }
262 var percent = ((_completedTests() / _foundTests) * 100).toInt().toString(); 272 var percent = ((_completedTests() / _foundTests) * 100).toInt().toString();
263 print('Done ${test.displayName}: $status'); 273 print('Done ${test.displayName}: $status');
264 print('@@@STEP_CLEAR@@@'); 274 print('@@@STEP_CLEAR@@@');
265 print('@@@STEP_TEXT@ $percent% +$_passedTests -$_failedTests @@@'); 275 print('@@@STEP_TEXT@ $percent% +$_passedTests -$_failedTests @@@');
266 } 276 }
267 } 277 }
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