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

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

Issue 18811008: Tweak unittest compact config a bit and don't use it on bots. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Fix comment. Created 7 years, 5 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 | « pkg/barback/test/utils.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) 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:async';
13 import 'dart:io'; 14 import 'dart:io';
15
14 import 'unittest.dart'; 16 import 'unittest.dart';
15 import 'vm_config.dart'; 17 import 'vm_config.dart';
16 18
17 const String _GREEN = '\u001b[32m'; 19 const String _GREEN = '\u001b[32m';
18 const String _RED = '\u001b[31m'; 20 const String _RED = '\u001b[31m';
19 const String _NONE = '\u001b[0m'; 21 const String _NONE = '\u001b[0m';
22
20 const int MAX_LINE = 80; 23 const int MAX_LINE = 80;
21 24
22 class CompactVMConfiguration extends VMConfiguration { 25 class CompactVMConfiguration extends VMConfiguration {
23 DateTime _start; 26 DateTime _start;
24 int _pass = 0; 27 int _pass = 0;
25 int _fail = 0; 28 int _fail = 0;
26 29
27 void onInit() { 30 void onInit() {
28 super.onInit(); 31 // Override and don't call the superclass onInit() to avoid printing the
32 // "unittest-suite-..." boilerplate.
29 } 33 }
30 34
31 void onStart() { 35 void onStart() {
32 super.onStart();
33 _start = new DateTime.now(); 36 _start = new DateTime.now();
34 } 37 }
35 38
36 void onTestStart(TestCase test) { 39 void onTestStart(TestCase test) {
37 super.onTestStart(test); 40 super.onTestStart(test);
38 _progressLine(_start, _pass, _fail, test.description); 41 _progressLine(_start, _pass, _fail, test.description);
39 } 42 }
40 43
41 void onTestResult(TestCase test) { 44 void onTestResult(TestCase test) {
42 super.onTestResult(test); 45 super.onTestResult(test);
43 if (test.result == PASS) { 46 if (test.result == PASS) {
44 _pass++; 47 _pass++;
45 _progressLine(_start, _pass, _fail, test.description); 48 _progressLine(_start, _pass, _fail, test.description);
46 } else { 49 } else {
47 _fail++; 50 _fail++;
48 _progressLine(_start, _pass, _fail, test.description); 51 _progressLine(_start, _pass, _fail, test.description);
49 print(''); 52 print('');
50 if (test.message != '') { 53 if (test.message != '') {
51 print(_indent(test.message)); 54 print(_indent(test.message));
52 } 55 }
53 56
54 if (test.stackTrace != null && test.stackTrace != '') { 57 if (test.stackTrace != null && test.stackTrace != '') {
55 print(_indent(test.stackTrace)); 58 print(_indent(test.stackTrace));
56 } 59 }
57 } 60 }
58 } 61 }
59 62
63 void onDone(bool success) {
64 // Override and don't call the superclass onDone() to avoid printing the
65 // "unittest-suite-..." boilerplate.
66 Future.wait([stdout.close(), stderr.close()]).then((_) {
67 exit(success ? 0 : 1);
68 });
69 }
70
60 String _indent(String str) { 71 String _indent(String str) {
61 return str.split("\n").map((line) => " $line").join("\n"); 72 return str.split("\n").map((line) => " $line").join("\n");
62 } 73 }
63 74
64 void onSummary(int passed, int failed, int errors, List<TestCase> results, 75 void onSummary(int passed, int failed, int errors, List<TestCase> results,
65 String uncaughtError) { 76 String uncaughtError) {
66 var success = false; 77 var success = false;
67 if (passed == 0 && failed == 0 && errors == 0 && uncaughtError == null) { 78 if (passed == 0 && failed == 0 && errors == 0 && uncaughtError == null) {
68 print('\nNo tests ran.'); 79 print('\nNo tests ran.');
69 } else if (failed == 0 && errors == 0 && uncaughtError == null) { 80 } else if (failed == 0 && errors == 0 && uncaughtError == null) {
70 _progressLine(_start, _pass, _fail, 'All tests pass', _GREEN); 81 _progressLine(_start, _pass, _fail, 'All tests passed!', _NONE);
71 print('\nAll $passed tests passed.'); 82 print('');
72 success = true; 83 success = true;
73 } else { 84 } else {
74 _progressLine(_start, _pass, _fail, 'Some tests fail', _RED); 85 _progressLine(_start, _pass, _fail, 'Some tests failed.', _RED);
75 print(''); 86 print('');
76 if (uncaughtError != null) { 87 if (uncaughtError != null) {
77 print('Top-level uncaught error: $uncaughtError'); 88 print('Top-level uncaught error: $uncaughtError');
78 } 89 }
79 print('$passed PASSED, $failed FAILED, $errors ERRORS'); 90 print('$passed PASSED, $failed FAILED, $errors ERRORS');
80 } 91 }
81 } 92 }
82 93
83 int _lastLength = 0; 94 int _lastLength = 0;
84 95
85 final int _nonVisiblePrefix = 1 + _GREEN.length + _NONE.length; 96 final int _nonVisiblePrefix = 1 + _GREEN.length + _NONE.length;
86 97
87 void _progressLine(DateTime startTime, int passed, int failed, String message, 98 void _progressLine(DateTime startTime, int passed, int failed, String message,
88 [String color = _NONE]) { 99 [String color = _NONE]) {
89 var duration = (new DateTime.now()).difference(startTime); 100 var duration = (new DateTime.now()).difference(startTime);
90 var buffer = new StringBuffer(); 101 var buffer = new StringBuffer();
91 // \r moves back to the beginning of the current line. 102 // \r moves back to the beginning of the current line.
92 buffer.write('\r${_timeString(duration)} '); 103 buffer.write('\r${_timeString(duration)} ');
93 buffer.write(_GREEN); 104 buffer.write(_GREEN);
94 buffer.write('+'); 105 buffer.write('+');
95 buffer.write(passed); 106 buffer.write(passed);
96 buffer.write(_NONE); 107 buffer.write(_NONE);
97 if (failed != 0) buffer.write(_RED); 108 if (failed != 0) {
98 buffer.write(' -'); 109 buffer.write(_RED);
99 buffer.write(failed); 110 buffer.write(' -');
100 if (failed != 0) buffer.write(_NONE); 111 buffer.write(failed);
112 buffer.write(_NONE);
113 }
101 buffer.write(': '); 114 buffer.write(': ');
102 buffer.write(color); 115 buffer.write(color);
103 116
104 // Ensure the line fits under MAX_LINE. [buffer] includes the color escape 117 // Ensure the line fits under MAX_LINE. [buffer] includes the color escape
105 // sequences too. Because these sequences are not visible characters, we 118 // sequences too. Because these sequences are not visible characters, we
106 // make sure they are not counted towards the limit. 119 // make sure they are not counted towards the limit.
107 int nonVisible = _nonVisiblePrefix + color.length + 120 int nonVisible = _nonVisiblePrefix + color.length +
108 (failed != 0 ? (_RED.length + _NONE.length) : 0); 121 (failed != 0 ? (_RED.length + _NONE.length) : 0);
109 int len = buffer.length - nonVisible; 122 int len = buffer.length - nonVisible;
110 var mx = MAX_LINE - len; 123 var mx = MAX_LINE - len;
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
164 var res = text.substring(text.length - maxLength + 4); 177 var res = text.substring(text.length - maxLength + 4);
165 var firstSpace = res.indexOf(' '); 178 var firstSpace = res.indexOf(' ');
166 if (firstSpace > 0) { 179 if (firstSpace > 0) {
167 res = res.substring(firstSpace); 180 res = res.substring(firstSpace);
168 } 181 }
169 return '...$res'; 182 return '...$res';
170 } 183 }
171 } 184 }
172 185
173 void useCompactVMConfiguration() { 186 void useCompactVMConfiguration() {
187 // If the test is running on the Dart buildbots, we don't want to use this
188 // config since it's output may not be what the bots expect.
189 if (Platform.environment.containsKey('BUILDBOT_BUILDERNAME')) {
190 return;
191 }
192
174 unittestConfiguration = _singleton; 193 unittestConfiguration = _singleton;
175 } 194 }
176 195
177 final _singleton = new CompactVMConfiguration(); 196 final _singleton = new CompactVMConfiguration();
OLDNEW
« no previous file with comments | « pkg/barback/test/utils.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698