| Index: mojo/public/dart/third_party/test/lib/src/backend/suite.dart
|
| diff --git a/mojo/public/dart/third_party/test/lib/src/backend/suite.dart b/mojo/public/dart/third_party/test/lib/src/backend/suite.dart
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..4b6fbc941de47c13bebe16f9688af3f2ea2e9478
|
| --- /dev/null
|
| +++ b/mojo/public/dart/third_party/test/lib/src/backend/suite.dart
|
| @@ -0,0 +1,92 @@
|
| +// Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file
|
| +// for details. All rights reserved. Use of this source code is governed by a
|
| +// BSD-style license that can be found in the LICENSE file.
|
| +
|
| +library test.backend.suite;
|
| +
|
| +import 'dart:collection';
|
| +
|
| +import 'metadata.dart';
|
| +import 'operating_system.dart';
|
| +import 'test.dart';
|
| +import 'test_platform.dart';
|
| +
|
| +/// A test suite.
|
| +///
|
| +/// A test suite is a set of tests that are intended to be run together and that
|
| +/// share default configuration.
|
| +class Suite {
|
| + /// The platform on which the suite is running, or `null` if that platform is
|
| + /// unknown.
|
| + final TestPlatform platform;
|
| +
|
| + /// The operating system on which the suite is running, or `null` if that
|
| + /// operating system is unknown.
|
| + ///
|
| + /// This will always be `null` if [platform] is `null`.
|
| + final OperatingSystem os;
|
| +
|
| + /// The path to the Dart test suite, or `null` if that path is unknown.
|
| + final String path;
|
| +
|
| + /// The metadata associated with this test suite.
|
| + final Metadata metadata;
|
| +
|
| + /// The tests in the test suite.
|
| + final List<Test> tests;
|
| +
|
| + /// Creates a new suite containing [tests].
|
| + ///
|
| + /// If [platform] and/or [os] are passed, [tests] and [metadata] are filtered
|
| + /// to match that platform information.
|
| + ///
|
| + /// If [os] is passed without [platform], throws an [ArgumentError].
|
| + Suite(Iterable<Test> tests, {this.path, TestPlatform platform,
|
| + OperatingSystem os, Metadata metadata})
|
| + : platform = platform,
|
| + os = os,
|
| + metadata = _filterMetadata(metadata, platform, os),
|
| + tests = new UnmodifiableListView<Test>(
|
| + _filterTests(tests, platform, os));
|
| +
|
| + /// Returns [metadata] filtered according to [platform] and [os].
|
| + ///
|
| + /// Gracefully handles either [metadata] or [platform] being null.
|
| + static Metadata _filterMetadata(Metadata metadata, TestPlatform platform,
|
| + OperatingSystem os) {
|
| + if (platform == null && os != null) {
|
| + throw new ArgumentError.value(null, "os",
|
| + "If os is passed, platform must be passed as well");
|
| + }
|
| +
|
| + if (metadata == null) return new Metadata();
|
| + if (platform == null) return metadata;
|
| + return metadata.forPlatform(platform, os: os);
|
| + }
|
| +
|
| + /// Returns [tests] filtered according to [platform] and [os].
|
| + ///
|
| + /// Gracefully handles [platform] being null.
|
| + static List<Test> _filterTests(Iterable<Test> tests,
|
| + TestPlatform platform, OperatingSystem os) {
|
| + if (platform == null) return tests.toList();
|
| +
|
| + return tests.where((test) {
|
| + return test.metadata.testOn.evaluate(platform, os: os);
|
| + }).map((test) {
|
| + return test.change(metadata: test.metadata.forPlatform(platform, os: os));
|
| + }).toList();
|
| + }
|
| +
|
| + /// Returns a new suite with the given fields updated.
|
| + ///
|
| + /// In the new suite, [metadata] and [tests] will be filtered according to
|
| + /// [platform] and [os].
|
| + Suite change({String path, Metadata metadata, Iterable<Test> tests}) {
|
| + if (path == null) path = this.path;
|
| + if (metadata == null) metadata = this.metadata;
|
| + if (tests == null) tests = this.tests;
|
| + return new Suite(tests, platform: platform, os: os, path: path,
|
| + metadata: metadata);
|
| + }
|
| +}
|
|
|