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

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

Issue 1379203002: Refactor groups to pipe them through to the runner. (Closed) Base URL: git@github.com:dart-lang/test@master
Patch Set: Code review changes Created 5 years, 2 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/backend/suite_entry.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:collection'; 7 import 'dart:collection';
8 8
9 import 'metadata.dart'; 9 import 'metadata.dart';
10 import 'operating_system.dart'; 10 import 'operating_system.dart';
11 import 'suite_entry.dart';
11 import 'test.dart'; 12 import 'test.dart';
12 import 'test_platform.dart'; 13 import 'test_platform.dart';
13 14
14 /// A test suite. 15 /// A test suite.
15 /// 16 ///
16 /// A test suite is a set of tests that are intended to be run together and that 17 /// A test suite is a set of tests that are intended to be run together and that
17 /// share default configuration. 18 /// share default configuration.
18 class Suite { 19 class Suite {
19 /// The platform on which the suite is running, or `null` if that platform is 20 /// The platform on which the suite is running, or `null` if that platform is
20 /// unknown. 21 /// unknown.
21 final TestPlatform platform; 22 final TestPlatform platform;
22 23
23 /// The operating system on which the suite is running, or `null` if that 24 /// The operating system on which the suite is running, or `null` if that
24 /// operating system is unknown. 25 /// operating system is unknown.
25 /// 26 ///
26 /// This will always be `null` if [platform] is `null`. 27 /// This will always be `null` if [platform] is `null`.
27 final OperatingSystem os; 28 final OperatingSystem os;
28 29
29 /// The path to the Dart test suite, or `null` if that path is unknown. 30 /// The path to the Dart test suite, or `null` if that path is unknown.
30 final String path; 31 final String path;
31 32
32 /// The metadata associated with this test suite. 33 /// The metadata associated with this test suite.
33 final Metadata metadata; 34 final Metadata metadata;
34 35
35 /// The tests in the test suite. 36 /// The tests and groups in this test suite.
36 final List<Test> tests; 37 final List<SuiteEntry> entries;
37 38
38 /// Creates a new suite containing [tests]. 39 /// Creates a new suite containing [entires].
39 /// 40 ///
40 /// If [platform] and/or [os] are passed, [tests] and [metadata] are filtered 41 /// If [platform] and/or [os] are passed, [entries] and [metadata] are filtere d
41 /// to match that platform information. 42 /// to match that platform information.
42 /// 43 ///
43 /// If [os] is passed without [platform], throws an [ArgumentError]. 44 /// If [os] is passed without [platform], throws an [ArgumentError].
44 Suite(Iterable<Test> tests, {this.path, TestPlatform platform, 45 Suite(Iterable<SuiteEntry> entries, {this.path, TestPlatform platform,
45 OperatingSystem os, Metadata metadata}) 46 OperatingSystem os, Metadata metadata})
46 : platform = platform, 47 : platform = platform,
47 os = os, 48 os = os,
48 metadata = _filterMetadata(metadata, platform, os), 49 metadata = _filterMetadata(metadata, platform, os),
49 tests = new UnmodifiableListView<Test>( 50 entries = new UnmodifiableListView<SuiteEntry>(
50 _filterTests(tests, platform, os)); 51 _filterEntries(entries, platform, os));
51 52
52 /// Returns [metadata] filtered according to [platform] and [os]. 53 /// Returns [metadata] filtered according to [platform] and [os].
53 /// 54 ///
54 /// Gracefully handles either [metadata] or [platform] being null. 55 /// Gracefully handles either [metadata] or [platform] being null.
55 static Metadata _filterMetadata(Metadata metadata, TestPlatform platform, 56 static Metadata _filterMetadata(Metadata metadata, TestPlatform platform,
56 OperatingSystem os) { 57 OperatingSystem os) {
57 if (platform == null && os != null) { 58 if (platform == null && os != null) {
58 throw new ArgumentError.value(null, "os", 59 throw new ArgumentError.value(null, "os",
59 "If os is passed, platform must be passed as well"); 60 "If os is passed, platform must be passed as well");
60 } 61 }
61 62
62 if (metadata == null) return new Metadata(); 63 if (metadata == null) return new Metadata();
63 if (platform == null) return metadata; 64 if (platform == null) return metadata;
64 return metadata.forPlatform(platform, os: os); 65 return metadata.forPlatform(platform, os: os);
65 } 66 }
66 67
67 /// Returns [tests] filtered according to [platform] and [os]. 68 /// Returns [entries] filtered according to [platform] and [os].
68 /// 69 ///
69 /// Gracefully handles [platform] being null. 70 /// Gracefully handles [platform] being null.
70 static List<Test> _filterTests(Iterable<Test> tests, 71 static List<SuiteEntry> _filterEntries(Iterable<SuiteEntry> entries,
71 TestPlatform platform, OperatingSystem os) { 72 TestPlatform platform, OperatingSystem os) {
72 if (platform == null) return tests.toList(); 73 if (platform == null) return entries.toList();
73 74
74 return tests.where((test) { 75 return entries.map((entry) {
75 return test.metadata.testOn.evaluate(platform, os: os); 76 return entry.forPlatform(platform, os: os);
76 }).map((test) { 77 }).where((entry) => entry != null).toList();
77 return test.change(metadata: test.metadata.forPlatform(platform, os: os));
78 }).toList();
79 } 78 }
80 79
81 /// Returns a new suite with the given fields updated. 80 /// Returns a new suite with all tests matching [test] removed.
82 /// 81 ///
83 /// In the new suite, [metadata] and [tests] will be filtered according to 82 /// Unlike [SuiteEntry.filter], this never returns `null`. If all entries are
84 /// [platform] and [os]. 83 /// filtered out, it returns an empty suite.
85 Suite change({String path, Metadata metadata, Iterable<Test> tests}) { 84 Suite filter(bool callback(Test test)) {
86 if (path == null) path = this.path; 85 var filtered = entries
87 if (metadata == null) metadata = this.metadata; 86 .map((entry) => entry.filter(callback))
88 if (tests == null) tests = this.tests; 87 .where((entry) => entry != null)
89 return new Suite(tests, platform: platform, os: os, path: path, 88 .toList();
90 metadata: metadata); 89 return new Suite(filtered,
90 platform: platform, os: os, path: path, metadata: metadata);
91 } 91 }
92 } 92 }
OLDNEW
« no previous file with comments | « lib/src/backend/metadata.dart ('k') | lib/src/backend/suite_entry.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698