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