Chromium Code Reviews| 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.backend.suite; | 5 library test.backend.suite; |
| 6 | 6 |
| 7 import 'dart:async'; | 7 import 'dart:async'; |
|
kevmoo
2015/07/28 01:48:00
unused
nweiz
2015/07/28 20:01:21
Done.
| |
| 8 import 'dart:collection'; | 8 import 'dart:collection'; |
| 9 | 9 |
| 10 import '../util/async_thunk.dart'; | 10 import '../util/async_thunk.dart'; |
|
kevmoo
2015/07/28 01:47:59
unused
nweiz
2015/07/28 20:01:21
Done.
| |
| 11 import '../utils.dart'; | 11 import '../utils.dart'; |
|
kevmoo
2015/07/28 01:47:59
unused
nweiz
2015/07/28 20:01:21
Done.
| |
| 12 import 'metadata.dart'; | 12 import 'metadata.dart'; |
| 13 import 'operating_system.dart'; | 13 import 'operating_system.dart'; |
| 14 import 'test.dart'; | 14 import 'test.dart'; |
| 15 import 'test_platform.dart'; | 15 import 'test_platform.dart'; |
| 16 | 16 |
| 17 /// A test suite. | 17 /// A test suite. |
| 18 /// | 18 /// |
| 19 /// A test suite is a set of tests that are intended to be run together and that | 19 /// A test suite is a set of tests that are intended to be run together and that |
| 20 /// share default configuration. | 20 /// share default configuration. |
| 21 class Suite { | 21 class Suite { |
| 22 /// The platform on which the suite is running, or `null` if that platform is | 22 /// The platform on which the suite is running, or `null` if that platform is |
| 23 /// unknown. | 23 /// unknown. |
| 24 final TestPlatform platform; | 24 final TestPlatform platform; |
| 25 | 25 |
| 26 /// The operating system on which the suite is running, or `null` if that | 26 /// The operating system on which the suite is running, or `null` if that |
| 27 /// operating system is unknown. | 27 /// operating system is unknown. |
| 28 /// | 28 /// |
| 29 /// This will always be `null` if [platform] is `null`. | 29 /// This will always be `null` if [platform] is `null`. |
| 30 final OperatingSystem os; | 30 final OperatingSystem os; |
| 31 | 31 |
| 32 /// The path to the Dart test suite, or `null` if that path is unknown. | 32 /// The path to the Dart test suite, or `null` if that path is unknown. |
| 33 final String path; | 33 final String path; |
| 34 | 34 |
| 35 /// The metadata associated with this test suite. | 35 /// The metadata associated with this test suite. |
| 36 final Metadata metadata; | 36 final Metadata metadata; |
| 37 | 37 |
| 38 /// The thunk for running [close] exactly once. | |
| 39 final _closeThunk = new AsyncThunk(); | |
| 40 | |
| 41 /// The function to call when the suite is closed. | |
| 42 final AsyncFunction _onClose; | |
| 43 | |
| 44 /// The tests in the test suite. | 38 /// The tests in the test suite. |
| 45 final List<Test> tests; | 39 final List<Test> tests; |
| 46 | 40 |
| 47 /// Creates a new suite containing [tests]. | 41 /// Creates a new suite containing [tests]. |
| 48 /// | 42 /// |
| 49 /// If [platform] and/or [os] are passed, [tests] and [metadata] are filtered | 43 /// If [platform] and/or [os] are passed, [tests] and [metadata] are filtered |
| 50 /// to match that platform information. | 44 /// to match that platform information. |
| 51 /// | 45 /// |
| 52 /// If [os] is passed without [platform], throws an [ArgumentError]. | 46 /// If [os] is passed without [platform], throws an [ArgumentError]. |
| 53 Suite(Iterable<Test> tests, {this.path, TestPlatform platform, | 47 Suite(Iterable<Test> tests, {this.path, TestPlatform platform, |
| 54 OperatingSystem os, Metadata metadata, AsyncFunction onClose}) | 48 OperatingSystem os, Metadata metadata}) |
| 55 : platform = platform, | 49 : platform = platform, |
| 56 os = os, | 50 os = os, |
| 57 metadata = _filterMetadata(metadata, platform, os), | 51 metadata = _filterMetadata(metadata, platform, os), |
| 58 _onClose = onClose, | |
| 59 tests = new UnmodifiableListView<Test>( | 52 tests = new UnmodifiableListView<Test>( |
| 60 _filterTests(tests, platform, os)); | 53 _filterTests(tests, platform, os)); |
| 61 | 54 |
| 62 /// Returns [metadata] filtered according to [platform] and [os]. | 55 /// Returns [metadata] filtered according to [platform] and [os]. |
| 63 /// | 56 /// |
| 64 /// Gracefully handles either [metadata] or [platform] being null. | 57 /// Gracefully handles either [metadata] or [platform] being null. |
| 65 static Metadata _filterMetadata(Metadata metadata, TestPlatform platform, | 58 static Metadata _filterMetadata(Metadata metadata, TestPlatform platform, |
| 66 OperatingSystem os) { | 59 OperatingSystem os) { |
| 67 if (platform == null && os != null) { | 60 if (platform == null && os != null) { |
| 68 throw new ArgumentError.value(null, "os", | 61 throw new ArgumentError.value(null, "os", |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 90 | 83 |
| 91 /// Returns a new suite with the given fields updated. | 84 /// Returns a new suite with the given fields updated. |
| 92 /// | 85 /// |
| 93 /// In the new suite, [metadata] and [tests] will be filtered according to | 86 /// In the new suite, [metadata] and [tests] will be filtered according to |
| 94 /// [platform] and [os]. | 87 /// [platform] and [os]. |
| 95 Suite change({String path, Metadata metadata, Iterable<Test> tests}) { | 88 Suite change({String path, Metadata metadata, Iterable<Test> tests}) { |
| 96 if (path == null) path = this.path; | 89 if (path == null) path = this.path; |
| 97 if (metadata == null) metadata = this.metadata; | 90 if (metadata == null) metadata = this.metadata; |
| 98 if (tests == null) tests = this.tests; | 91 if (tests == null) tests = this.tests; |
| 99 return new Suite(tests, platform: platform, os: os, path: path, | 92 return new Suite(tests, platform: platform, os: os, path: path, |
| 100 metadata: metadata, onClose: this.close); | 93 metadata: metadata); |
| 101 } | |
| 102 | |
| 103 /// Closes the suite and releases any resources associated with it. | |
| 104 Future close() { | |
| 105 return _closeThunk.run(() async { | |
| 106 if (_onClose != null) await _onClose(); | |
| 107 }); | |
| 108 } | 94 } |
| 109 } | 95 } |
| OLD | NEW |