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