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_context; | |
6 | |
7 import 'dart:async'; | |
8 | |
9 import '../unittest.dart'; | |
10 | |
11 /// Setup and teardown functions for a group and its parents, the latter | |
12 /// for chaining. | |
13 class GroupContext { | |
14 /// The parent context, or `null`. | |
15 final GroupContext parent; | |
16 | |
17 /// Whether this is the root context. | |
18 bool get isRoot => parent == null; | |
19 | |
20 /// Description text of the current test group. | |
21 final String _name; | |
22 | |
23 /// The set-up function called before each test in a group. | |
24 Function get testSetUp => _testSetUp; | |
25 Function _testSetUp; | |
26 | |
27 set testSetUp(Function setUp) { | |
28 if (parent == null || parent.testSetUp == null) { | |
29 _testSetUp = setUp; | |
30 return; | |
31 } | |
32 | |
33 _testSetUp = () { | |
34 var f = parent.testSetUp(); | |
35 if (f is Future) { | |
36 return f.then((_) => setUp()); | |
37 } else { | |
38 return setUp(); | |
39 } | |
40 }; | |
41 } | |
42 | |
43 /// The tear-down function called after each test in a group. | |
44 Function get testTearDown => _testTearDown; | |
45 Function _testTearDown; | |
46 | |
47 set testTearDown(Function tearDown) { | |
48 if (parent == null || parent.testTearDown == null) { | |
49 _testTearDown = tearDown; | |
50 return; | |
51 } | |
52 | |
53 _testTearDown = () { | |
54 var f = tearDown(); | |
55 if (f is Future) { | |
56 return f.then((_) => parent.testTearDown()); | |
57 } else { | |
58 return parent.testTearDown(); | |
59 } | |
60 }; | |
61 } | |
62 | |
63 /// Returns the fully-qualified name of this context. | |
64 String get fullName => | |
65 (isRoot || parent.isRoot) ? _name : "${parent.fullName}$groupSep$_name"; | |
66 | |
67 GroupContext.root() | |
68 : parent = null, | |
69 _name = ''; | |
70 | |
71 GroupContext(this.parent, this._name) { | |
72 _testSetUp = parent.testSetUp; | |
73 _testTearDown = parent.testTearDown; | |
74 } | |
75 } | |
OLD | NEW |