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

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

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

Powered by Google App Engine
This is Rietveld 408576698