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

Side by Side Diff: lib/metatest.dart

Issue 1246853002: Update metatest for the latest test package. (Closed) Base URL: git@github.com:dart-lang/metatest@master
Patch Set: Missing import. 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 | « 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 import 'dart:isolate'; 13 import 'dart:isolate';
14 14
15 // TODO(nweiz): Stop importing from src when dart-lang/test#48 is fixed. 15 // TODO(nweiz): Stop importing from src when dart-lang/test#48 is fixed.
16 import 'package:test/src/backend/declarer.dart'; 16 import 'package:test/src/backend/declarer.dart';
17 import 'package:test/src/backend/live_test.dart';
17 import 'package:test/src/backend/state.dart'; 18 import 'package:test/src/backend/state.dart';
18 import 'package:test/src/backend/suite.dart'; 19 import 'package:test/src/backend/suite.dart';
19 import 'package:test/src/runner/engine.dart'; 20 import 'package:test/src/runner/engine.dart';
20 import 'package:test/test.dart'; 21 import 'package:test/test.dart';
21 22
22 /// Declares a test with the given [description] and [body]. 23 /// Declares a test with the given [description] and [body].
23 /// 24 ///
24 /// [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
25 /// 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,
26 /// only tests listed there are expected to pass. 27 /// only tests listed there are expected to pass.
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
59 } 60 }
60 61
61 /// Sets up a test with the given [description] and [body]. After the test runs, 62 /// Sets up a test with the given [description] and [body]. After the test runs,
62 /// calls [validate] with the result map. 63 /// calls [validate] with the result map.
63 void _setUpTest(String description, void body(), 64 void _setUpTest(String description, void body(),
64 void validate(List<LiveTest> liveTests)) { 65 void validate(List<LiveTest> liveTests)) {
65 test(description, () async { 66 test(description, () async {
66 var declarer = new Declarer(); 67 var declarer = new Declarer();
67 runZoned(body, zoneValues: {#test.declarer: declarer}); 68 runZoned(body, zoneValues: {#test.declarer: declarer});
68 69
69 var engine = new Engine([new Suite(declarer.tests)]); 70 var engine = new Engine.withSuites([new Suite(declarer.tests)]);
70 for (var test in engine.liveTests) { 71 for (var test in engine.liveTests) {
71 test.onPrint.listen(print); 72 test.onPrint.listen(print);
72 } 73 }
73 await engine.run(); 74 await engine.run();
74 75
75 validate(engine.liveTests); 76 validate(engine.liveTests);
76 }); 77 });
77 } 78 }
78 79
79 /// Returns a string description of the test run descibed by [liveTests]. 80 /// Returns a string description of the test run descibed by [liveTests].
80 String _summarizeTests(List<LiveTest> liveTests) { 81 String _summarizeTests(List<LiveTest> liveTests) {
81 var buffer = new StringBuffer(); 82 var buffer = new StringBuffer();
82 for (var liveTest in liveTests) { 83 for (var liveTest in liveTests) {
83 buffer.writeln("${liveTest.state.result}: ${liveTest.test.name}"); 84 buffer.writeln("${liveTest.state.result}: ${liveTest.test.name}");
84 for (var error in liveTest.errors) { 85 for (var error in liveTest.errors) {
85 buffer.writeln(error.error); 86 buffer.writeln(error.error);
86 if (error.stackTrace != null) buffer.writeln(error.stackTrace); 87 if (error.stackTrace != null) buffer.writeln(error.stackTrace);
87 } 88 }
88 } 89 }
89 return buffer.toString(); 90 return buffer.toString();
90 } 91 }
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