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

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

Issue 1243293002: Convert a bunch of tests to use scheduled_test's infrastructure. (Closed) Base URL: git@github.com:dart-lang/test@master
Patch Set: Code review changes Created 5 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
« no previous file with comments | « test/runner/pub_serve_test.dart ('k') | test/runner/signal_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 import 'dart:math' as math; 8 import 'dart:math' as math;
9 9
10 import 'package:path/path.dart' as p; 10 import 'package:path/path.dart' as p;
11 import 'package:scheduled_test/descriptor.dart' as d;
12 import 'package:scheduled_test/scheduled_stream.dart';
13 import 'package:scheduled_test/scheduled_test.dart';
11 import 'package:test/src/util/exit_codes.dart' as exit_codes; 14 import 'package:test/src/util/exit_codes.dart' as exit_codes;
12 import 'package:test/src/util/io.dart';
13 import 'package:test/test.dart';
14 15
15 import '../io.dart'; 16 import '../io.dart';
16 17
17 String _sandbox;
18
19 final _success = """ 18 final _success = """
20 import 'dart:async'; 19 import 'dart:async';
21 20
22 import 'package:test/test.dart'; 21 import 'package:test/test.dart';
23 22
24 void main() { 23 void main() {
25 test("success", () {}); 24 test("success", () {});
26 } 25 }
27 """; 26 """;
28 27
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
64 [compact] A single line, updated continuously. 63 [compact] A single line, updated continuously.
65 [expanded] A separate line for each update. 64 [expanded] A separate line for each update.
66 65
67 --verbose-trace Whether to emit stack traces with core library fr ames. 66 --verbose-trace Whether to emit stack traces with core library fr ames.
68 --js-trace Whether to emit raw JavaScript stack traces for b rowser tests. 67 --js-trace Whether to emit raw JavaScript stack traces for b rowser tests.
69 --[no-]color Whether to use terminal colors. 68 --[no-]color Whether to use terminal colors.
70 (auto-detected by default) 69 (auto-detected by default)
71 """; 70 """;
72 71
73 void main() { 72 void main() {
74 setUp(() { 73 useSandbox();
75 _sandbox = createTempDir();
76 });
77
78 tearDown(() {
79 new Directory(_sandbox).deleteSync(recursive: true);
80 });
81 74
82 test("prints help information", () { 75 test("prints help information", () {
83 var result = _runTest(["--help"]); 76 var test = runTest(["--help"]);
84 expect(result.stdout, equals(""" 77 expectStdoutEquals(test, """
85 Runs tests in this package. 78 Runs tests in this package.
86 79
87 $_usage""")); 80 $_usage""");
88 expect(result.exitCode, equals(exit_codes.success)); 81 test.shouldExit(0);
89 }); 82 });
90 83
91 group("fails gracefully if", () { 84 group("fails gracefully if", () {
92 test("an invalid option is passed", () { 85 test("an invalid option is passed", () {
93 var result = _runTest(["--asdf"]); 86 var test = runTest(["--asdf"]);
94 expect(result.stderr, equals(""" 87 expectStderrEquals(test, """
95 Could not find an option named "asdf". 88 Could not find an option named "asdf".
96 89
97 $_usage""")); 90 $_usage""");
98 expect(result.exitCode, equals(exit_codes.usage)); 91 test.shouldExit(exit_codes.usage);
99 }); 92 });
100 93
101 test("a non-existent file is passed", () { 94 test("a non-existent file is passed", () {
102 var result = _runTest(["file"]); 95 var test = runTest(["file"]);
103 expect(result.stdout, allOf([ 96 test.stdout.expect(containsInOrder([
104 contains('-1: loading file'), 97 '-1: loading file',
105 contains('Failed to load "file": Does not exist.') 98 'Failed to load "file": Does not exist.'
106 ])); 99 ]));
107 expect(result.exitCode, equals(1)); 100 test.shouldExit(1);
108 }); 101 });
109 102
110 test("the default directory doesn't exist", () { 103 test("the default directory doesn't exist", () {
111 var result = _runTest([]); 104 var test = runTest([]);
112 expect(result.stderr, equals(""" 105 expectStderrEquals(test, """
113 No test files were passed and the default "test/" directory doesn't exist. 106 No test files were passed and the default "test/" directory doesn't exist.
114 107
115 $_usage""")); 108 $_usage""");
116 expect(result.exitCode, equals(exit_codes.data)); 109 test.shouldExit(exit_codes.data);
117 }); 110 });
118 111
119 test("a test file fails to load", () { 112 test("a test file fails to load", () {
120 var testPath = p.join(_sandbox, "test.dart"); 113 d.file("test.dart", "invalid Dart file").create();
121 new File(testPath).writeAsStringSync("invalid Dart file"); 114 var test = runTest(["test.dart"]);
122 var result = _runTest(["test.dart"]);
123 115
124 expect(result.stdout, allOf([ 116 test.stdout.expect(containsInOrder([
125 contains('-1: loading test.dart'), 117 '-1: loading test.dart',
126 contains( 118 'Failed to load "test.dart":',
127 ' Failed to load "${p.relative(testPath, from: _sandbox)}":\n' 119 "line 1 pos 1: unexpected token 'invalid'",
128 " line 1 pos 1: unexpected token 'invalid'\n" 120 "invalid Dart file",
129 " invalid Dart file\n" 121 "^"
130 " ^\n")
131 ])); 122 ]));
132 expect(result.exitCode, equals(1)); 123 test.shouldExit(1);
133 }); 124 });
134 125
135 // This syntax error is detected lazily, and so requires some extra 126 // This syntax error is detected lazily, and so requires some extra
136 // machinery to support. 127 // machinery to support.
137 test("a test file fails to parse due to a missing semicolon", () { 128 test("a test file fails to parse due to a missing semicolon", () {
138 var testPath = p.join(_sandbox, "test.dart"); 129 d.file("test.dart", "void main() {foo}").create();
139 new File(testPath).writeAsStringSync("void main() {foo}"); 130 var test = runTest(["test.dart"]);
140 var result = _runTest(["test.dart"]);
141 131
142 expect(result.stdout, allOf([ 132 test.stdout.expect(containsInOrder([
143 contains('-1: loading test.dart'), 133 '-1: loading test.dart',
144 contains( 134 'Failed to load "test.dart":',
145 ' Failed to load "${p.relative(testPath, from: _sandbox)}":\n' 135 'line 1 pos 17: semicolon expected',
146 " line 1 pos 17: semicolon expected\n" 136 'void main() {foo}',
147 " void main() {foo}\n" 137 ' ^'
148 " ^\n")
149 ])); 138 ]));
150 expect(result.exitCode, equals(1)); 139 test.shouldExit(1);
151 }); 140 });
152 141
153 // This is slightly different from the above test because it's an error 142 // This is slightly different from the above test because it's an error
154 // that's caught first by the analyzer when it's used to parse the file. 143 // that's caught first by the analyzer when it's used to parse the file.
155 test("a test file fails to parse", () { 144 test("a test file fails to parse", () {
156 var testPath = p.join(_sandbox, "test.dart"); 145 d.file("test.dart", "@TestOn)").create();
157 new File(testPath).writeAsStringSync("@TestOn)"); 146 var test = runTest(["test.dart"]);
158 var result = _runTest(["test.dart"]);
159 147
160 expect(result.stdout, allOf([ 148 test.stdout.expect(containsInOrder([
161 contains('-1: loading test.dart'), 149 '-1: loading test.dart',
162 contains( 150 'Failed to load "test.dart":',
163 ' Failed to load "${p.relative(testPath, from: _sandbox)}":\n' 151 "line 1 pos 8: unexpected token ')'",
164 " line 1 pos 8: unexpected token ')'\n" 152 "@TestOn)",
165 " @TestOn)\n" 153 " ^"
166 " ^\n")
167 ])); 154 ]));
168 expect(result.exitCode, equals(1)); 155 test.shouldExit(1);
169 }); 156 });
170 157
171 test("an annotation's structure is invalid", () { 158 test("an annotation's structure is invalid", () {
172 var testPath = p.join(_sandbox, "test.dart"); 159 d.file("test.dart", "@TestOn()\nlibrary foo;").create();
173 new File(testPath).writeAsStringSync("@TestOn()\nlibrary foo;"); 160 var test = runTest(["test.dart"]);
174 var result = _runTest(["test.dart"]);
175 161
176 expect(result.stdout, allOf([ 162 test.stdout.expect(containsInOrder([
177 contains('-1: loading test.dart'), 163 '-1: loading test.dart',
178 contains( 164 'Failed to load "test.dart":',
179 ' Failed to load "${p.relative(testPath, from: _sandbox)}":\n' 165 "Error on line 1, column 8: TestOn takes 1 argument.",
180 " Error on line 1, column 8: TestOn takes 1 argument.\n" 166 "@TestOn()",
181 " @TestOn()\n" 167 " ^^"
182 " ^^\n")
183 ])); 168 ]));
184 expect(result.exitCode, equals(1)); 169 test.shouldExit(1);
185 }); 170 });
186 171
187 test("an annotation's contents are invalid", () { 172 test("an annotation's contents are invalid", () {
188 var testPath = p.join(_sandbox, "test.dart"); 173 d.file("test.dart", "@TestOn('zim')\nlibrary foo;").create();
189 new File(testPath).writeAsStringSync("@TestOn('zim')\nlibrary foo;"); 174 var test = runTest(["test.dart"]);
190 var result = _runTest(["test.dart"]);
191 175
192 expect(result.stdout, allOf([ 176 test.stdout.expect(containsInOrder([
193 contains('-1: loading test.dart'), 177 '-1: loading test.dart',
194 contains( 178 'Failed to load "test.dart":',
195 ' Failed to load "${p.relative(testPath, from: _sandbox)}":\n' 179 "Error on line 1, column 10: Undefined variable.",
196 " Error on line 1, column 10: Undefined variable.\n" 180 "@TestOn('zim')",
197 " @TestOn('zim')\n" 181 " ^^^"
198 " ^^^\n")
199 ])); 182 ]));
200 expect(result.exitCode, equals(1)); 183 test.shouldExit(1);
201 }); 184 });
202 185
203 test("a test file throws", () { 186 test("a test file throws", () {
204 var testPath = p.join(_sandbox, "test.dart"); 187 d.file("test.dart", "void main() => throw 'oh no';").create();
205 new File(testPath).writeAsStringSync("void main() => throw 'oh no';"); 188 var test = runTest(["test.dart"]);
206 189
207 var result = _runTest(["test.dart"]); 190 test.stdout.expect(containsInOrder([
208 expect(result.stdout, allOf([ 191 '-1: loading test.dart',
209 contains('-1: loading test.dart'), 192 'Failed to load "test.dart": oh no'
210 contains(
211 'Failed to load "${p.relative(testPath, from: _sandbox)}": oh no')
212 ])); 193 ]));
213 expect(result.exitCode, equals(1)); 194 test.shouldExit(1);
214 }); 195 });
215 196
216 test("a test file doesn't have a main defined", () { 197 test("a test file doesn't have a main defined", () {
217 var testPath = p.join(_sandbox, "test.dart"); 198 d.file("test.dart", "void foo() {}").create();
218 new File(testPath).writeAsStringSync("void foo() {}"); 199 var test = runTest(["test.dart"]);
219 200
220 var result = _runTest(["test.dart"]); 201 test.stdout.expect(containsInOrder([
221 expect(result.stdout, allOf([ 202 '-1: loading test.dart',
222 contains('-1: loading test.dart'), 203 'Failed to load "test.dart": No top-level main() function defined.'
223 contains(
224 'Failed to load "${p.relative(testPath, from: _sandbox)}": No '
225 'top-level main() function defined.')
226 ])); 204 ]));
227 expect(result.exitCode, equals(1)); 205 test.shouldExit(1);
228 }); 206 });
229 207
230 test("a test file has a non-function main", () { 208 test("a test file has a non-function main", () {
231 var testPath = p.join(_sandbox, "test.dart"); 209 d.file("test.dart", "int main;").create();
232 new File(testPath).writeAsStringSync("int main;"); 210 var test = runTest(["test.dart"]);
233 211
234 var result = _runTest(["test.dart"]); 212 test.stdout.expect(containsInOrder([
235 expect(result.stdout, allOf([ 213 '-1: loading test.dart',
236 contains('-1: loading test.dart'), 214 'Failed to load "test.dart": Top-level main getter is not a function.'
237 contains(
238 'Failed to load "${p.relative(testPath, from: _sandbox)}": '
239 'Top-level main getter is not a function.')
240 ])); 215 ]));
241 expect(result.exitCode, equals(1)); 216 test.shouldExit(1);
242 }); 217 });
243 218
244 test("a test file has a main with arguments", () { 219 test("a test file has a main with arguments", () {
245 var testPath = p.join(_sandbox, "test.dart"); 220 d.file("test.dart", "void main(arg) {}").create();
246 new File(testPath).writeAsStringSync("void main(arg) {}"); 221 var test = runTest(["test.dart"]);
247 222
248 var result = _runTest(["test.dart"]); 223 test.stdout.expect(containsInOrder([
249 expect(result.stdout, allOf([ 224 '-1: loading test.dart',
250 contains('-1: loading test.dart'), 225 'Failed to load "test.dart": Top-level main() function takes arguments.'
251 contains(
252 'Failed to load "${p.relative(testPath, from: _sandbox)}": '
253 'Top-level main() function takes arguments.')
254 ])); 226 ]));
255 expect(result.exitCode, equals(1)); 227 test.shouldExit(1);
256 }); 228 });
257 229
258 test("multiple load errors occur", () { 230 test("multiple load errors occur", () {
259 var testPath = p.join(_sandbox, "test.dart"); 231 d.file("test.dart", "invalid Dart file").create();
260 new File(testPath).writeAsStringSync("invalid Dart file"); 232 var test = runTest(["test.dart", "nonexistent.dart"]);
261 var result = _runTest(["test.dart", "nonexistent.dart"]);
262 233
263 expect(result.stdout, allOf([ 234 test.stdout.expect(containsInOrder([
264 contains('loading test.dart'), 235 'loading nonexistent.dart',
265 contains( 236 'Failed to load "nonexistent.dart": Does not exist.',
266 ' Failed to load "test.dart":\n' 237 'loading test.dart',
267 " line 1 pos 1: unexpected token 'invalid'\n" 238 'Failed to load "test.dart":',
268 " invalid Dart file\n" 239 "line 1 pos 1: unexpected token 'invalid'",
269 " ^\n"), 240 "invalid Dart file",
270 contains('loading nonexistent.dart'), 241 "^"
271 contains('Failed to load "nonexistent.dart": Does not exist.')
272 ])); 242 ]));
243 test.shouldExit(1);
273 }); 244 });
274 245
275 // TODO(nweiz): test what happens when a test file is unreadable once issue 246 // TODO(nweiz): test what happens when a test file is unreadable once issue
276 // 15078 is fixed. 247 // 15078 is fixed.
277 }); 248 });
278 249
279 group("runs successful tests", () { 250 group("runs successful tests", () {
280 test("defined in a single file", () { 251 test("defined in a single file", () {
281 new File(p.join(_sandbox, "test.dart")).writeAsStringSync(_success); 252 d.file("test.dart", _success).create();
282 var result = _runTest(["test.dart"]); 253 var test = runTest(["test.dart"]);
283 expect(result.exitCode, equals(0)); 254 test.stdout.expect(consumeThrough(contains("+1: All tests passed!")));
255 test.shouldExit(0);
284 }); 256 });
285 257
286 test("defined in a directory", () { 258 test("defined in a directory", () {
287 for (var i = 0; i < 3; i++) { 259 for (var i = 0; i < 3; i++) {
288 new File(p.join(_sandbox, "${i}_test.dart")) 260 d.file("${i}_test.dart", _success).create();
289 .writeAsStringSync(_success);
290 } 261 }
291 262
292 var result = _runTest(["."]); 263 var test = runTest(["."]);
293 expect(result.exitCode, equals(0)); 264 test.stdout.expect(consumeThrough(contains("+3: All tests passed!")));
265 test.shouldExit(0);
294 }); 266 });
295 267
296 test("defaulting to the test directory", () { 268 test("defaulting to the test directory", () {
297 new Directory(p.join(_sandbox, "test")).createSync(); 269 d.dir("test", new Iterable.generate(3, (i) {
298 for (var i = 0; i < 3; i++) { 270 return d.file("${i}_test.dart", _success);
299 new File(p.join(_sandbox, "test", "${i}_test.dart")) 271 })).create();
300 .writeAsStringSync(_success);
301 }
302 272
303 var result = _runTest([]); 273 var test = runTest([]);
304 expect(result.exitCode, equals(0)); 274 test.stdout.expect(consumeThrough(contains("+3: All tests passed!")));
275 test.shouldExit(0);
305 }); 276 });
306 277
307 test("directly", () { 278 test("directly", () {
308 new File(p.join(_sandbox, "test.dart")).writeAsStringSync(_success); 279 d.file("test.dart", _success).create();
309 var result = _runDart([ 280 var test = runDart([
310 "--package-root=${p.join(packageDir, 'packages')}", 281 "--package-root=${p.join(packageDir, 'packages')}",
311 "test.dart" 282 "test.dart"
312 ]); 283 ]);
313 expect(result.stdout, contains("All tests passed!")); 284
314 expect(result.exitCode, equals(0)); 285 test.stdout.expect(consumeThrough(contains("All tests passed!")));
286 test.shouldExit(0);
315 }); 287 });
316 288
317 // Regression test; this broke in 0.12.0-beta.9. 289 // Regression test; this broke in 0.12.0-beta.9.
318 test("on a file in a subdirectory", () { 290 test("on a file in a subdirectory", () {
319 new Directory(p.join(_sandbox, "dir")).createSync(); 291 d.dir("dir", [d.file("test.dart", _success)]).create();
320 new File(p.join(_sandbox, "dir", "test.dart")) 292
321 .writeAsStringSync(_success); 293 var test = runTest(["dir/test.dart"]);
322 var result = _runTest(["dir/test.dart"]); 294 test.stdout.expect(consumeThrough(contains("+1: All tests passed!")));
323 expect(result.exitCode, equals(0)); 295 test.shouldExit(0);
324 }); 296 });
325 }); 297 });
326 298
327 group("runs failing tests", () { 299 group("runs failing tests", () {
328 test("defined in a single file", () { 300 test("defined in a single file", () {
329 new File(p.join(_sandbox, "test.dart")).writeAsStringSync(_failure); 301 d.file("test.dart", _failure).create();
330 var result = _runTest(["test.dart"]); 302
331 expect(result.exitCode, equals(1)); 303 var test = runTest(["test.dart"]);
304 test.stdout.expect(consumeThrough(contains("-1: Some tests failed.")));
305 test.shouldExit(1);
332 }); 306 });
333 307
334 test("defined in a directory", () { 308 test("defined in a directory", () {
335 for (var i = 0; i < 3; i++) { 309 for (var i = 0; i < 3; i++) {
336 new File(p.join(_sandbox, "${i}_test.dart")) 310 d.file("${i}_test.dart", _failure).create();
337 .writeAsStringSync(_failure);
338 } 311 }
339 312
340 var result = _runTest(["."]); 313 var test = runTest(["."]);
341 expect(result.exitCode, equals(1)); 314 test.stdout.expect(consumeThrough(contains("-3: Some tests failed.")));
315 test.shouldExit(1);
342 }); 316 });
343 317
344 test("defaulting to the test directory", () { 318 test("defaulting to the test directory", () {
345 new Directory(p.join(_sandbox, "test")).createSync(); 319 d.dir("test", new Iterable.generate(3, (i) {
346 for (var i = 0; i < 3; i++) { 320 return d.file("${i}_test.dart", _failure);
347 new File(p.join(_sandbox, "test", "${i}_test.dart")) 321 })).create();
348 .writeAsStringSync(_failure);
349 }
350 322
351 var result = _runTest([]); 323 var test = runTest([]);
352 expect(result.exitCode, equals(1)); 324 test.stdout.expect(consumeThrough(contains("-3: Some tests failed.")));
325 test.shouldExit(1);
353 }); 326 });
354 327
355 test("directly", () { 328 test("directly", () {
356 new File(p.join(_sandbox, "test.dart")).writeAsStringSync(_failure); 329 d.file("test.dart", _failure).create();
357 var result = _runDart([ 330 var test = runDart([
358 "--package-root=${p.join(packageDir, 'packages')}", 331 "--package-root=${p.join(packageDir, 'packages')}",
359 "test.dart" 332 "test.dart"
360 ]); 333 ]);
361 expect(result.stdout, contains("Some tests failed.")); 334 test.stdout.expect(consumeThrough(contains("Some tests failed.")));
362 expect(result.exitCode, isNot(equals(0))); 335 test.shouldExit(255);
363 }); 336 });
364 }); 337 });
365 338
366 test("runs tests even when a file fails to load", () { 339 test("runs tests even when a file fails to load", () {
367 new File(p.join(_sandbox, "test.dart")).writeAsStringSync(_success); 340 d.file("test.dart", _success).create();
368 var result = _runTest(["test.dart", "nonexistent.dart"]); 341
369 expect(result.stdout, contains("+1 -1: Some tests failed.")); 342 var test = runTest(["test.dart", "nonexistent.dart"]);
370 expect(result.exitCode, equals(1)); 343 test.stdout.expect(consumeThrough(contains("+1 -1: Some tests failed.")));
344 test.shouldExit(1);
371 }); 345 });
372 346
373 test("respects top-level @Timeout declarations", () { 347 test("respects top-level @Timeout declarations", () {
374 new File(p.join(_sandbox, "test.dart")).writeAsStringSync(''' 348 d.file("test.dart", '''
375 @Timeout(const Duration(seconds: 0)) 349 @Timeout(const Duration(seconds: 0))
376 350
377 import 'dart:async'; 351 import 'dart:async';
378 352
379 import 'package:test/test.dart'; 353 import 'package:test/test.dart';
380 354
381 void main() { 355 void main() {
382 test("timeout", () {}); 356 test("timeout", () {});
383 } 357 }
384 '''); 358 ''').create();
385 359
386 var result = _runTest(["test.dart"]); 360 var test = runTest(["test.dart"]);
387 expect(result.stdout, contains("Test timed out after 0 seconds.")); 361 test.stdout.expect(containsInOrder([
388 expect(result.stdout, contains("-1: Some tests failed.")); 362 "Test timed out after 0 seconds.",
363 "-1: Some tests failed."
364 ]));
365 test.shouldExit(1);
389 }); 366 });
390 367
391 test("respects top-level @Skip declarations", () { 368 test("respects top-level @Skip declarations", () {
392 new File(p.join(_sandbox, "test.dart")).writeAsStringSync(''' 369 d.file("test.dart", '''
393 @Skip() 370 @Skip()
394 371
395 import 'dart:async'; 372 import 'dart:async';
396 373
397 import 'package:test/test.dart'; 374 import 'package:test/test.dart';
398 375
399 void main() { 376 void main() {
400 test("fail", () => throw 'oh no'); 377 test("fail", () => throw 'oh no');
401 } 378 }
402 '''); 379 ''').create();
403 380
404 var result = _runTest(["test.dart"]); 381 var test = runTest(["test.dart"]);
405 expect(result.stdout, contains("+0 ~1: All tests skipped.")); 382 test.stdout.expect(consumeThrough(contains("+0 ~1: All tests skipped.")));
383 test.shouldExit(0);
406 }); 384 });
407 385
408 group("with onPlatform", () { 386 group("with onPlatform", () {
409 test("respects matching Skips", () { 387 test("respects matching Skips", () {
410 new File(p.join(_sandbox, "test.dart")).writeAsStringSync(''' 388 d.file("test.dart", '''
411 import 'dart:async'; 389 import 'dart:async';
412 390
413 import 'package:test/test.dart'; 391 import 'package:test/test.dart';
414 392
415 void main() { 393 void main() {
416 test("fail", () => throw 'oh no', onPlatform: {"vm": new Skip()}); 394 test("fail", () => throw 'oh no', onPlatform: {"vm": new Skip()});
417 } 395 }
418 '''); 396 ''').create();
419 397
420 var result = _runTest(["test.dart"]); 398 var test = runTest(["test.dart"]);
421 expect(result.stdout, contains("+0 ~1: All tests skipped.")); 399 test.stdout.expect(consumeThrough(contains("+0 ~1: All tests skipped.")));
400 test.shouldExit(0);
422 }); 401 });
423 402
424 test("ignores non-matching Skips", () { 403 test("ignores non-matching Skips", () {
425 new File(p.join(_sandbox, "test.dart")).writeAsStringSync(''' 404 d.file("test.dart", '''
426 import 'dart:async'; 405 import 'dart:async';
427 406
428 import 'package:test/test.dart'; 407 import 'package:test/test.dart';
429 408
430 void main() { 409 void main() {
431 test("success", () {}, onPlatform: {"chrome": new Skip()}); 410 test("success", () {}, onPlatform: {"chrome": new Skip()});
432 } 411 }
433 '''); 412 ''').create();
434 413
435 var result = _runTest(["test.dart"]); 414 var test = runTest(["test.dart"]);
436 expect(result.stdout, contains("+1: All tests passed!")); 415 test.stdout.expect(consumeThrough(contains("+1: All tests passed!")));
416 test.shouldExit(0);
437 }); 417 });
438 418
439 test("respects matching Timeouts", () { 419 test("respects matching Timeouts", () {
440 new File(p.join(_sandbox, "test.dart")).writeAsStringSync(''' 420 d.file("test.dart", '''
441 import 'dart:async'; 421 import 'dart:async';
442 422
443 import 'package:test/test.dart'; 423 import 'package:test/test.dart';
444 424
445 void main() { 425 void main() {
446 test("fail", () => throw 'oh no', onPlatform: { 426 test("fail", () => throw 'oh no', onPlatform: {
447 "vm": new Timeout(new Duration(seconds: 0)) 427 "vm": new Timeout(new Duration(seconds: 0))
448 }); 428 });
449 } 429 }
450 '''); 430 ''').create();
451 431
452 var result = _runTest(["test.dart"]); 432 var test = runTest(["test.dart"]);
453 expect(result.stdout, contains("Test timed out after 0 seconds.")); 433 test.stdout.expect(containsInOrder([
454 expect(result.stdout, contains("-1: Some tests failed.")); 434 "Test timed out after 0 seconds.",
435 "-1: Some tests failed."
436 ]));
437 test.shouldExit(1);
455 }); 438 });
456 439
457 test("ignores non-matching Timeouts", () { 440 test("ignores non-matching Timeouts", () {
458 new File(p.join(_sandbox, "test.dart")).writeAsStringSync(''' 441 d.file("test.dart", '''
459 import 'dart:async'; 442 import 'dart:async';
460 443
461 import 'package:test/test.dart'; 444 import 'package:test/test.dart';
462 445
463 void main() { 446 void main() {
464 test("success", () {}, onPlatform: { 447 test("success", () {}, onPlatform: {
465 "chrome": new Timeout(new Duration(seconds: 0)) 448 "chrome": new Timeout(new Duration(seconds: 0))
466 }); 449 });
467 } 450 }
468 '''); 451 ''').create();
469 452
470 var result = _runTest(["test.dart"]); 453 var test = runTest(["test.dart"]);
471 expect(result.stdout, contains("+1: All tests passed!")); 454 test.stdout.expect(consumeThrough(contains("+1: All tests passed!")));
455 test.shouldExit(0);
472 }); 456 });
473 457
474 test("applies matching platforms in order", () { 458 test("applies matching platforms in order", () {
475 new File(p.join(_sandbox, "test.dart")).writeAsStringSync(''' 459 d.file("test.dart", '''
476 import 'dart:async'; 460 import 'dart:async';
477 461
478 import 'package:test/test.dart'; 462 import 'package:test/test.dart';
479 463
480 void main() { 464 void main() {
481 test("success", () {}, onPlatform: { 465 test("success", () {}, onPlatform: {
482 "vm": new Skip("first"), 466 "vm": new Skip("first"),
483 "vm || windows": new Skip("second"), 467 "vm || windows": new Skip("second"),
484 "vm || linux": new Skip("third"), 468 "vm || linux": new Skip("third"),
485 "vm || mac-os": new Skip("fourth"), 469 "vm || mac-os": new Skip("fourth"),
486 "vm || android": new Skip("fifth") 470 "vm || android": new Skip("fifth")
487 }); 471 });
488 } 472 }
489 '''); 473 ''').create();
490 474
491 var result = _runTest(["test.dart"]); 475 var test = runTest(["test.dart"]);
492 expect(result.stdout, contains("Skip: fifth")); 476 test.stdout.fork().expect(never(contains("Skip: first")));
493 expect(result.stdout, isNot(anyOf([ 477 test.stdout.fork().expect(never(contains("Skip: second")));
494 contains("Skip: first"), 478 test.stdout.fork().expect(never(contains("Skip: third")));
495 contains("Skip: second"), 479 test.stdout.fork().expect(never(contains("Skip: fourth")));
496 contains("Skip: third"), 480 test.stdout.expect(consumeThrough(contains("Skip: fifth")));
497 contains("Skip: fourth") 481 test.shouldExit(0);
498 ])));
499 }); 482 });
500 }); 483 });
501 484
502 group("with an @OnPlatform annotation", () { 485 group("with an @OnPlatform annotation", () {
503 test("respects matching Skips", () { 486 test("respects matching Skips", () {
504 new File(p.join(_sandbox, "test.dart")).writeAsStringSync(''' 487 d.file("test.dart", '''
505 @OnPlatform(const {"vm": const Skip()}) 488 @OnPlatform(const {"vm": const Skip()})
506 489
507 import 'dart:async'; 490 import 'dart:async';
508 491
509 import 'package:test/test.dart'; 492 import 'package:test/test.dart';
510 493
511 void main() { 494 void main() {
512 test("fail", () => throw 'oh no'); 495 test("fail", () => throw 'oh no');
513 } 496 }
514 '''); 497 ''').create();
515 498
516 var result = _runTest(["test.dart"]); 499 var test = runTest(["test.dart"]);
517 expect(result.stdout, contains("+0 ~1: All tests skipped.")); 500 test.stdout.expect(consumeThrough(contains("+0 ~1: All tests skipped.")));
501 test.shouldExit(0);
518 }); 502 });
519 503
520 test("ignores non-matching Skips", () { 504 test("ignores non-matching Skips", () {
521 new File(p.join(_sandbox, "test.dart")).writeAsStringSync(''' 505 d.file("test.dart", '''
522 @OnPlatform(const {"chrome": const Skip()}) 506 @OnPlatform(const {"chrome": const Skip()})
523 507
524 import 'dart:async'; 508 import 'dart:async';
525 509
526 import 'package:test/test.dart'; 510 import 'package:test/test.dart';
527 511
528 void main() { 512 void main() {
529 test("success", () {}); 513 test("success", () {});
530 } 514 }
531 '''); 515 ''').create();
532 516
533 var result = _runTest(["test.dart"]); 517 var test = runTest(["test.dart"]);
534 expect(result.stdout, contains("+1: All tests passed!")); 518 test.stdout.expect(consumeThrough(contains("+1: All tests passed!")));
519 test.shouldExit(0);
535 }); 520 });
536 521
537 test("respects matching Timeouts", () { 522 test("respects matching Timeouts", () {
538 new File(p.join(_sandbox, "test.dart")).writeAsStringSync(''' 523 d.file("test.dart", '''
539 @OnPlatform(const { 524 @OnPlatform(const {
540 "vm": const Timeout(const Duration(seconds: 0)) 525 "vm": const Timeout(const Duration(seconds: 0))
541 }) 526 })
542 527
543 import 'dart:async'; 528 import 'dart:async';
544 529
545 import 'package:test/test.dart'; 530 import 'package:test/test.dart';
546 531
547 void main() { 532 void main() {
548 test("fail", () => throw 'oh no'); 533 test("fail", () => throw 'oh no');
549 } 534 }
550 '''); 535 ''').create();
551 536
552 var result = _runTest(["test.dart"]); 537 var test = runTest(["test.dart"]);
553 expect(result.stdout, contains("Test timed out after 0 seconds.")); 538 test.stdout.expect(containsInOrder([
554 expect(result.stdout, contains("-1: Some tests failed.")); 539 "Test timed out after 0 seconds.",
540 "-1: Some tests failed."
541 ]));
542 test.shouldExit(1);
555 }); 543 });
556 544
557 test("ignores non-matching Timeouts", () { 545 test("ignores non-matching Timeouts", () {
558 new File(p.join(_sandbox, "test.dart")).writeAsStringSync(''' 546 d.file("test.dart", '''
559 @OnPlatform(const { 547 @OnPlatform(const {
560 "chrome": const Timeout(const Duration(seconds: 0)) 548 "chrome": const Timeout(const Duration(seconds: 0))
561 }) 549 })
562 550
563 import 'dart:async'; 551 import 'dart:async';
564 552
565 import 'package:test/test.dart'; 553 import 'package:test/test.dart';
566 554
567 void main() { 555 void main() {
568 test("success", () {}); 556 test("success", () {});
569 } 557 }
570 '''); 558 ''').create();
571 559
572 var result = _runTest(["test.dart"]); 560 var test = runTest(["test.dart"]);
573 expect(result.stdout, contains("+1: All tests passed!")); 561 test.stdout.expect(consumeThrough(contains("+1: All tests passed!")));
562 test.shouldExit(0);
574 }); 563 });
575 }); 564 });
576 565
577 group("flags:", () { 566 group("flags:", () {
578 test("with the --color flag, uses colors", () { 567 test("with the --color flag, uses colors", () {
579 new File(p.join(_sandbox, "test.dart")).writeAsStringSync(_failure); 568 d.file("test.dart", _failure).create();
580 var result = _runTest(["--color", "test.dart"]); 569 var test = runTest(["--color", "test.dart"]);
581 // This is the color code for red. 570 // This is the color code for red.
582 expect(result.stdout, contains("\u001b[31m")); 571 test.stdout.expect(consumeThrough(contains("\u001b[31m")));
572 test.shouldExit();
583 }); 573 });
584 574
585 group("with the --name flag,", () { 575 group("with the --name flag,", () {
586 test("selects tests with matching names", () { 576 test("selects tests with matching names", () {
587 new File(p.join(_sandbox, "test.dart")).writeAsStringSync(""" 577 d.file("test.dart", """
588 import 'dart:async'; 578 import 'dart:async';
589 579
590 import 'package:test/test.dart'; 580 import 'package:test/test.dart';
591 581
592 void main() { 582 void main() {
593 test("selected 1", () {}); 583 test("selected 1", () {});
594 test("nope", () => throw new TestFailure("oh no")); 584 test("nope", () => throw new TestFailure("oh no"));
595 test("selected 2", () {}); 585 test("selected 2", () {});
596 } 586 }
597 """); 587 """).create();
598 588
599 var result = _runTest(["--name", "selected", "test.dart"]); 589 var test = runTest(["--name", "selected", "test.dart"]);
600 expect(result.stdout, contains("+2: All tests passed!")); 590 test.stdout.expect(consumeThrough(contains("+2: All tests passed!")));
601 expect(result.exitCode, equals(0)); 591 test.shouldExit(0);
602 }); 592 });
603 593
604 test("supports RegExp syntax", () { 594 test("supports RegExp syntax", () {
605 new File(p.join(_sandbox, "test.dart")).writeAsStringSync(""" 595 d.file("test.dart", """
606 import 'dart:async'; 596 import 'dart:async';
607 597
608 import 'package:test/test.dart'; 598 import 'package:test/test.dart';
609 599
610 void main() { 600 void main() {
611 test("test 1", () {}); 601 test("test 1", () {});
612 test("test 2", () => throw new TestFailure("oh no")); 602 test("test 2", () => throw new TestFailure("oh no"));
613 test("test 3", () {}); 603 test("test 3", () {});
614 } 604 }
615 """); 605 """).create();
616 606
617 var result = _runTest(["--name", "test [13]", "test.dart"]); 607 var test = runTest(["--name", "test [13]", "test.dart"]);
618 expect(result.stdout, contains("+2: All tests passed!")); 608 test.stdout.expect(consumeThrough(contains("+2: All tests passed!")));
619 expect(result.exitCode, equals(0)); 609 test.shouldExit(0);
620 }); 610 });
621 611
622 test("produces an error when no tests match", () { 612 test("produces an error when no tests match", () {
623 new File(p.join(_sandbox, "test.dart")).writeAsStringSync(_success); 613 d.file("test.dart", _success).create();
624 614
625 var result = _runTest(["--name", "no match", "test.dart"]); 615 var test = runTest(["--name", "no match", "test.dart"]);
626 expect(result.stderr, 616 test.stderr.expect(consumeThrough(
627 contains('No tests match regular expression "no match".')); 617 contains('No tests match regular expression "no match".')));
628 expect(result.exitCode, equals(exit_codes.data)); 618 test.shouldExit(exit_codes.data);
629 }); 619 });
630 620
631 test("doesn't filter out load exceptions", () { 621 test("doesn't filter out load exceptions", () {
632 var result = _runTest(["--name", "name", "file"]); 622 var test = runTest(["--name", "name", "file"]);
633 expect(result.stdout, allOf([ 623 test.stdout.expect(containsInOrder([
634 contains('-1: loading file'), 624 '-1: loading file',
635 contains('Failed to load "file": Does not exist.') 625 ' Failed to load "file": Does not exist.'
636 ])); 626 ]));
637 expect(result.exitCode, equals(1)); 627 test.shouldExit(1);
638 }); 628 });
639 }); 629 });
640 630
641 group("with the --plain-name flag,", () { 631 group("with the --plain-name flag,", () {
642 test("selects tests with matching names", () { 632 test("selects tests with matching names", () {
643 new File(p.join(_sandbox, "test.dart")).writeAsStringSync(""" 633 d.file("test.dart", """
644 import 'dart:async'; 634 import 'dart:async';
645 635
646 import 'package:test/test.dart'; 636 import 'package:test/test.dart';
647 637
648 void main() { 638 void main() {
649 test("selected 1", () {}); 639 test("selected 1", () {});
650 test("nope", () => throw new TestFailure("oh no")); 640 test("nope", () => throw new TestFailure("oh no"));
651 test("selected 2", () {}); 641 test("selected 2", () {});
652 } 642 }
653 """); 643 """).create();
654 644
655 var result = _runTest(["--plain-name", "selected", "test.dart"]); 645 var test = runTest(["--plain-name", "selected", "test.dart"]);
656 expect(result.stdout, contains("+2: All tests passed!")); 646 test.stdout.expect(consumeThrough(contains("+2: All tests passed!")));
657 expect(result.exitCode, equals(0)); 647 test.shouldExit(0);
658 }); 648 });
659 649
660 test("doesn't support RegExp syntax", () { 650 test("doesn't support RegExp syntax", () {
661 new File(p.join(_sandbox, "test.dart")).writeAsStringSync(""" 651 d.file("test.dart", """
662 import 'dart:async'; 652 import 'dart:async';
663 653
664 import 'package:test/test.dart'; 654 import 'package:test/test.dart';
665 655
666 void main() { 656 void main() {
667 test("test 1", () => throw new TestFailure("oh no")); 657 test("test 1", () => throw new TestFailure("oh no"));
668 test("test 2", () => throw new TestFailure("oh no")); 658 test("test 2", () => throw new TestFailure("oh no"));
669 test("test [12]", () {}); 659 test("test [12]", () {});
670 } 660 }
671 """); 661 """).create();
672 662
673 var result = _runTest(["--plain-name", "test [12]", "test.dart"]); 663 var test = runTest(["--plain-name", "test [12]", "test.dart"]);
674 expect(result.stdout, contains("+1: All tests passed!")); 664 test.stdout.expect(consumeThrough(contains("+1: All tests passed!")));
675 expect(result.exitCode, equals(0)); 665 test.shouldExit(0);
676 }); 666 });
677 667
678 test("produces an error when no tests match", () { 668 test("produces an error when no tests match", () {
679 new File(p.join(_sandbox, "test.dart")).writeAsStringSync(_success); 669 d.file("test.dart", _success).create();
680 670
681 var result = _runTest(["--plain-name", "no match", "test.dart"]); 671 var test = runTest(["--plain-name", "no match", "test.dart"]);
682 expect(result.stderr, 672 test.stderr.expect(
683 contains('No tests match "no match".')); 673 consumeThrough(contains('No tests match "no match".')));
684 expect(result.exitCode, equals(exit_codes.data)); 674 test.shouldExit(exit_codes.data);
685 }); 675 });
686 }); 676 });
687 }); 677 });
688 } 678 }
689
690 ProcessResult _runTest(List<String> args) =>
691 runTest(args, workingDirectory: _sandbox);
692
693 ProcessResult _runDart(List<String> args) =>
694 runDart(args, workingDirectory: _sandbox);
OLDNEW
« no previous file with comments | « test/runner/pub_serve_test.dart ('k') | test/runner/signal_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698