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