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

Side by Side Diff: test/runner/compact_reporter_test.dart

Issue 1044953004: Gracefully handle tests that print. (Closed) Base URL: git@github.com:dart-lang/unittest@master
Patch Set: 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 | « test/runner/browser/runner_test.dart ('k') | test/runner/isolate_listener_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 @TestOn("vm") 5 @TestOn("vm")
6 6
7 import 'dart:io'; 7 import 'dart:io';
8 8
9 import 'package:path/path.dart' as p; 9 import 'package:path/path.dart' as p;
10 import 'package:unittest/src/util/io.dart'; 10 import 'package:unittest/src/util/io.dart';
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
103 test('wait', () => completer.future);""", 103 test('wait', () => completer.future);""",
104 """ 104 """
105 +0: failures 105 +0: failures
106 +0 -1: failures 106 +0 -1: failures
107 first error 107 first error
108 test.dart 10:38 main.<fn>.<fn> 108 test.dart 10:38 main.<fn>.<fn>
109 ===== asynchronous gap =========================== 109 ===== asynchronous gap ===========================
110 dart:async Future.Future.microtask 110 dart:async Future.Future.microtask
111 test.dart 10:15 main.<fn> 111 test.dart 10:15 main.<fn>
112 112
113
114 second error 113 second error
115 test.dart 11:38 main.<fn>.<fn> 114 test.dart 11:38 main.<fn>.<fn>
116 ===== asynchronous gap =========================== 115 ===== asynchronous gap ===========================
117 dart:async Future.Future.microtask 116 dart:async Future.Future.microtask
118 test.dart 11:15 main.<fn> 117 test.dart 11:15 main.<fn>
119 118
120
121 third error 119 third error
122 test.dart 12:38 main.<fn>.<fn> 120 test.dart 12:38 main.<fn>.<fn>
123 ===== asynchronous gap =========================== 121 ===== asynchronous gap ===========================
124 dart:async Future.Future.microtask 122 dart:async Future.Future.microtask
125 test.dart 12:15 main.<fn> 123 test.dart 12:15 main.<fn>
126 124
127 125
128 +0 -1: wait 126 +0 -1: wait
129 +1 -1: wait 127 +1 -1: wait
130 +1 -1: Some tests failed."""); 128 +1 -1: Some tests failed.""");
131 }); 129 });
130
131 group("print:", () {
132 test("handles multiple prints", () {
133 _expectReport("""
134 test('test', () {
135 print("one");
136 print("two");
137 print("three");
138 print("four");
139 });""",
140 """
141 +0: test
142 one
143 two
144 three
145 four
146
147 +1: test
148 +1: All tests passed!""");
149 });
150
151 test("handles a print after the test completes", () {
152 _expectReport("""
153 // This completer ensures that the test isolate isn't killed until all
154 // prints have happened.
155 var testDone = new Completer();
156 var waitStarted = new Completer();
157 test('test', () {
158 waitStarted.future.then((_) {
159 new Future(() => print("one"));
160 new Future(() => print("two"));
161 new Future(() => print("three"));
162 new Future(() => print("four"));
163 new Future(testDone.complete);
164 });
165 });
166
167 test('wait', () {
168 waitStarted.complete();
169 return testDone.future;
170 });""", """
171 +0: test
172 +1: test
173 +1: wait
174 +1: test
175 one
176 two
177 three
178 four
179
180 +2: wait
181 +2: All tests passed!""");
182 });
183
184 test("interleaves prints and errors", () {
185 _expectReport("""
186 // This completer ensures that the test isolate isn't killed until all
187 // prints have happened.
188 var completer = new Completer();
189 test('test', () {
190 scheduleMicrotask(() {
191 print("three");
192 print("four");
193 throw "second error";
194 });
195
196 scheduleMicrotask(() {
197 print("five");
198 print("six");
199 completer.complete();
200 });
201
202 print("one");
203 print("two");
204 throw "first error";
205 });
206
207 test('wait', () => completer.future);""",
208 """
209 +0: test
210 one
211 two
212
213 +0 -1: test
214 first error
215 test.dart 24:11 main.<fn>
216
217 three
218 four
219 second error
220 test.dart 13:13 main.<fn>.<fn>
221 ===== asynchronous gap ===========================
222 dart:async scheduleMicrotask
223 test.dart 10:28 main.<fn>
224
225 five
226 six
227
228 +0 -1: wait
229 +1 -1: wait
230 +1 -1: Some tests failed.""");
231 });
232 });
132 } 233 }
133 234
134 void _expectReport(String tests, String expected, {List<String> args}) { 235 void _expectReport(String tests, String expected, {List<String> args}) {
135 var dart = """ 236 var dart = """
136 import 'dart:async'; 237 import 'dart:async';
137 238
138 import 'package:unittest/unittest.dart'; 239 import 'package:unittest/unittest.dart';
139 240
140 void main() { 241 void main() {
141 $tests 242 $tests
(...skipping 16 matching lines...) Expand all
158 // Un-indent the expected string. 259 // Un-indent the expected string.
159 var indentation = expected.indexOf(new RegExp("[^ ]")); 260 var indentation = expected.indexOf(new RegExp("[^ ]"));
160 expected = expected.split("\n").map((line) { 261 expected = expected.split("\n").map((line) {
161 if (line.isEmpty) return line; 262 if (line.isEmpty) return line;
162 return line.substring(indentation); 263 return line.substring(indentation);
163 }).join("\n"); 264 }).join("\n");
164 265
165 expect(actual, equals(expected)); 266 expect(actual, equals(expected));
166 }), completes); 267 }), completes);
167 } 268 }
OLDNEW
« no previous file with comments | « test/runner/browser/runner_test.dart ('k') | test/runner/isolate_listener_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698