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

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

Issue 1056733002: Run test tearDowns and clean up temporary directories when a signal is caught. (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/engine.dart ('k') | lib/src/runner/vm/isolate_listener.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 9
10 import '../../backend/live_test.dart'; 10 import '../../backend/live_test.dart';
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
44 44
45 /// A stopwatch that tracks the duration of the full run. 45 /// A stopwatch that tracks the duration of the full run.
46 final _stopwatch = new Stopwatch(); 46 final _stopwatch = new Stopwatch();
47 47
48 /// The set of tests that have completed and been marked as passing. 48 /// The set of tests that have completed and been marked as passing.
49 final _passed = new Set<LiveTest>(); 49 final _passed = new Set<LiveTest>();
50 50
51 /// The set of tests that have completed and been marked as failing or error. 51 /// The set of tests that have completed and been marked as failing or error.
52 final _failed = new Set<LiveTest>(); 52 final _failed = new Set<LiveTest>();
53 53
54 /// Whether [close] has been called.
55 bool _closed = false;
56
54 /// The size of [_passed] last time a progress notification was printed. 57 /// The size of [_passed] last time a progress notification was printed.
55 int _lastProgressPassed; 58 int _lastProgressPassed;
56 59
57 /// The size of [_failed] last time a progress notification was printed. 60 /// The size of [_failed] last time a progress notification was printed.
58 int _lastProgressFailed; 61 int _lastProgressFailed;
59 62
60 /// The message printed for the last progress notification. 63 /// The message printed for the last progress notification.
61 String _lastProgressMessage; 64 String _lastProgressMessage;
62 65
66 // Whether a newline has been printed since the last progress line.
67 var _printedNewline = true;
68
63 /// Creates a [ConsoleReporter] that will run all tests in [suites]. 69 /// Creates a [ConsoleReporter] that will run all tests in [suites].
64 /// 70 ///
65 /// If [color] is `true`, this will use terminal colors; if it's `false`, it 71 /// If [color] is `true`, this will use terminal colors; if it's `false`, it
66 /// won't. 72 /// won't.
67 CompactReporter(Iterable<Suite> suites, {bool color: true}) 73 CompactReporter(Iterable<Suite> suites, {bool color: true})
68 : _multiplePaths = suites.map((suite) => suite.path).toSet().length > 1, 74 : _multiplePaths = suites.map((suite) => suite.path).toSet().length > 1,
69 _multiplePlatforms = 75 _multiplePlatforms =
70 suites.map((suite) => suite.platform).toSet().length > 1, 76 suites.map((suite) => suite.platform).toSet().length > 1,
71 _engine = new Engine(suites), 77 _engine = new Engine(suites),
72 _green = color ? '\u001b[32m' : '', 78 _green = color ? '\u001b[32m' : '',
73 _red = color ? '\u001b[31m' : '', 79 _red = color ? '\u001b[31m' : '',
74 _noColor = color ? '\u001b[0m' : '' { 80 _noColor = color ? '\u001b[0m' : '' {
75 // Whether a newline has been printed since the last progress line.
76 var printedNewline = false;
77 _engine.onTestStarted.listen((liveTest) { 81 _engine.onTestStarted.listen((liveTest) {
78 _progressLine(_description(liveTest)); 82 _progressLine(_description(liveTest));
83 _printedNewline = false;
84
79 liveTest.onStateChange.listen((state) { 85 liveTest.onStateChange.listen((state) {
80 if (state.status != Status.complete) return; 86 if (state.status != Status.complete) return;
81 if (state.result == Result.success) { 87 if (state.result == Result.success) {
82 _passed.add(liveTest); 88 _passed.add(liveTest);
83 } else { 89 } else {
84 _passed.remove(liveTest); 90 _passed.remove(liveTest);
85 _failed.add(liveTest); 91 _failed.add(liveTest);
86 } 92 }
87 _progressLine(_description(liveTest)); 93 _progressLine(_description(liveTest));
88 printedNewline = false; 94 _printedNewline = false;
89 }); 95 });
90 96
91 liveTest.onError.listen((error) { 97 liveTest.onError.listen((error) {
92 if (liveTest.state.status != Status.complete) return; 98 if (liveTest.state.status != Status.complete) return;
93 99
94 _progressLine(_description(liveTest)); 100 _progressLine(_description(liveTest));
95 if (!printedNewline) print(''); 101 if (!_printedNewline) print('');
96 printedNewline = true; 102 _printedNewline = true;
97 103
98 print(indent(error.error.toString())); 104 print(indent(error.error.toString()));
99 print(indent(terseChain(error.stackTrace).toString())); 105 print(indent(terseChain(error.stackTrace).toString()));
100 }); 106 });
101 107
102 liveTest.onPrint.listen((line) { 108 liveTest.onPrint.listen((line) {
103 _progressLine(_description(liveTest)); 109 _progressLine(_description(liveTest));
104 if (!printedNewline) print(''); 110 if (!_printedNewline) print('');
105 printedNewline = true; 111 _printedNewline = true;
106 112
107 print(line); 113 print(line);
108 }); 114 });
109 }); 115 });
110 } 116 }
111 117
112 /// Runs all tests in all provided suites. 118 /// Runs all tests in all provided suites.
113 /// 119 ///
114 /// This returns `true` if all tests succeed, and `false` otherwise. It will 120 /// This returns `true` if all tests succeed, and `false` otherwise. It will
115 /// only return once all tests have finished running. 121 /// only return once all tests have finished running.
116 Future<bool> run() { 122 Future<bool> run() {
117 if (_stopwatch.isRunning) { 123 if (_stopwatch.isRunning) {
118 throw new StateError("CompactReporter.run() may not be called more than " 124 throw new StateError("CompactReporter.run() may not be called more than "
119 "once."); 125 "once.");
120 } 126 }
121 127
122 if (_engine.liveTests.isEmpty) { 128 if (_engine.liveTests.isEmpty) {
123 print("No tests ran."); 129 print("No tests ran.");
124 return new Future.value(true); 130 return new Future.value(true);
125 } 131 }
126 132
127 _stopwatch.start(); 133 _stopwatch.start();
128 return _engine.run().then((success) { 134 return _engine.run().then((success) {
135 if (_closed) return false;
136
129 if (success) { 137 if (success) {
130 _progressLine("All tests passed!"); 138 _progressLine("All tests passed!");
131 print(''); 139 print('');
132 } else { 140 } else {
133 _progressLine('Some tests failed.', color: _red); 141 _progressLine('Some tests failed.', color: _red);
134 print(''); 142 print('');
135 } 143 }
136 144
137 return success; 145 return success;
138 }); 146 });
139 } 147 }
140 148
141 /// Signals that the caller is done with any test output and the reporter 149 /// Signals that the caller is done with any test output and the reporter
142 /// should release any resources it has allocated. 150 /// should release any resources it has allocated.
143 Future close() => _engine.close(); 151 Future close() {
152 if (!_printedNewline) print("");
153 _printedNewline = true;
154 _closed = true;
155 return _engine.close();
156 }
144 157
145 /// Prints a line representing the current state of the tests. 158 /// Prints a line representing the current state of the tests.
146 /// 159 ///
147 /// [message] goes after the progress report, and may be truncated to fit the 160 /// [message] goes after the progress report, and may be truncated to fit the
148 /// entire line within [_lineLength]. If [color] is passed, it's used as the 161 /// entire line within [_lineLength]. If [color] is passed, it's used as the
149 /// color for [message]. 162 /// color for [message].
150 bool _progressLine(String message, {String color}) { 163 bool _progressLine(String message, {String color}) {
151 // Print nothing if nothing has changed since the last progress line. 164 // Print nothing if nothing has changed since the last progress line.
152 if (_passed.length == _lastProgressPassed && 165 if (_passed.length == _lastProgressPassed &&
153 _failed.length == _lastProgressFailed && 166 _failed.length == _lastProgressFailed &&
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
213 name = "${liveTest.suite.path}: $name"; 226 name = "${liveTest.suite.path}: $name";
214 } 227 }
215 228
216 if (_multiplePlatforms && liveTest.suite.platform != null) { 229 if (_multiplePlatforms && liveTest.suite.platform != null) {
217 name = "[${liveTest.suite.platform}] $name"; 230 name = "[${liveTest.suite.platform}] $name";
218 } 231 }
219 232
220 return name; 233 return name;
221 } 234 }
222 } 235 }
OLDNEW
« no previous file with comments | « lib/src/runner/engine.dart ('k') | lib/src/runner/vm/isolate_listener.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698