OLD | NEW |
(Empty) | |
| 1 part of unittest; |
| 2 |
| 3 /** |
| 4 * Setup and teardown functions for a group and its parents, the latter |
| 5 * for chaining. |
| 6 */ |
| 7 class _GroupContext { |
| 8 final _GroupContext parent; |
| 9 |
| 10 /** Description text of the current test group. */ |
| 11 final String _name; |
| 12 |
| 13 /** Setup function called before each test in a group. */ |
| 14 Function _testSetup; |
| 15 |
| 16 get testSetup => _testSetup; |
| 17 |
| 18 get parentSetup => (parent == null) ? null : parent.testSetup; |
| 19 |
| 20 set testSetup(Function setup) { |
| 21 var preSetup = parentSetup; |
| 22 if (preSetup == null) { |
| 23 _testSetup = setup; |
| 24 } else { |
| 25 _testSetup = () { |
| 26 var f = preSetup(); |
| 27 if (f is Future) { |
| 28 return f.then((_) => setup()); |
| 29 } else { |
| 30 return setup(); |
| 31 } |
| 32 }; |
| 33 } |
| 34 } |
| 35 |
| 36 /** Teardown function called after each test in a group. */ |
| 37 Function _testTeardown; |
| 38 |
| 39 get testTeardown => _testTeardown; |
| 40 |
| 41 get parentTeardown => (parent == null) ? null : parent.testTeardown; |
| 42 |
| 43 set testTeardown(Function teardown) { |
| 44 var postTeardown = parentTeardown; |
| 45 if (postTeardown == null) { |
| 46 _testTeardown = teardown; |
| 47 } else { |
| 48 _testTeardown = () { |
| 49 var f = teardown(); |
| 50 if (f is Future) { |
| 51 return f.then((_) => postTeardown()); |
| 52 } else { |
| 53 return postTeardown(); |
| 54 } |
| 55 }; |
| 56 } |
| 57 } |
| 58 |
| 59 String get fullName => (parent == null || parent == _rootContext) |
| 60 ? _name |
| 61 : "${parent.fullName}$groupSep$_name"; |
| 62 |
| 63 _GroupContext([this.parent, this._name = '']) { |
| 64 _testSetup = parentSetup; |
| 65 _testTeardown = parentTeardown; |
| 66 } |
| 67 } |
OLD | NEW |