Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(186)

Side by Side Diff: lib/src/group_context.dart

Issue 869043002: Clean up unittest a bunch. (Closed) Base URL: git@github.com:dart-lang/unittest@master
Patch Set: Code review changes Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « lib/src/expected_function.dart ('k') | lib/src/internal_test_case.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 part of unittest; 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';
2 10
3 /// Setup and teardown functions for a group and its parents, the latter 11 /// Setup and teardown functions for a group and its parents, the latter
4 /// for chaining. 12 /// for chaining.
5 class _GroupContext { 13 class GroupContext {
6 final _GroupContext parent; 14 /// The parent context, or `null`.
15 final GroupContext parent;
16
17 /// Whether this is the root context.
18 bool get isRoot => parent == null;
7 19
8 /// Description text of the current test group. 20 /// Description text of the current test group.
9 final String _name; 21 final String _name;
10 22
11 /// Setup function called before each test in a group. 23 /// The set-up function called before each test in a group.
12 Function _testSetup; 24 Function get testSetUp => _testSetUp;
25 Function _testSetUp;
13 26
14 get testSetup => _testSetup; 27 set testSetUp(Function setUp) {
28 if (parent == null || parent.testSetUp == null) {
29 _testSetUp = setUp;
30 return;
31 }
15 32
16 get parentSetup => (parent == null) ? null : parent.testSetup; 33 _testSetUp = () {
17 34 var f = parent.testSetUp();
18 set testSetup(Function setup) { 35 if (f is Future) {
19 var preSetup = parentSetup; 36 return f.then((_) => setUp());
20 if (preSetup == null) { 37 } else {
21 _testSetup = setup; 38 return setUp();
22 } else { 39 }
23 _testSetup = () { 40 };
24 var f = preSetup();
25 if (f is Future) {
26 return f.then((_) => setup());
27 } else {
28 return setup();
29 }
30 };
31 }
32 } 41 }
33 42
34 /// Teardown function called after each test in a group. 43 /// The tear-down function called after each test in a group.
35 Function _testTeardown; 44 Function get testTearDown => _testTearDown;
45 Function _testTearDown;
36 46
37 get testTeardown => _testTeardown; 47 set testTearDown(Function tearDown) {
48 if (parent == null || parent.testTearDown == null) {
49 _testTearDown = tearDown;
50 return;
51 }
38 52
39 get parentTeardown => (parent == null) ? null : parent.testTeardown; 53 _testTearDown = () {
40 54 var f = tearDown();
41 set testTeardown(Function teardown) { 55 if (f is Future) {
42 var postTeardown = parentTeardown; 56 return f.then((_) => parent.testTearDown());
43 if (postTeardown == null) { 57 } else {
44 _testTeardown = teardown; 58 return parent.testTearDown();
45 } else { 59 }
46 _testTeardown = () { 60 };
47 var f = teardown();
48 if (f is Future) {
49 return f.then((_) => postTeardown());
50 } else {
51 return postTeardown();
52 }
53 };
54 }
55 } 61 }
56 62
57 String get fullName => (parent == null || parent == _environment.rootContext) 63 /// Returns the fully-qualified name of this context.
58 ? _name 64 String get fullName =>
59 : "${parent.fullName}$groupSep$_name"; 65 (isRoot || parent.isRoot) ? _name : "${parent.fullName}$groupSep$_name";
60 66
61 _GroupContext([this.parent, this._name = '']) { 67 GroupContext.root()
62 _testSetup = parentSetup; 68 : parent = null,
63 _testTeardown = parentTeardown; 69 _name = '';
70
71 GroupContext(this.parent, this._name) {
72 _testSetUp = parent.testSetUp;
73 _testTearDown = parent.testTearDown;
64 } 74 }
65 } 75 }
OLDNEW
« no previous file with comments | « lib/src/expected_function.dart ('k') | lib/src/internal_test_case.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698