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 unittest.backend.group; | 5 library unittest.backend.group; |
6 | 6 |
7 import 'dart:async'; | 7 import 'dart:async'; |
8 | 8 |
9 import '../utils.dart'; | 9 import '../utils.dart'; |
| 10 import 'metadata.dart'; |
10 | 11 |
11 /// A group contains multiple tests and subgroups. | 12 /// A group contains multiple tests and subgroups. |
12 /// | 13 /// |
13 /// A group has a description that is prepended to that of all nested tests and | 14 /// A group has a description that is prepended to that of all nested tests and |
14 /// subgroups. It also has [setUp] and [tearDown] functions which are scoped to | 15 /// subgroups. It also has [setUp] and [tearDown] functions which are scoped to |
15 /// the tests and groups it contains. | 16 /// the tests and groups it contains. |
16 class Group { | 17 class Group { |
17 /// The parent group, or `null` if this is the root group. | 18 /// The parent group, or `null` if this is the root group. |
18 final Group parent; | 19 final Group parent; |
19 | 20 |
20 /// The description of the current test group, or `null` if this is the root | 21 /// The description of the current test group, or `null` if this is the root |
21 /// group. | 22 /// group. |
22 final String _description; | 23 final String _description; |
23 | 24 |
| 25 /// The metadata for this group, including the metadata of any parent groups. |
| 26 Metadata get metadata { |
| 27 if (parent == null) return _metadata; |
| 28 return parent.metadata.merge(_metadata); |
| 29 } |
| 30 final Metadata _metadata; |
| 31 |
24 /// The set-up function for this group, or `null`. | 32 /// The set-up function for this group, or `null`. |
25 AsyncFunction setUp; | 33 AsyncFunction setUp; |
26 | 34 |
27 /// The tear-down function for this group, or `null`. | 35 /// The tear-down function for this group, or `null`. |
28 AsyncFunction tearDown; | 36 AsyncFunction tearDown; |
29 | 37 |
30 /// Returns the description for this group, including the description of any | 38 /// Returns the description for this group, including the description of any |
31 /// parent groups. | 39 /// parent groups. |
32 /// | 40 /// |
33 /// If this is the root group, returns `null`. | 41 /// If this is the root group, returns `null`. |
34 String get description { | 42 String get description { |
35 if (parent == null || parent.description == null) return _description; | 43 if (parent == null || parent.description == null) return _description; |
36 return "${parent.description} $_description"; | 44 return "${parent.description} $_description"; |
37 } | 45 } |
38 | 46 |
39 /// Creates a new root group. | 47 /// Creates a new root group. |
40 /// | 48 /// |
41 /// This is the implicit group that exists outside of any calls to `group()`. | 49 /// This is the implicit group that exists outside of any calls to `group()`. |
42 Group.root() | 50 Group.root() |
43 : this(null, null); | 51 : this(null, null, new Metadata()); |
44 | 52 |
45 Group(this.parent, this._description); | 53 Group(this.parent, this._description, this._metadata); |
46 | 54 |
47 /// Run the set-up functions for this and any parent groups. | 55 /// Run the set-up functions for this and any parent groups. |
48 /// | 56 /// |
49 /// If no set-up functions are declared, this returns a [Future] that | 57 /// If no set-up functions are declared, this returns a [Future] that |
50 /// completes immediately. | 58 /// completes immediately. |
51 Future runSetUp() { | 59 Future runSetUp() { |
52 if (parent != null) { | 60 if (parent != null) { |
53 return parent.runSetUp().then((_) { | 61 return parent.runSetUp().then((_) { |
54 if (setUp != null) return setUp(); | 62 if (setUp != null) return setUp(); |
55 }); | 63 }); |
(...skipping 11 matching lines...) Expand all Loading... |
67 if (parent != null) { | 75 if (parent != null) { |
68 return new Future.sync(() { | 76 return new Future.sync(() { |
69 if (tearDown != null) return tearDown(); | 77 if (tearDown != null) return tearDown(); |
70 }).then((_) => parent.runTearDown()); | 78 }).then((_) => parent.runTearDown()); |
71 } | 79 } |
72 | 80 |
73 if (tearDown != null) return new Future.sync(tearDown); | 81 if (tearDown != null) return new Future.sync(tearDown); |
74 return new Future.value(); | 82 return new Future.value(); |
75 } | 83 } |
76 } | 84 } |
OLD | NEW |