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

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

Issue 1263503008: Add an Environment class that's exposed through RunnerSuite. (Closed) Base URL: git@github.com:dart-lang/test@master
Patch Set: 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
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/test_platform.dart'; 14 import '../backend/test_platform.dart';
15 import '../utils.dart'; 15 import '../utils.dart';
16 import 'load_exception.dart'; 16 import 'load_exception.dart';
17 import 'runner_suite.dart'; 17 import 'runner_suite.dart';
18 import 'vm/environment.dart';
18 19
19 /// A [Suite] emitted by a [Loader] that provides a test-like interface for 20 /// A [Suite] emitted by a [Loader] that provides a test-like interface for
20 /// loading a test file. 21 /// loading a test file.
21 /// 22 ///
22 /// This is used to expose the current status of test loading to the user. It's 23 /// 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 24 /// 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 25 /// 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 26 /// 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 27 /// suite so that it can integrate well into the existing reporting interface
27 /// without too much extra logic. 28 /// without too much extra logic.
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
92 }, platform: platform); 93 }, platform: platform);
93 } 94 }
94 95
95 /// A utility constructor for a load suite that just emits [suite]. 96 /// A utility constructor for a load suite that just emits [suite].
96 factory LoadSuite.forSuite(RunnerSuite suite) { 97 factory LoadSuite.forSuite(RunnerSuite suite) {
97 return new LoadSuite("loading ${suite.path}", () => suite, 98 return new LoadSuite("loading ${suite.path}", () => suite,
98 platform: suite.platform); 99 platform: suite.platform);
99 } 100 }
100 101
101 LoadSuite._(String name, void body(), this.suite, {TestPlatform platform}) 102 LoadSuite._(String name, void body(), this.suite, {TestPlatform platform})
102 : super([ 103 : super(const VMEnvironment(), [
103 new LocalTest(name, 104 new LocalTest(name,
104 new Metadata(timeout: new Timeout(new Duration(minutes: 5))), 105 new Metadata(timeout: new Timeout(new Duration(minutes: 5))),
105 body) 106 body)
106 ], platform: platform); 107 ], platform: platform);
107 108
108 /// A constructor used by [changeSuite]. 109 /// A constructor used by [changeSuite].
109 LoadSuite._changeSuite(LoadSuite old, Future<RunnerSuite> this.suite) 110 LoadSuite._changeSuite(LoadSuite old, Future<RunnerSuite> this.suite)
110 : super(old.tests, platform: old.platform); 111 : super(const VMEnvironment(), old.tests, platform: old.platform);
111 112
112 /// Creates a new [LoadSuite] that's identical to this one, but that 113 /// Creates a new [LoadSuite] that's identical to this one, but that
113 /// transforms [suite] once it's loaded. 114 /// transforms [suite] once it's loaded.
114 /// 115 ///
115 /// If [suite] completes to `null`, [change] won't be run. 116 /// If [suite] completes to `null`, [change] won't be run.
116 LoadSuite changeSuite(RunnerSuite change(RunnerSuite suite)) { 117 LoadSuite changeSuite(RunnerSuite change(RunnerSuite suite)) {
117 return new LoadSuite._changeSuite(this, suite.then((loadedSuite) { 118 return new LoadSuite._changeSuite(this, suite.then((loadedSuite) {
118 if (loadedSuite == null) return null; 119 if (loadedSuite == null) return null;
119 return change(loadedSuite); 120 return change(loadedSuite);
120 })); 121 }));
121 } 122 }
122 123
123 /// Runs the test and returns the suite. 124 /// Runs the test and returns the suite.
124 /// 125 ///
125 /// Rather than emitting errors through a [LiveTest], this just pipes them 126 /// Rather than emitting errors through a [LiveTest], this just pipes them
126 /// through the return value. 127 /// through the return value.
127 Future<RunnerSuite> getSuite() async { 128 Future<RunnerSuite> getSuite() async {
128 var liveTest = await tests.single.load(this); 129 var liveTest = await tests.single.load(this);
129 liveTest.onPrint.listen(print); 130 liveTest.onPrint.listen(print);
130 await liveTest.run(); 131 await liveTest.run();
131 132
132 if (liveTest.errors.isEmpty) return await suite; 133 if (liveTest.errors.isEmpty) return await suite;
133 134
134 var error = liveTest.errors.first; 135 var error = liveTest.errors.first;
135 await new Future.error(error.error, error.stackTrace); 136 await new Future.error(error.error, error.stackTrace);
136 throw 'unreachable'; 137 throw 'unreachable';
137 } 138 }
138 } 139 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698