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

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

Issue 8772044: Add color indication to progress. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Line length 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') | no next file » | 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);
12 12
13 factory ProgressIndicator.fromName(String name, Date startTime) { 13 factory ProgressIndicator.fromName(String name, Date startTime) {
14 switch (name) { 14 switch (name) {
15 case 'compact': 15 case 'compact':
16 return new CompactProgressIndicator(startTime); 16 return new CompactProgressIndicator(startTime);
17 case 'color':
18 return new ColorProgressIndicator(startTime);
17 case 'line': 19 case 'line':
18 return new LineProgressIndicator(startTime); 20 return new LineProgressIndicator(startTime);
19 case 'verbose': 21 case 'verbose':
20 return new VerboseProgressIndicator(startTime); 22 return new VerboseProgressIndicator(startTime);
21 case 'status': 23 case 'status':
22 return new StatusProgressIndicator(startTime); 24 return new StatusProgressIndicator(startTime);
23 case 'buildbot': 25 case 'buildbot':
24 return new BuildbotProgressIndicator(startTime); 26 return new BuildbotProgressIndicator(startTime);
25 default: 27 default:
26 assert(false); 28 assert(false);
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
134 '\r[${_timeString()} | $percentPadded% | ' + 136 '\r[${_timeString()} | $percentPadded% | ' +
135 '+$passedPadded | -$failedPadded]'; 137 '+$passedPadded | -$failedPadded]';
136 stdout.write(progressLine.charCodes()); 138 stdout.write(progressLine.charCodes());
137 } 139 }
138 140
139 void _printStartProgress(TestCase test) => _printProgress(); 141 void _printStartProgress(TestCase test) => _printProgress();
140 void _printDoneProgress(TestCase test) => _printProgress(); 142 void _printDoneProgress(TestCase test) => _printProgress();
141 } 143 }
142 144
143 145
146 class ColorProgressIndicator extends ProgressIndicator {
147 ColorProgressIndicator(Date startTime) : super(startTime);
148
149 void allDone() {
150 SummaryReport.printReport();
151 stdout.write('\n'.charCodes());
152 stdout.close();
153 }
154
155 static int GREEN = 32;
156 static int RED = 31;
157 static int NONE = 0;
158
159 addColorWrapped(List<int> codes, String string, int color) {
160 codes.add(27);
161 codes.addAll('[${color}m'.charCodes());
162 codes.addAll(string.charCodes());
163 codes.add(27);
164 codes.addAll('[0m'.charCodes());
165 }
166
167 void _printProgress() {
168 var percent = ((_completedTests() / _foundTests) * 100).floor().toString();
169 var percentPadded = _pad(percent, 5);
170 var passedPadded = _pad(_passedTests.toString(), 5);
171 var failedPadded = _pad(_failedTests.toString(), 5);
172 var progressLine = [];
173 progressLine.addAll('\r[${_timeString()} | $percentPadded% | '.charCodes());
174 addColorWrapped(progressLine, '+$passedPadded ', GREEN);
175 progressLine.addAll('| '.charCodes());
176 var failedColor = (_failedTests != 0) ? RED : NONE;
177 addColorWrapped(progressLine, '-$failedPadded', failedColor);
178 progressLine.addAll(']'.charCodes());
179 stdout.write(progressLine);
180 }
181
182 void _printStartProgress(TestCase test) => _printProgress();
183 void _printDoneProgress(TestCase test) => _printProgress();
184 }
185
186
187
144 class LineProgressIndicator extends ProgressIndicator { 188 class LineProgressIndicator extends ProgressIndicator {
145 LineProgressIndicator(Date startTime) : super(startTime); 189 LineProgressIndicator(Date startTime) : super(startTime);
146 190
147 void allDone() { 191 void allDone() {
148 _printStatus(); 192 _printStatus();
149 SummaryReport.printReport(); 193 SummaryReport.printReport();
150 } 194 }
151 195
152 void _printStartProgress(TestCase test) { 196 void _printStartProgress(TestCase test) {
153 } 197 }
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
214 var status = 'pass'; 258 var status = 'pass';
215 if (test.output.unexpectedOutput) { 259 if (test.output.unexpectedOutput) {
216 status = 'fail'; 260 status = 'fail';
217 } 261 }
218 var percent = ((_completedTests() / _foundTests) * 100).toInt().toString(); 262 var percent = ((_completedTests() / _foundTests) * 100).toInt().toString();
219 print('Done ${test.displayName}: $status'); 263 print('Done ${test.displayName}: $status');
220 print('@@@STEP_CLEAR@@@'); 264 print('@@@STEP_CLEAR@@@');
221 print('@@@STEP_TEXT@ $percent% +$_passedTests -$_failedTests @@@'); 265 print('@@@STEP_TEXT@ $percent% +$_passedTests -$_failedTests @@@');
222 } 266 }
223 } 267 }
OLDNEW
« no previous file with comments | « tools/testing/dart/test_options.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698