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

Side by Side Diff: lib/src/runner/load_suite.dart

Issue 1258163002: Split out a RunnerSuite class. (Closed) Base URL: git@github.com:dart-lang/test@master
Patch Set: Code review changes Created 5 years, 4 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 | « lib/src/runner/engine.dart ('k') | lib/src/runner/loader.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 library test.runner.load_suite; 5 library test.runner.load_suite;
6 6
7 import 'dart:async'; 7 import 'dart:async';
8 8
9 import 'package:stack_trace/stack_trace.dart'; 9 import 'package:stack_trace/stack_trace.dart';
10 10
11 import '../../test.dart'; 11 import '../../test.dart';
12 import '../backend/invoker.dart'; 12 import '../backend/invoker.dart';
13 import '../backend/metadata.dart'; 13 import '../backend/metadata.dart';
14 import '../backend/suite.dart';
15 import '../backend/test_platform.dart'; 14 import '../backend/test_platform.dart';
16 import '../utils.dart'; 15 import '../utils.dart';
17 import 'load_exception.dart'; 16 import 'load_exception.dart';
17 import 'runner_suite.dart';
18 18
19 /// A [Suite] emitted by a [Loader] that provides a test-like interface for 19 /// A [Suite] emitted by a [Loader] that provides a test-like interface for
20 /// loading a test file. 20 /// loading a test file.
21 /// 21 ///
22 /// This is used to expose the current status of test loading to the user. It's 22 /// This is used to expose the current status of test loading to the user. It's
23 /// important to provide users visibility into what's taking a long time and 23 /// important to provide users visibility into what's taking a long time and
24 /// where failures occur. And since some tests may be loaded at the same time as 24 /// where failures occur. And since some tests may be loaded at the same time as
25 /// others are run, it's useful to provide that visibility in the form of a test 25 /// others are run, it's useful to provide that visibility in the form of a test
26 /// suite so that it can integrate well into the existing reporting interface 26 /// suite so that it can integrate well into the existing reporting interface
27 /// without too much extra logic. 27 /// without too much extra logic.
28 /// 28 ///
29 /// A suite is constructed with logic necessary to produce a test suite. As with 29 /// A suite is constructed with logic necessary to produce a test suite. As with
30 /// a normal test body, this logic isn't run until [LiveTest.run] is called. The 30 /// a normal test body, this logic isn't run until [LiveTest.run] is called. The
31 /// suite itself is returned by [suite] once it's avaialble, but any errors or 31 /// suite itself is returned by [suite] once it's avaialble, but any errors or
32 /// prints will be emitted through the running [LiveTest]. 32 /// prints will be emitted through the running [LiveTest].
33 class LoadSuite extends Suite { 33 class LoadSuite extends RunnerSuite {
34 /// A future that completes to the loaded suite once the suite's test has been 34 /// A future that completes to the loaded suite once the suite's test has been
35 /// run and completed successfully. 35 /// run and completed successfully.
36 /// 36 ///
37 /// This will return `null` if the suite is unavailable for some reason (for 37 /// This will return `null` if the suite is unavailable for some reason (for
38 /// example if an error occurred while loading it). 38 /// example if an error occurred while loading it).
39 final Future<Suite> suite; 39 final Future<RunnerSuite> suite;
40 40
41 /// Creates a load suite named [name] on [platform]. 41 /// Creates a load suite named [name] on [platform].
42 /// 42 ///
43 /// [body] may return either a [Suite] or a [Future] that completes to a 43 /// [body] may return either a [RunnerSuite] or a [Future] that completes to a
44 /// [Suite]. Its return value is forwarded through [suite], although if it 44 /// [RunnerSuite]. Its return value is forwarded through [suite], although if
45 /// throws an error that will be forwarded through the suite's test. 45 /// it throws an error that will be forwarded through the suite's test.
46 /// 46 ///
47 /// If the the load test is closed before [body] is complete, it will close 47 /// If the the load test is closed before [body] is complete, it will close
48 /// the suite returned by [body] once it completes. 48 /// the suite returned by [body] once it completes.
49 factory LoadSuite(String name, body(), {TestPlatform platform}) { 49 factory LoadSuite(String name, body(), {TestPlatform platform}) {
50 var completer = new Completer.sync(); 50 var completer = new Completer.sync();
51 return new LoadSuite._(name, () { 51 return new LoadSuite._(name, () {
52 var invoker = Invoker.current; 52 var invoker = Invoker.current;
53 invoker.addOutstandingCallback(); 53 invoker.addOutstandingCallback();
54 54
55 invoke(() async { 55 invoke(() async {
(...skipping 30 matching lines...) Expand all
86 factory LoadSuite.forLoadException(LoadException exception, 86 factory LoadSuite.forLoadException(LoadException exception,
87 {StackTrace stackTrace, TestPlatform platform}) { 87 {StackTrace stackTrace, TestPlatform platform}) {
88 if (stackTrace == null) stackTrace = new Trace.current(); 88 if (stackTrace == null) stackTrace = new Trace.current();
89 89
90 return new LoadSuite("loading ${exception.path}", () { 90 return new LoadSuite("loading ${exception.path}", () {
91 return new Future.error(exception, stackTrace); 91 return new Future.error(exception, stackTrace);
92 }, platform: platform); 92 }, platform: platform);
93 } 93 }
94 94
95 /// A utility constructor for a load suite that just emits [suite]. 95 /// A utility constructor for a load suite that just emits [suite].
96 factory LoadSuite.forSuite(Suite suite) { 96 factory LoadSuite.forSuite(RunnerSuite suite) {
97 return new LoadSuite("loading ${suite.path}", () => suite, 97 return new LoadSuite("loading ${suite.path}", () => suite,
98 platform: suite.platform); 98 platform: suite.platform);
99 } 99 }
100 100
101 LoadSuite._(String name, void body(), this.suite, {TestPlatform platform}) 101 LoadSuite._(String name, void body(), this.suite, {TestPlatform platform})
102 : super([ 102 : super([
103 new LocalTest(name, 103 new LocalTest(name,
104 new Metadata(timeout: new Timeout(new Duration(minutes: 5))), 104 new Metadata(timeout: new Timeout(new Duration(minutes: 5))),
105 body) 105 body)
106 ], platform: platform); 106 ], platform: platform);
107 107
108 /// A constructor used by [changeSuite]. 108 /// A constructor used by [changeSuite].
109 LoadSuite._changeSuite(LoadSuite old, Future<Suite> this.suite) 109 LoadSuite._changeSuite(LoadSuite old, Future<RunnerSuite> this.suite)
110 : super(old.tests, platform: old.platform); 110 : super(old.tests, platform: old.platform);
111 111
112 /// Creates a new [LoadSuite] that's identical to this one, but that 112 /// Creates a new [LoadSuite] that's identical to this one, but that
113 /// transforms [suite] once it's loaded. 113 /// transforms [suite] once it's loaded.
114 /// 114 ///
115 /// If [suite] completes to `null`, [change] won't be run. 115 /// If [suite] completes to `null`, [change] won't be run.
116 LoadSuite changeSuite(Suite change(Suite suite)) { 116 LoadSuite changeSuite(RunnerSuite change(RunnerSuite suite)) {
117 return new LoadSuite._changeSuite(this, suite.then((loadedSuite) { 117 return new LoadSuite._changeSuite(this, suite.then((loadedSuite) {
118 if (loadedSuite == null) return null; 118 if (loadedSuite == null) return null;
119 return change(loadedSuite); 119 return change(loadedSuite);
120 })); 120 }));
121 } 121 }
122 122
123 /// Runs the test and returns the suite. 123 /// Runs the test and returns the suite.
124 /// 124 ///
125 /// Rather than emitting errors through a [LiveTest], this just pipes them 125 /// Rather than emitting errors through a [LiveTest], this just pipes them
126 /// through the return value. 126 /// through the return value.
127 Future<Suite> getSuite() async { 127 Future<RunnerSuite> getSuite() async {
128 var liveTest = await tests.single.load(this); 128 var liveTest = await tests.single.load(this);
129 liveTest.onPrint.listen(print); 129 liveTest.onPrint.listen(print);
130 await liveTest.run(); 130 await liveTest.run();
131 131
132 if (liveTest.errors.isEmpty) return await suite; 132 if (liveTest.errors.isEmpty) return await suite;
133 133
134 var error = liveTest.errors.first; 134 var error = liveTest.errors.first;
135 await new Future.error(error.error, error.stackTrace); 135 await new Future.error(error.error, error.stackTrace);
136 throw 'unreachable'; 136 throw 'unreachable';
137 } 137 }
138 } 138 }
OLDNEW
« no previous file with comments | « lib/src/runner/engine.dart ('k') | lib/src/runner/loader.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698