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

Side by Side Diff: lib/metatest.dart

Issue 1921533010: Support the latest version of test. (Closed) Base URL: git@github.com:dart-lang/metatest@master
Patch Set: Code review changes Created 4 years, 7 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 | « CHANGELOG.md ('k') | pubspec.yaml » ('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) 2014, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2014, 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 /// A test library for testing test libraries? We must go deeper. 5 /// A test library for testing test libraries? We must go deeper.
6 /// 6 ///
7 /// Since unit testing code tends to use a lot of global state, it can be tough 7 /// Since unit testing code tends to use a lot of global state, it can be tough
8 /// to test. This library manages it by running each test case in a child 8 /// to test. This library manages it by running each test case in a child
9 /// isolate, then reporting the results back to the parent isolate. 9 /// isolate, then reporting the results back to the parent isolate.
10 library metatest; 10 library metatest;
11 11
12 import 'dart:async'; 12 import 'dart:async';
13 13
14 // TODO(nweiz): Stop importing from src when dart-lang/test#48 is fixed. 14 // TODO(nweiz): Stop importing from src when dart-lang/test#48 is fixed.
15 import 'package:test/src/backend/declarer.dart'; 15 import 'package:test/src/backend/declarer.dart';
16 import 'package:test/src/backend/live_test.dart'; 16 import 'package:test/src/backend/live_test.dart';
17 import 'package:test/src/backend/state.dart'; 17 import 'package:test/src/backend/state.dart';
18 import 'package:test/src/runner/engine.dart'; 18 import 'package:test/src/runner/engine.dart';
19 import 'package:test/src/runner/runner_suite.dart'; 19 import 'package:test/src/runner/runner_suite.dart';
20 import 'package:test/src/runner/vm/environment.dart'; 20 import 'package:test/src/runner/plugin/environment.dart';
21 import 'package:test/test.dart'; 21 import 'package:test/test.dart';
22 22
23 /// Declares a test with the given [description] and [body]. 23 /// Declares a test with the given [description] and [body].
24 /// 24 ///
25 /// [body] corresponds to the `main` method of a test file. By default, this 25 /// [body] corresponds to the `main` method of a test file. By default, this
26 /// expects that all tests defined in [body] pass, but if [passing] is passed, 26 /// expects that all tests defined in [body] pass, but if [passing] is passed,
27 /// only tests listed there are expected to pass. 27 /// only tests listed there are expected to pass.
28 void expectTestsPass(String description, void body(), {List<String> passing, 28 void expectTestsPass(String description, void body(), {List<String> passing,
29 String testOn, Timeout timeout, skip, Map<String, dynamic> onPlatform}) { 29 String testOn, Timeout timeout, skip, Map<String, dynamic> onPlatform}) {
30 _setUpTest(description, body, (liveTests) { 30 _setUpTest(description, body, (liveTests) {
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
65 /// Sets up a test with the given [description] and [body]. After the test runs, 65 /// Sets up a test with the given [description] and [body]. After the test runs,
66 /// calls [validate] with the result map. 66 /// calls [validate] with the result map.
67 void _setUpTest(String description, void body(), 67 void _setUpTest(String description, void body(),
68 void validate(List<LiveTest> liveTests), {String testOn, Timeout timeout, 68 void validate(List<LiveTest> liveTests), {String testOn, Timeout timeout,
69 skip, Map<String, dynamic> onPlatform}) { 69 skip, Map<String, dynamic> onPlatform}) {
70 test(description, () async { 70 test(description, () async {
71 var declarer = new Declarer(); 71 var declarer = new Declarer();
72 runZoned(body, zoneValues: {#test.declarer: declarer}); 72 runZoned(body, zoneValues: {#test.declarer: declarer});
73 73
74 var engine = new Engine.withSuites([ 74 var engine = new Engine.withSuites([
75 new RunnerSuite(new VMEnvironment(), declarer.build()) 75 new RunnerSuite(new PluginEnvironment(), declarer.build())
76 ]); 76 ]);
77 for (var test in engine.liveTests) { 77 for (var test in engine.liveTests) {
78 test.onPrint.listen(print); 78 test.onPrint.listen(print);
79 } 79 }
80 await engine.run(); 80 await engine.run();
81 81
82 validate(engine.liveTests); 82 validate(engine.liveTests);
83 }, testOn: testOn, timeout: timeout, skip: skip, onPlatform: onPlatform); 83 }, testOn: testOn, timeout: timeout, skip: skip, onPlatform: onPlatform);
84 } 84 }
85 85
86 /// Returns a string description of the test run descibed by [liveTests]. 86 /// Returns a string description of the test run descibed by [liveTests].
87 String _summarizeTests(List<LiveTest> liveTests) { 87 String _summarizeTests(List<LiveTest> liveTests) {
88 var buffer = new StringBuffer(); 88 var buffer = new StringBuffer();
89 for (var liveTest in liveTests) { 89 for (var liveTest in liveTests) {
90 buffer.writeln("${liveTest.state.result}: ${liveTest.test.name}"); 90 buffer.writeln("${liveTest.state.result}: ${liveTest.test.name}");
91 for (var error in liveTest.errors) { 91 for (var error in liveTest.errors) {
92 buffer.writeln(error.error); 92 buffer.writeln(error.error);
93 if (error.stackTrace != null) buffer.writeln(error.stackTrace); 93 if (error.stackTrace != null) buffer.writeln(error.stackTrace);
94 } 94 }
95 } 95 }
96 return buffer.toString(); 96 return buffer.toString();
97 } 97 }
OLDNEW
« no previous file with comments | « CHANGELOG.md ('k') | pubspec.yaml » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698