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

Side by Side Diff: pkg/unittest/lib/compact_vm_config.dart

Issue 11829045: Cleaning up unittest configurations (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 11 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 | « no previous file | pkg/unittest/lib/html_config.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) 2013, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2013, 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 /** 5 /**
6 * A test configuration that generates a compact 1-line progress bar. The bar is 6 * A test configuration that generates a compact 1-line progress bar. The bar is
7 * updated in-place before and after each test is executed. If all test pass, 7 * updated in-place before and after each test is executed. If all test pass,
8 * you should only see a couple lines in the terminal. If a test fails, the 8 * you should only see a couple lines in the terminal. If a test fails, the
9 * failure is shown and the progress bar continues to be updated below it. 9 * failure is shown and the progress bar continues to be updated below it.
10 */ 10 */
11 library compact_vm_config; 11 library compact_vm_config;
12 12
13 import 'dart:io'; 13 import 'dart:io';
14 import 'package:unittest/unittest.dart'; 14 import 'unittest.dart';
15 15
16 const String _GREEN = '\u001b[32m'; 16 const String _GREEN = '\u001b[32m';
17 const String _RED = '\u001b[31m'; 17 const String _RED = '\u001b[31m';
18 const String _NONE = '\u001b[0m'; 18 const String _NONE = '\u001b[0m';
19 const int MAX_LINE = 80; 19 const int MAX_LINE = 80;
20 20
21 class CompactVMConfiguration extends Configuration { 21 class CompactVMConfiguration extends Configuration {
22 Date _start; 22 Date _start;
23 int _pass = 0; 23 int _pass = 0;
24 int _fail = 0; 24 int _fail = 0;
(...skipping 28 matching lines...) Expand all
53 if (test.stackTrace != null && test.stackTrace != '') { 53 if (test.stackTrace != null && test.stackTrace != '') {
54 print(_indent(test.stackTrace)); 54 print(_indent(test.stackTrace));
55 } 55 }
56 } 56 }
57 } 57 }
58 58
59 String _indent(String str) { 59 String _indent(String str) {
60 return str.split("\n").mappedBy((line) => " $line").join("\n"); 60 return str.split("\n").mappedBy((line) => " $line").join("\n");
61 } 61 }
62 62
63 void onDone(int passed, int failed, int errors, List<TestCase> results, 63 void onSummary(int passed, int failed, int errors, List<TestCase> results,
64 String uncaughtError) { 64 String uncaughtError) {
65 var success = false; 65 var success = false;
66 if (passed == 0 && failed == 0 && errors == 0) { 66 if (passed == 0 && failed == 0 && errors == 0) {
67 print('\nNo tests ran.'); 67 print('\nNo tests ran.');
68 } else if (failed == 0 && errors == 0 && uncaughtError == null) { 68 } else if (failed == 0 && errors == 0 && uncaughtError == null) {
69 _progressLine(_start, _pass, _fail, 'All tests pass', _GREEN); 69 _progressLine(_start, _pass, _fail, 'All tests pass', _GREEN);
70 print('\nAll $passed tests passed.'); 70 print('\nAll $passed tests passed.');
71 success = true; 71 success = true;
72 } else { 72 } else {
73 _progressLine(_start, _pass, _fail, 'Some tests fail', _RED); 73 _progressLine(_start, _pass, _fail, 'Some tests fail', _RED);
74 print(''); 74 print('');
75 if (uncaughtError != null) { 75 if (uncaughtError != null) {
76 print('Top-level uncaught error: $uncaughtError'); 76 print('Top-level uncaught error: $uncaughtError');
77 } 77 }
78 print('$passed PASSED, $failed FAILED, $errors ERRORS'); 78 print('$passed PASSED, $failed FAILED, $errors ERRORS');
79 } 79 }
80 }
80 81
81 if (!success) exit(1); 82 void onDone(bool success) {
83 try {
84 super.onDone(success);
85 } on Exception catch(ex) {
Jennifer Messerly 2013/01/10 02:31:32 should this just be a raw catch -- or do we know f
Siggi Cherem (dart-lang) 2013/01/10 02:44:49 Done (see changes in vm_config). Technically we kn
86 exit(1);
Jennifer Messerly 2013/01/10 02:31:32 out of curiousity -- why do we need the explicit "
Siggi Cherem (dart-lang) 2013/01/10 02:44:49 Configuration (the base class I was using) is mean
87 }
82 } 88 }
83 89
84 int _lastLength = 0; 90 int _lastLength = 0;
85 91
86 final int _nonVisiblePrefix = 1 + _GREEN.length + _NONE.length; 92 final int _nonVisiblePrefix = 1 + _GREEN.length + _NONE.length;
87 93
88 void _progressLine(Date startTime, int passed, int failed, String message, 94 void _progressLine(Date startTime, int passed, int failed, String message,
89 [String color = _NONE]) { 95 [String color = _NONE]) {
90 var duration = (new Date.now()).difference(startTime); 96 var duration = (new Date.now()).difference(startTime);
91 var buffer = new StringBuffer(); 97 var buffer = new StringBuffer();
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
159 165
160 // Otherwise truncate to return the trailing text, but attempt to start at 166 // Otherwise truncate to return the trailing text, but attempt to start at
161 // the beginning of a word. 167 // the beginning of a word.
162 var res = text.substring(text.length - maxLength + 4); 168 var res = text.substring(text.length - maxLength + 4);
163 var firstSpace = res.indexOf(' '); 169 var firstSpace = res.indexOf(' ');
164 if (firstSpace > 0) { 170 if (firstSpace > 0) {
165 res = res.substring(firstSpace); 171 res = res.substring(firstSpace);
166 } 172 }
167 return '...$res'; 173 return '...$res';
168 } 174 }
175
176 void notifyController(String msg) {}
169 } 177 }
170 178
171 void useCompactVMConfiguration() { 179 void useCompactVMConfiguration() {
172 configure(new CompactVMConfiguration()); 180 configure(new CompactVMConfiguration());
173 } 181 }
OLDNEW
« no previous file with comments | « no previous file | pkg/unittest/lib/html_config.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698