OLD | NEW |
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.group; | 5 library test.backend.group; |
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_entry.dart'; |
12 import 'test.dart'; | 10 import 'test.dart'; |
13 import 'test_platform.dart'; | 11 import 'test_platform.dart'; |
14 | 12 |
15 /// A group contains one or more tests and subgroups. | 13 /// A group contains one or more tests and subgroups. |
16 /// | 14 /// |
17 /// It includes metadata that applies to all contained tests. | 15 /// It includes metadata that applies to all contained tests. |
18 class Group implements SuiteEntry { | 16 class Group implements GroupEntry { |
19 final String name; | 17 final String name; |
20 | 18 |
21 final Metadata metadata; | 19 final Metadata metadata; |
22 | 20 |
23 /// The children of this group. | 21 /// The children of this group. |
24 final List<SuiteEntry> entries; | 22 final List<GroupEntry> entries; |
25 | 23 |
26 Group(this.name, this.metadata, Iterable<SuiteEntry> entries) | 24 /// Returns a new root-level group. |
27 : entries = new UnmodifiableListView<SuiteEntry>(entries.toList()); | 25 Group.root(Iterable<GroupEntry> entries, {Metadata metadata}) |
| 26 : this(null, entries, metadata: metadata); |
| 27 |
| 28 Group(this.name, Iterable<GroupEntry> entries, {Metadata metadata}) |
| 29 : entries = new List<GroupEntry>.unmodifiable(entries), |
| 30 metadata = metadata == null ? new Metadata() : metadata; |
28 | 31 |
29 Group forPlatform(TestPlatform platform, {OperatingSystem os}) { | 32 Group forPlatform(TestPlatform platform, {OperatingSystem os}) { |
30 if (!metadata.testOn.evaluate(platform, os: os)) return null; | 33 if (!metadata.testOn.evaluate(platform, os: os)) return null; |
31 var newMetadata = metadata.forPlatform(platform, os: os); | 34 var newMetadata = metadata.forPlatform(platform, os: os); |
32 var filtered = _map((entry) => entry.forPlatform(platform, os: os)); | 35 var filtered = _map((entry) => entry.forPlatform(platform, os: os)); |
33 if (filtered.isEmpty) return null; | 36 if (filtered.isEmpty) return null; |
34 return new Group(name, newMetadata, filtered); | 37 return new Group(name, filtered, metadata: newMetadata); |
35 } | 38 } |
36 | 39 |
37 Group filter(bool callback(Test test)) { | 40 Group filter(bool callback(Test test)) { |
38 var filtered = _map((entry) => entry.filter(callback)); | 41 var filtered = _map((entry) => entry.filter(callback)); |
39 if (filtered.isEmpty) return null; | 42 if (filtered.isEmpty) return null; |
40 return new Group(name, metadata, filtered); | 43 return new Group(name, filtered, metadata: metadata); |
41 } | 44 } |
42 | 45 |
43 /// Returns the entries of this group mapped using [callback]. | 46 /// Returns the entries of this group mapped using [callback]. |
44 /// | 47 /// |
45 /// Any `null` values returned by [callback] will be removed. | 48 /// Any `null` values returned by [callback] will be removed. |
46 List<SuiteEntry> _map(SuiteEntry callback(SuiteEntry entry)) { | 49 List<GroupEntry> _map(GroupEntry callback(GroupEntry entry)) { |
47 return entries | 50 return entries |
48 .map((entry) => callback(entry)) | 51 .map((entry) => callback(entry)) |
49 .where((entry) => entry != null) | 52 .where((entry) => entry != null) |
50 .toList(); | 53 .toList(); |
51 } | 54 } |
52 } | 55 } |
OLD | NEW |