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

Side by Side Diff: test/runner/expanded_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/compact_reporter_test.dart ('k') | test/runner/pub_serve_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", "expanded", "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: success 1 30 +0: success 1
32 +1: success 2 31 +1: success 2
(...skipping 19 matching lines...) Expand all
52 51
53 +0 -2: failure 3 52 +0 -2: failure 3
54 +0 -3: failure 3 53 +0 -3: failure 3
55 oh no 54 oh no
56 test.dart 8:33 main.<fn> 55 test.dart 8:33 main.<fn>
57 56
58 +0 -3: Some tests failed."""); 57 +0 -3: Some tests failed.""");
59 }); 58 });
60 59
61 test("includes the full stack trace with --verbose-trace", () { 60 test("includes the full stack trace with --verbose-trace", () {
62 return withTempDir((path) { 61 d.file("test.dart", """
63 new File(p.join(path, "test.dart")).writeAsStringSync("""
64 import 'dart:async'; 62 import 'dart:async';
65 63
66 import 'package:test/test.dart'; 64 import 'package:test/test.dart';
67 65
68 void main() { 66 void main() {
69 test("failure", () => throw "oh no"); 67 test("failure", () => throw "oh no");
70 } 68 }
71 """); 69 """).create();
72 var result = runTest(["-r", "compact", "--verbose-trace", "test.dart"], 70
73 workingDirectory: path); 71 var test = runTest(["--verbose-trace", "test.dart"], compact: true);
74 expect(result.stdout, contains("dart:isolate-patch")); 72 test.stdout.expect(consumeThrough(contains("dart:isolate-patch")));
75 }); 73 test.shouldExit(1);
76 }); 74 });
77 75
78 test("runs failing tests along with successful tests", () { 76 test("runs failing tests along with successful tests", () {
79 _expectReport(""" 77 _expectReport("""
80 test('failure 1', () => throw new TestFailure('oh no')); 78 test('failure 1', () => throw new TestFailure('oh no'));
81 test('success 1', () {}); 79 test('success 1', () {});
82 test('failure 2', () => throw new TestFailure('oh no')); 80 test('failure 2', () => throw new TestFailure('oh no'));
83 test('success 2', () {});""", 81 test('success 2', () {});""",
84 """ 82 """
85 +0: failure 1 83 +0: failure 1
(...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after
302 +0 ~1: skip 1 300 +0 ~1: skip 1
303 Skip: some reason 301 Skip: some reason
304 +0 ~1: skip 2 302 +0 ~1: skip 2
305 +0 ~2: skip 2 303 +0 ~2: skip 2
306 Skip: or another 304 Skip: or another
307 +0 ~2: All tests skipped."""); 305 +0 ~2: All tests skipped.""");
308 }); 306 });
309 }); 307 });
310 } 308 }
311 309
312 void _expectReport(String tests, String expected, {List<String> args, 310 void _expectReport(String tests, String expected) {
313 int concurrency}) {
314 if (concurrency == null) concurrency = 1;
315
316 var dart = """ 311 var dart = """
317 import 'dart:async'; 312 import 'dart:async';
318 313
319 import 'package:test/test.dart'; 314 import 'package:test/test.dart';
320 315
321 void main() { 316 void main() {
322 $tests 317 $tests
323 } 318 }
324 """; 319 """;
325 320
326 expect(withTempDir((path) { 321 d.file("test.dart", dart).create();
327 new File(p.join(path, "test.dart")).writeAsStringSync(dart); 322
328 if (args == null) args = []; 323 var test = runTest(["test.dart"]);
329 args = args.toList() 324 test.shouldExit();
330 ..add("test.dart") 325
331 ..add("--concurrency=$concurrency") 326 schedule(() async {
332 ..add("--reporter=expanded"); 327 var stdoutLines = await test.stdoutStream().toList();
333 var result = runTest(args, workingDirectory: path);
334 328
335 // Remove excess trailing whitespace and trim off timestamps. 329 // Remove excess trailing whitespace and trim off timestamps.
336 var actual = result.stdout.trim().split("\n").map((line) { 330 var actual = stdoutLines.map((line) {
337 if (line.startsWith(" ") || line.isEmpty) return line.trimRight(); 331 if (line.startsWith(" ") || line.isEmpty) return line.trimRight();
338 return line.trim().replaceFirst(new RegExp("^[0-9]{2}:[0-9]{2} "), ""); 332 return line.trim().replaceFirst(new RegExp("^[0-9]{2}:[0-9]{2} "), "");
339 }).join("\n"); 333 }).join("\n");
340 334
341 // Un-indent the expected string. 335 // Un-indent the expected string.
342 var indentation = expected.indexOf(new RegExp("[^ ]")); 336 var indentation = expected.indexOf(new RegExp("[^ ]"));
343 expected = expected.split("\n").map((line) { 337 expected = expected.split("\n").map((line) {
344 if (line.isEmpty) return line; 338 if (line.isEmpty) return line;
345 return line.substring(indentation); 339 return line.substring(indentation);
346 }).join("\n"); 340 }).join("\n");
347 341
348 expect(actual, equals(expected)); 342 expect(actual, equals(expected));
349 }), completes); 343 });
350 } 344 }
OLDNEW
« no previous file with comments | « test/runner/compact_reporter_test.dart ('k') | test/runner/pub_serve_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698