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