| 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'; | |
| 12 import '../backend/operating_system.dart'; | 11 import '../backend/operating_system.dart'; |
| 13 import '../backend/suite.dart'; | 12 import '../backend/suite.dart'; |
| 14 import '../backend/suite_entry.dart'; | 13 import '../backend/group.dart'; |
| 15 import '../backend/test.dart'; | 14 import '../backend/test.dart'; |
| 16 import '../backend/test_platform.dart'; | 15 import '../backend/test_platform.dart'; |
| 17 import '../utils.dart'; | 16 import '../utils.dart'; |
| 18 import 'environment.dart'; | 17 import 'environment.dart'; |
| 19 | 18 |
| 20 /// 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 |
| 21 /// logic and lifecycle management. | 20 /// logic and lifecycle management. |
| 22 /// | 21 /// |
| 23 /// This is separated from [Suite] because the backend library (which will | 22 /// This is separated from [Suite] because the backend library (which will |
| 24 /// 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, |
| 25 /// for which the [RunnerSuite] APIs don't make sense. | 24 /// for which the [RunnerSuite] APIs don't make sense. |
| 26 class RunnerSuite extends Suite { | 25 class RunnerSuite extends Suite { |
| 27 final Environment environment; | 26 final Environment environment; |
| 28 | 27 |
| 29 /// The memoizer for running [close] exactly once. | 28 /// The memoizer for running [close] exactly once. |
| 30 final _closeMemo = new AsyncMemoizer(); | 29 final _closeMemo = new AsyncMemoizer(); |
| 31 | 30 |
| 32 /// The function to call when the suite is closed. | 31 /// The function to call when the suite is closed. |
| 33 final AsyncFunction _onClose; | 32 final AsyncFunction _onClose; |
| 34 | 33 |
| 35 RunnerSuite(this.environment, Iterable<SuiteEntry> entries, {String path, | 34 RunnerSuite(this.environment, Group group, {String path, |
| 36 TestPlatform platform, OperatingSystem os, Metadata metadata, | 35 TestPlatform platform, OperatingSystem os, AsyncFunction onClose}) |
| 37 AsyncFunction onClose}) | 36 : super(group, path: path, platform: platform, os: os), |
| 38 : super(entries, | |
| 39 path: path, platform: platform, os: os, metadata: metadata), | |
| 40 _onClose = onClose; | 37 _onClose = onClose; |
| 41 | 38 |
| 42 RunnerSuite filter(bool callback(Test test)) { | 39 RunnerSuite filter(bool callback(Test test)) { |
| 43 var filtered = entries | 40 var filtered = group.filter(callback); |
| 44 .map((entry) => entry.filter(callback)) | 41 filtered ??= new Group.root([], metadata: metadata); |
| 45 .where((entry) => entry != null) | |
| 46 .toList(); | |
| 47 return new RunnerSuite(environment, filtered, | 42 return new RunnerSuite(environment, filtered, |
| 48 platform: platform, os: os, path: path, metadata: metadata); | 43 platform: platform, os: os, path: path); |
| 49 } | 44 } |
| 50 | 45 |
| 51 /// Closes the suite and releases any resources associated with it. | 46 /// Closes the suite and releases any resources associated with it. |
| 52 Future close() { | 47 Future close() { |
| 53 return _closeMemo.runOnce(() async { | 48 return _closeMemo.runOnce(() async { |
| 54 if (_onClose != null) await _onClose(); | 49 if (_onClose != null) await _onClose(); |
| 55 }); | 50 }); |
| 56 } | 51 } |
| 57 } | 52 } |
| OLD | NEW |