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

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

Issue 18892003: Roll forward "Use package:stack_trace in unittest." (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Merge head. 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 | « 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:async'; 13 import 'dart:async';
14 import 'dart:io'; 14 import 'dart:io';
15 15
16 import 'unittest.dart'; 16 import 'unittest.dart';
17 import 'src/utils.dart';
17 import 'vm_config.dart'; 18 import 'vm_config.dart';
18 19
19 const String _GREEN = '\u001b[32m'; 20 const String _GREEN = '\u001b[32m';
20 const String _RED = '\u001b[31m'; 21 const String _RED = '\u001b[31m';
21 const String _NONE = '\u001b[0m'; 22 const String _NONE = '\u001b[0m';
22 23
23 const int MAX_LINE = 80; 24 const int MAX_LINE = 80;
24 25
25 class CompactVMConfiguration extends VMConfiguration { 26 class CompactVMConfiguration extends VMConfiguration {
26 DateTime _start; 27 DateTime _start;
(...skipping 17 matching lines...) Expand all
44 void onTestResult(TestCase test) { 45 void onTestResult(TestCase test) {
45 super.onTestResult(test); 46 super.onTestResult(test);
46 if (test.result == PASS) { 47 if (test.result == PASS) {
47 _pass++; 48 _pass++;
48 _progressLine(_start, _pass, _fail, test.description); 49 _progressLine(_start, _pass, _fail, test.description);
49 } else { 50 } else {
50 _fail++; 51 _fail++;
51 _progressLine(_start, _pass, _fail, test.description); 52 _progressLine(_start, _pass, _fail, test.description);
52 print(''); 53 print('');
53 if (test.message != '') { 54 if (test.message != '') {
54 print(_indent(test.message)); 55 print(indent(test.message));
55 } 56 }
56 57
57 if (test.stackTrace != null && test.stackTrace != '') { 58 if (test.stackTrace != null) {
58 print(_indent(test.stackTrace)); 59 print(indent(test.stackTrace.toString()));
59 } 60 }
60 } 61 }
61 } 62 }
62 63
63 void onDone(bool success) { 64 void onDone(bool success) {
64 // Override and don't call the superclass onDone() to avoid printing the 65 // Override and don't call the superclass onDone() to avoid printing the
65 // "unittest-suite-..." boilerplate. 66 // "unittest-suite-..." boilerplate.
66 Future.wait([stdout.close(), stderr.close()]).then((_) { 67 Future.wait([stdout.close(), stderr.close()]).then((_) {
67 exit(success ? 0 : 1); 68 exit(success ? 0 : 1);
68 }); 69 });
69 } 70 }
70 71
71 String _indent(String str) {
72 return str.split("\n").map((line) => " $line").join("\n");
73 }
74
75 void onSummary(int passed, int failed, int errors, List<TestCase> results, 72 void onSummary(int passed, int failed, int errors, List<TestCase> results,
76 String uncaughtError) { 73 String uncaughtError) {
77 var success = false; 74 var success = false;
78 if (passed == 0 && failed == 0 && errors == 0 && uncaughtError == null) { 75 if (passed == 0 && failed == 0 && errors == 0 && uncaughtError == null) {
79 print('\nNo tests ran.'); 76 print('\nNo tests ran.');
80 } else if (failed == 0 && errors == 0 && uncaughtError == null) { 77 } else if (failed == 0 && errors == 0 && uncaughtError == null) {
81 _progressLine(_start, _pass, _fail, 'All tests passed!', _NONE); 78 _progressLine(_start, _pass, _fail, 'All tests passed!', _NONE);
82 print(''); 79 print('');
83 success = true; 80 success = true;
84 } else { 81 } else {
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
187 // If the test is running on the Dart buildbots, we don't want to use this 184 // 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. 185 // config since it's output may not be what the bots expect.
189 if (Platform.environment.containsKey('BUILDBOT_BUILDERNAME')) { 186 if (Platform.environment.containsKey('BUILDBOT_BUILDERNAME')) {
190 return; 187 return;
191 } 188 }
192 189
193 unittestConfiguration = _singleton; 190 unittestConfiguration = _singleton;
194 } 191 }
195 192
196 final _singleton = new CompactVMConfiguration(); 193 final _singleton = new CompactVMConfiguration();
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