Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(73)

Side by Side Diff: lib/src/backend/suite.dart

Issue 1239693002: Pass actual TestPlatform and OperatingSystem values to Suite. (Closed) Base URL: git@github.com:dart-lang/test@master
Patch Set: Update pubspec. Created 5 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « lib/src/backend/metadata.dart ('k') | lib/src/runner/browser/browser_manager.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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';
8 import 'dart:collection'; 8 import 'dart:collection';
9 9
10 import '../util/async_thunk.dart'; 10 import '../util/async_thunk.dart';
11 import '../utils.dart'; 11 import '../utils.dart';
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 /// A description of the platform on which the suite is running, or `null` if 22 /// The platform on which the suite is running, or `null` if that platform is
23 /// that platform is unknown. 23 /// unknown.
24 final String platform; 24 final TestPlatform platform;
25
26 /// The operating system on which the suite is running, or `null` if that
27 /// operating system is unknown.
28 ///
29 /// This will always be `null` if [platform] is `null`.
30 final OperatingSystem os;
25 31
26 /// 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.
27 final String path; 33 final String path;
28 34
29 /// The metadata associated with this test suite. 35 /// The metadata associated with this test suite.
30 final Metadata metadata; 36 final Metadata metadata;
31 37
32 /// The thunk for running [close] exactly once. 38 /// The thunk for running [close] exactly once.
33 final _closeThunk = new AsyncThunk(); 39 final _closeThunk = new AsyncThunk();
34 40
35 /// The function to call when the suite is closed. 41 /// The function to call when the suite is closed.
36 final AsyncFunction _onClose; 42 final AsyncFunction _onClose;
37 43
38 /// The tests in the test suite. 44 /// The tests in the test suite.
39 final List<Test> tests; 45 final List<Test> tests;
40 46
41 Suite(Iterable<Test> tests, {this.path, this.platform, Metadata metadata, 47 /// Creates a new suite containing [tests].
42 AsyncFunction onClose}) 48 ///
43 : metadata = metadata == null ? new Metadata() : metadata, 49 /// If [platform] and/or [os] are passed, [tests] and [metadata] are filtered
50 /// to match that platform information.
51 ///
52 /// If [os] is passed without [platform], throws an [ArgumentError].
53 Suite(Iterable<Test> tests, {this.path, TestPlatform platform,
54 OperatingSystem os, Metadata metadata, AsyncFunction onClose})
55 : platform = platform,
56 os = os,
57 metadata = _filterMetadata(metadata, platform, os),
44 _onClose = onClose, 58 _onClose = onClose,
45 tests = new UnmodifiableListView<Test>(tests.toList()); 59 tests = new UnmodifiableListView<Test>(
60 _filterTests(tests, platform, os));
46 61
47 /// Returns a view of this suite for the given [platform] and [os]. 62 /// Returns [metadata] filtered according to [platform] and [os].
48 /// 63 ///
49 /// This filters out tests that are invalid for [platform] and [os] and 64 /// Gracefully handles either [metadata] or [platform] being null.
50 /// resolves platform-specific metadata. If the suite itself is invalid for 65 static Metadata _filterMetadata(Metadata metadata, TestPlatform platform,
51 /// [platform] and [os], returns `null`. 66 OperatingSystem os) {
52 Suite forPlatform(TestPlatform platform, {OperatingSystem os}) { 67 if (platform == null && os != null) {
53 if (!metadata.testOn.evaluate(platform, os: os)) return null; 68 throw new ArgumentError.value(null, "os",
54 return change(tests: tests.where((test) { 69 "If os is passed, platform must be passed as well");
70 }
71
72 if (metadata == null) return new Metadata();
73 if (platform == null) return metadata;
74 return metadata.forPlatform(platform, os: os);
75 }
76
77 /// Returns [tests] filtered according to [platform] and [os].
78 ///
79 /// Gracefully handles [platform] being null.
80 static List<Test> _filterTests(Iterable<Test> tests,
81 TestPlatform platform, OperatingSystem os) {
82 if (platform == null) return tests.toList();
83
84 return tests.where((test) {
55 return test.metadata.testOn.evaluate(platform, os: os); 85 return test.metadata.testOn.evaluate(platform, os: os);
56 }).map((test) { 86 }).map((test) {
57 return test.change(metadata: test.metadata.forPlatform(platform, os: os)); 87 return test.change(metadata: test.metadata.forPlatform(platform, os: os));
58 }), metadata: metadata.forPlatform(platform, os: os)); 88 }).toList();
59 } 89 }
60 90
61 /// Returns a new suite with the given fields updated. 91 /// Returns a new suite with the given fields updated.
62 Suite change({String path, String platform, Metadata metadata, 92 ///
63 Iterable<Test> tests}) { 93 /// In the new suite, [metadata] and [tests] will be filtered according to
94 /// [platform] and [os].
95 Suite change({String path, Metadata metadata, Iterable<Test> tests}) {
64 if (path == null) path = this.path; 96 if (path == null) path = this.path;
65 if (platform == null) platform = this.platform;
66 if (metadata == null) metadata = this.metadata; 97 if (metadata == null) metadata = this.metadata;
67 if (tests == null) tests = this.tests; 98 if (tests == null) tests = this.tests;
68 return new Suite(tests, path: path, platform: platform, metadata: metadata, 99 return new Suite(tests, path: path, metadata: metadata,
69 onClose: this.close); 100 onClose: this.close);
70 } 101 }
71 102
72 /// Closes the suite and releases any resources associated with it. 103 /// Closes the suite and releases any resources associated with it.
73 Future close() { 104 Future close() {
74 return _closeThunk.run(() async { 105 return _closeThunk.run(() async {
75 if (_onClose != null) await _onClose(); 106 if (_onClose != null) await _onClose();
76 }); 107 });
77 } 108 }
78 } 109 }
OLDNEW
« no previous file with comments | « lib/src/backend/metadata.dart ('k') | lib/src/runner/browser/browser_manager.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698