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