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

Side by Side Diff: test/runner/compact_reporter_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/browser/safari_test.dart ('k') | test/runner/expanded_reporter_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 'package:scheduled_test/descriptor.dart' as d;
8 8 import 'package:scheduled_test/scheduled_stream.dart';
9 import 'package:path/path.dart' as p; 9 import 'package:scheduled_test/scheduled_test.dart';
10 import 'package:test/src/util/io.dart';
11 import 'package:test/test.dart';
12 10
13 import '../io.dart'; 11 import '../io.dart';
14 12
15 void main() { 13 void main() {
14 useSandbox();
15
16 test("reports when no tests are run", () { 16 test("reports when no tests are run", () {
17 return withTempDir((path) { 17 d.file("test.dart", "void main() {}").create();
18 new File(p.join(path, "test.dart")).writeAsStringSync("void main() {}"); 18
19 var result = runTest(["-r", "compact", "test.dart"], 19 var test = runTest(["test.dart"], compact: true);
20 workingDirectory: path); 20 test.stdout.expect(consumeThrough(contains("No tests ran.")));
21 expect(result.stdout, contains("No tests ran.")); 21 test.shouldExit(0);
22 });
23 }); 22 });
24 23
25 test("runs several successful tests and reports when each completes", () { 24 test("runs several successful tests and reports when each completes", () {
26 _expectReport(""" 25 _expectReport("""
27 test('success 1', () {}); 26 test('success 1', () {});
28 test('success 2', () {}); 27 test('success 2', () {});
29 test('success 3', () {});""", 28 test('success 3', () {});""",
30 """ 29 """
31 +0: loading test.dart 30 +0: loading test.dart
32 +0: success 1 31 +0: success 1
(...skipping 27 matching lines...) Expand all
60 +0 -2: failure 3 59 +0 -2: failure 3
61 +0 -3: failure 3 60 +0 -3: failure 3
62 oh no 61 oh no
63 test.dart 8:33 main.<fn> 62 test.dart 8:33 main.<fn>
64 63
65 64
66 +0 -3: Some tests failed."""); 65 +0 -3: Some tests failed.""");
67 }); 66 });
68 67
69 test("includes the full stack trace with --verbose-trace", () { 68 test("includes the full stack trace with --verbose-trace", () {
70 return withTempDir((path) { 69 d.file("test.dart", """
71 new File(p.join(path, "test.dart")).writeAsStringSync("""
72 import 'dart:async'; 70 import 'dart:async';
73 71
74 import 'package:test/test.dart'; 72 import 'package:test/test.dart';
75 73
76 void main() { 74 void main() {
77 test("failure", () => throw "oh no"); 75 test("failure", () => throw "oh no");
78 } 76 }
79 """); 77 """).create();
80 var result = runTest(["-r", "compact", "--verbose-trace", "test.dart"], 78
81 workingDirectory: path); 79 var test = runTest(["--verbose-trace", "test.dart"], compact: true);
82 expect(result.stdout, contains("dart:isolate-patch")); 80 test.stdout.expect(consumeThrough(contains("dart:isolate-patch")));
83 }); 81 test.shouldExit(1);
84 }); 82 });
85 83
86 test("runs failing tests along with successful tests", () { 84 test("runs failing tests along with successful tests", () {
87 _expectReport(""" 85 _expectReport("""
88 test('failure 1', () => throw new TestFailure('oh no')); 86 test('failure 1', () => throw new TestFailure('oh no'));
89 test('success 1', () {}); 87 test('success 1', () {});
90 test('failure 2', () => throw new TestFailure('oh no')); 88 test('failure 2', () => throw new TestFailure('oh no'));
91 test('success 2', () {});""", 89 test('success 2', () {});""",
92 """ 90 """
93 +0: loading test.dart 91 +0: loading test.dart
(...skipping 277 matching lines...) Expand 10 before | Expand all | Expand 10 after
371 369
372 +0 ~1: skip 2 370 +0 ~1: skip 2
373 +0 ~2: skip 2 371 +0 ~2: skip 2
374 Skip: or another 372 Skip: or another
375 373
376 +0 ~2: All tests skipped."""); 374 +0 ~2: All tests skipped.""");
377 }); 375 });
378 }); 376 });
379 } 377 }
380 378
381 void _expectReport(String tests, String expected, {List<String> args, 379 void _expectReport(String tests, String expected) {
382 int concurrency}) {
383 if (concurrency == null) concurrency = 1;
384
385 var dart = """ 380 var dart = """
386 import 'dart:async'; 381 import 'dart:async';
387 382
388 import 'package:test/test.dart'; 383 import 'package:test/test.dart';
389 384
390 void main() { 385 void main() {
391 $tests 386 $tests
392 } 387 }
393 """; 388 """;
394 389
395 expect(withTempDir((path) { 390 d.file("test.dart", dart).create();
396 new File(p.join(path, "test.dart")).writeAsStringSync(dart);
397 if (args == null) args = [];
398 args = args.toList()
399 ..add("test.dart")
400 ..add("--concurrency=$concurrency")
401 ..add("--reporter=compact");
402 var result = runTest(args, workingDirectory: path);
403 391
404 // Convert CRs into newlines, remove excess trailing whitespace, and trim 392 var test = runTest(["test.dart"], compact: true);
405 // off timestamps. 393 test.shouldExit();
394
395 schedule(() async {
396 var stdoutLines = await test.stdoutStream().toList();
397
398 // Skip the first CR, remove excess trailing whitespace, and trim off
399 // timestamps.
406 var lastLine; 400 var lastLine;
407 var actual = result.stdout.trim().split(new RegExp(r"[\r\n]")).map((line) { 401 var actual = stdoutLines.skip(1).map((line) {
408 if (line.startsWith(" ") || line.isEmpty) return line.trimRight(); 402 if (line.startsWith(" ") || line.isEmpty) return line.trimRight();
409 403
410 var trimmed = line.trim() 404 var trimmed = line.trim()
411 .replaceFirst(new RegExp("^[0-9]{2}:[0-9]{2} "), ""); 405 .replaceFirst(new RegExp("^[0-9]{2}:[0-9]{2} "), "");
412 406
413 // Trim identical lines so the test isn't dependent on how fast each test 407 // Trim identical lines so the test isn't dependent on how fast each test
414 // runs. 408 // runs.
415 if (trimmed == lastLine) return null; 409 if (trimmed == lastLine) return null;
416 lastLine = trimmed; 410 lastLine = trimmed;
417 return trimmed; 411 return trimmed;
418 }).where((line) => line != null).join("\n"); 412 }).where((line) => line != null).join("\n");
419 413
420 // Un-indent the expected string. 414 // Un-indent the expected string.
421 var indentation = expected.indexOf(new RegExp("[^ ]")); 415 var indentation = expected.indexOf(new RegExp("[^ ]"));
422 expected = expected.split("\n").map((line) { 416 expected = expected.split("\n").map((line) {
423 if (line.isEmpty) return line; 417 if (line.isEmpty) return line;
424 return line.substring(indentation); 418 return line.substring(indentation);
425 }).join("\n"); 419 }).join("\n");
426 420
427 expect(actual, equals(expected)); 421 expect(actual, equals(expected));
428 }), completes); 422 });
429 } 423 }
OLDNEW
« no previous file with comments | « test/runner/browser/safari_test.dart ('k') | test/runner/expanded_reporter_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698