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

Side by Side Diff: lib/src/runner/reporter/compact.dart

Issue 1083433002: More gracefully handle load errors. (Closed) Base URL: git@github.com:dart-lang/test@master
Patch Set: Code review changes Created 5 years, 8 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
« no previous file with comments | « lib/src/runner/loader.dart ('k') | test/runner/browser/compiler_pool_test.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) 2015, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2015, 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.runner.reporter.compact; 5 library test.runner.reporter.compact;
6 6
7 import 'dart:async'; 7 import 'dart:async';
8 import 'dart:io'; 8 import 'dart:io';
9 import 'dart:isolate';
9 10
10 import '../../backend/live_test.dart'; 11 import '../../backend/live_test.dart';
11 import '../../backend/state.dart'; 12 import '../../backend/state.dart';
12 import '../../backend/suite.dart'; 13 import '../../backend/suite.dart';
13 import '../../utils.dart'; 14 import '../../utils.dart';
14 import '../engine.dart'; 15 import '../engine.dart';
16 import '../load_exception.dart';
15 17
16 /// The maximum console line length. 18 /// The maximum console line length.
17 /// 19 ///
18 /// Lines longer than this will be cropped. 20 /// Lines longer than this will be cropped.
19 const _lineLength = 100; 21 const _lineLength = 100;
20 22
21 /// A reporter that prints test results to the console in a single 23 /// A reporter that prints test results to the console in a single
22 /// continuously-updating line. 24 /// continuously-updating line.
23 class CompactReporter { 25 class CompactReporter {
26 /// Whether the reporter should emit terminal color escapes.
27 final bool _color;
28
24 /// The terminal escape for green text, or the empty string if this is Windows 29 /// The terminal escape for green text, or the empty string if this is Windows
25 /// or not outputting to a terminal. 30 /// or not outputting to a terminal.
26 final String _green; 31 final String _green;
27 32
28 /// The terminal escape for red text, or the empty string if this is Windows 33 /// The terminal escape for red text, or the empty string if this is Windows
29 /// or not outputting to a terminal. 34 /// or not outputting to a terminal.
30 final String _red; 35 final String _red;
31 36
32 /// The terminal escape for removing test coloring, or the empty string if 37 /// The terminal escape for removing test coloring, or the empty string if
33 /// this is Windows or not outputting to a terminal. 38 /// this is Windows or not outputting to a terminal.
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
71 76
72 /// Creates a [ConsoleReporter] that will run all tests in [suites]. 77 /// Creates a [ConsoleReporter] that will run all tests in [suites].
73 /// 78 ///
74 /// If [color] is `true`, this will use terminal colors; if it's `false`, it 79 /// If [color] is `true`, this will use terminal colors; if it's `false`, it
75 /// won't. 80 /// won't.
76 CompactReporter(Iterable<Suite> suites, {int concurrency, bool color: true}) 81 CompactReporter(Iterable<Suite> suites, {int concurrency, bool color: true})
77 : _multiplePaths = suites.map((suite) => suite.path).toSet().length > 1, 82 : _multiplePaths = suites.map((suite) => suite.path).toSet().length > 1,
78 _multiplePlatforms = 83 _multiplePlatforms =
79 suites.map((suite) => suite.platform).toSet().length > 1, 84 suites.map((suite) => suite.platform).toSet().length > 1,
80 _engine = new Engine(suites, concurrency: concurrency), 85 _engine = new Engine(suites, concurrency: concurrency),
86 _color = color,
81 _green = color ? '\u001b[32m' : '', 87 _green = color ? '\u001b[32m' : '',
82 _red = color ? '\u001b[31m' : '', 88 _red = color ? '\u001b[31m' : '',
83 _noColor = color ? '\u001b[0m' : '' { 89 _noColor = color ? '\u001b[0m' : '' {
84 _engine.onTestStarted.listen((liveTest) { 90 _engine.onTestStarted.listen((liveTest) {
85 if (_active.isEmpty) _progressLine(_description(liveTest)); 91 if (_active.isEmpty) _progressLine(_description(liveTest));
86 _active.add(liveTest); 92 _active.add(liveTest);
87 _printedNewline = false; 93 _printedNewline = false;
88 94
89 liveTest.onStateChange.listen((state) { 95 liveTest.onStateChange.listen((state) {
90 if (state.status != Status.complete) return; 96 if (state.status != Status.complete) return;
(...skipping 16 matching lines...) Expand all
107 _printedNewline = false; 113 _printedNewline = false;
108 }); 114 });
109 115
110 liveTest.onError.listen((error) { 116 liveTest.onError.listen((error) {
111 if (liveTest.state.status != Status.complete) return; 117 if (liveTest.state.status != Status.complete) return;
112 118
113 _progressLine(_description(liveTest)); 119 _progressLine(_description(liveTest));
114 if (!_printedNewline) print(''); 120 if (!_printedNewline) print('');
115 _printedNewline = true; 121 _printedNewline = true;
116 122
117 print(indent(error.error.toString())); 123 if (error.error is! LoadException) {
118 print(indent(terseChain(error.stackTrace).toString())); 124 print(indent(error.error.toString()));
125 print(indent(terseChain(error.stackTrace).toString()));
126 return;
127 }
128
129 print(indent(error.error.toString(color: _color)));
130
131 // Only print stack traces for load errors that come from the user's cod e.
132 if (error.error.innerError is! IOException &&
133 error.error.innerError is! IsolateSpawnException &&
134 error.error.innerError is! FormatException &&
135 error.error.innerError is! String) {
136 print(indent(terseChain(error.stackTrace).toString()));
137 }
119 }); 138 });
120 139
121 liveTest.onPrint.listen((line) { 140 liveTest.onPrint.listen((line) {
122 _progressLine(_description(liveTest)); 141 _progressLine(_description(liveTest));
123 if (!_printedNewline) print(''); 142 if (!_printedNewline) print('');
124 _printedNewline = true; 143 _printedNewline = true;
125 144
126 print(line); 145 print(line);
127 }); 146 });
128 }); 147 });
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
239 name = "${liveTest.suite.path}: $name"; 258 name = "${liveTest.suite.path}: $name";
240 } 259 }
241 260
242 if (_multiplePlatforms && liveTest.suite.platform != null) { 261 if (_multiplePlatforms && liveTest.suite.platform != null) {
243 name = "[${liveTest.suite.platform}] $name"; 262 name = "[${liveTest.suite.platform}] $name";
244 } 263 }
245 264
246 return name; 265 return name;
247 } 266 }
248 } 267 }
OLDNEW
« no previous file with comments | « lib/src/runner/loader.dart ('k') | test/runner/browser/compiler_pool_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698