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

Side by Side Diff: mojo/public/dart/third_party/test/lib/src/backend/group.dart

Issue 1346773002: Stop running pub get at gclient sync time and fix build bugs (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 5 years, 3 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
OLDNEW
(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 test.backend.group;
6
7 import 'dart:async';
8
9 import '../utils.dart';
10 import 'metadata.dart';
11
12 /// A group contains multiple tests and subgroups.
13 ///
14 /// A group has a description that is prepended to that of all nested tests and
15 /// subgroups. It also has [setUp] and [tearDown] functions which are scoped to
16 /// the tests and groups it contains.
17 class Group {
18 /// The parent group, or `null` if this is the root group.
19 final Group parent;
20
21 /// The description of the current test group, or `null` if this is the root
22 /// group.
23 final String _description;
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
32 /// The set-up function for this group, or `null`.
33 AsyncFunction setUp;
34
35 /// The tear-down function for this group, or `null`.
36 AsyncFunction tearDown;
37
38 /// Returns the description for this group, including the description of any
39 /// parent groups.
40 ///
41 /// If this is the root group, returns `null`.
42 String get description {
43 if (parent == null || parent.description == null) return _description;
44 return "${parent.description} $_description";
45 }
46
47 /// Creates a new root group.
48 ///
49 /// This is the implicit group that exists outside of any calls to `group()`.
50 Group.root()
51 : this(null, null, new Metadata());
52
53 Group(this.parent, this._description, this._metadata);
54
55 /// Run the set-up functions for this and any parent groups.
56 ///
57 /// If no set-up functions are declared, this returns a [Future] that
58 /// completes immediately.
59 Future runSetUp() {
60 // TODO(nweiz): Use async/await here once issue 23497 has been fixed in two
61 // stable versions.
62 if (parent != null) {
63 return parent.runSetUp().then((_) {
64 if (setUp != null) return setUp();
65 });
66 }
67
68 if (setUp != null) return new Future.sync(setUp);
69 return new Future.value();
70 }
71
72 /// Run the tear-up functions for this and any parent groups.
73 ///
74 /// If no set-up functions are declared, this returns a [Future] that
75 /// completes immediately.
76 Future runTearDown() {
77 // TODO(nweiz): Use async/await here once issue 23497 has been fixed in two
78 // stable versions.
79 if (parent != null) {
80 return new Future.sync(() {
81 if (tearDown != null) return tearDown();
82 }).then((_) => parent.runTearDown());
83 }
84
85 if (tearDown != null) return new Future.sync(tearDown);
86 return new Future.value();
87 }
88 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698