OLD | NEW |
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.runner_suite; | 5 library test.runner.runner_suite; |
6 | 6 |
7 import 'dart:async'; | 7 import 'dart:async'; |
8 | 8 |
9 import 'package:async/async.dart'; | 9 import 'package:async/async.dart'; |
10 | 10 |
11 import '../backend/metadata.dart'; | 11 import '../backend/metadata.dart'; |
12 import '../backend/operating_system.dart'; | 12 import '../backend/operating_system.dart'; |
13 import '../backend/suite.dart'; | 13 import '../backend/suite.dart'; |
14 import '../backend/test.dart'; | 14 import '../backend/test.dart'; |
15 import '../backend/test_platform.dart'; | 15 import '../backend/test_platform.dart'; |
16 import '../utils.dart'; | 16 import '../utils.dart'; |
| 17 import 'environment.dart'; |
17 | 18 |
18 /// A suite produced and consumed by the test runner that has runner-specific | 19 /// A suite produced and consumed by the test runner that has runner-specific |
19 /// logic and lifecycle management. | 20 /// logic and lifecycle management. |
20 /// | 21 /// |
21 /// This is separated from [Suite] because the backend library (which will | 22 /// This is separated from [Suite] because the backend library (which will |
22 /// eventually become its own package) is primarily for test code itself to use, | 23 /// eventually become its own package) is primarily for test code itself to use, |
23 /// for which the [RunnerSuite] APIs don't make sense. | 24 /// for which the [RunnerSuite] APIs don't make sense. |
24 class RunnerSuite extends Suite { | 25 class RunnerSuite extends Suite { |
| 26 final Environment environment; |
| 27 |
25 /// The memoizer for running [close] exactly once. | 28 /// The memoizer for running [close] exactly once. |
26 final _closeMemo = new AsyncMemoizer(); | 29 final _closeMemo = new AsyncMemoizer(); |
27 | 30 |
28 /// The function to call when the suite is closed. | 31 /// The function to call when the suite is closed. |
29 final AsyncFunction _onClose; | 32 final AsyncFunction _onClose; |
30 | 33 |
31 RunnerSuite(Iterable<Test> tests, {String path, TestPlatform platform, | 34 RunnerSuite(this.environment, Iterable<Test> tests, {String path, |
32 OperatingSystem os, Metadata metadata, AsyncFunction onClose}) | 35 TestPlatform platform, OperatingSystem os, Metadata metadata, |
| 36 AsyncFunction onClose}) |
33 : super(tests, | 37 : super(tests, |
34 path: path, platform: platform, os: os, metadata: metadata), | 38 path: path, platform: platform, os: os, metadata: metadata), |
35 _onClose = onClose; | 39 _onClose = onClose; |
36 | 40 |
37 /// Creates a new [RunnerSuite] with the same properties as [suite]. | |
38 RunnerSuite.fromSuite(Suite suite) | |
39 : super(suite.tests, | |
40 path: suite.path, | |
41 platform: suite.platform, | |
42 os: suite.os, | |
43 metadata: suite.metadata), | |
44 _onClose = null; | |
45 | |
46 RunnerSuite change({String path, Metadata metadata, Iterable<Test> tests}) { | 41 RunnerSuite change({String path, Metadata metadata, Iterable<Test> tests}) { |
47 if (path == null) path = this.path; | 42 if (path == null) path = this.path; |
48 if (metadata == null) metadata = this.metadata; | 43 if (metadata == null) metadata = this.metadata; |
49 if (tests == null) tests = this.tests; | 44 if (tests == null) tests = this.tests; |
50 return new RunnerSuite(tests, platform: platform, os: os, path: path, | 45 return new RunnerSuite(environment, tests, platform: platform, os: os, |
51 metadata: metadata, onClose: this.close); | 46 path: path, metadata: metadata, onClose: close); |
52 } | 47 } |
53 | 48 |
54 /// Closes the suite and releases any resources associated with it. | 49 /// Closes the suite and releases any resources associated with it. |
55 Future close() { | 50 Future close() { |
56 return _closeMemo.runOnce(() async { | 51 return _closeMemo.runOnce(() async { |
57 if (_onClose != null) await _onClose(); | 52 if (_onClose != null) await _onClose(); |
58 }); | 53 }); |
59 } | 54 } |
60 } | 55 } |
OLD | NEW |