Chromium Code Reviews

Side by Side Diff: lib/src/backend/live_test.dart

Issue 1469863005: Add JSON protocol support for groups. (Closed) Base URL: git@github.com:dart-lang/test@master
Patch Set: Code review changes Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff |
« no previous file with comments | « lib/src/backend/invoker.dart ('k') | lib/src/backend/live_test_controller.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 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file 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 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. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 library test.backend.live_test; 5 library test.backend.live_test;
6 6
7 import 'dart:async'; 7 import 'dart:async';
8 8
9 import 'group.dart';
9 import 'state.dart'; 10 import 'state.dart';
10 import 'suite.dart'; 11 import 'suite.dart';
11 import 'test.dart'; 12 import 'test.dart';
12 13
13 /// A runnable instance of a test. 14 /// A runnable instance of a test.
14 /// 15 ///
15 /// This is distinct from [Test] in order to keep [Test]. Running a test 16 /// This is distinct from [Test] in order to keep [Test]. Running a test
16 /// requires state, and [LiveTest] provides a view of the state of the test as 17 /// requires state, and [LiveTest] provides a view of the state of the test as
17 /// it runs. 18 /// it runs.
18 /// 19 ///
19 /// If the state changes, [state] will be updated before [onStateChange] fires. 20 /// If the state changes, [state] will be updated before [onStateChange] fires.
20 /// Likewise, if an error is caught, it will be added to [errors] before being 21 /// Likewise, if an error is caught, it will be added to [errors] before being
21 /// emitted via [onError]. If an error causes a state change, [onStateChange] 22 /// emitted via [onError]. If an error causes a state change, [onStateChange]
22 /// will fire before [onError]. If an error or other state change causes the 23 /// will fire before [onError]. If an error or other state change causes the
23 /// test to complete, [onComplete] will complete after [onStateChange] and 24 /// test to complete, [onComplete] will complete after [onStateChange] and
24 /// [onError] fire. 25 /// [onError] fire.
25 abstract class LiveTest { 26 abstract class LiveTest {
26 /// The suite within which this test is being run. 27 /// The suite within which this test is being run.
27 Suite get suite; 28 Suite get suite;
28 29
30 /// The groups within which this test is being run, from the outermost to the
31 /// innermost.
32 ///
33 /// This will always contain at least the implicit top-level group.
34 List<Group> get groups;
35
29 /// The running test. 36 /// The running test.
30 Test get test; 37 Test get test;
31 38
32 /// The current state of the running test. 39 /// The current state of the running test.
33 /// 40 ///
34 /// This starts as [Status.pending] and [Result.success]. It will be updated 41 /// This starts as [Status.pending] and [Result.success]. It will be updated
35 /// before [onStateChange] fires. 42 /// before [onStateChange] fires.
36 /// 43 ///
37 /// Note that even if this is marked [Status.complete], the test may still be 44 /// Note that even if this is marked [Status.complete], the test may still be
38 /// running code asynchronously. A test is considered complete either once it 45 /// running code asynchronously. A test is considered complete either once it
(...skipping 49 matching lines...)
88 /// has fired if the test completes because of an error. It's the same as the 95 /// has fired if the test completes because of an error. It's the same as the
89 /// [Future] returned by [run]. 96 /// [Future] returned by [run].
90 /// 97 ///
91 /// Note that even once this completes, the test may still be running code 98 /// Note that even once this completes, the test may still be running code
92 /// asynchronously. A test is considered complete either once it hits its 99 /// asynchronously. A test is considered complete either once it hits its
93 /// first error or when all [expectAsync] callbacks have been called and any 100 /// first error or when all [expectAsync] callbacks have been called and any
94 /// returned [Future] has completed, but it's possible for further processing 101 /// returned [Future] has completed, but it's possible for further processing
95 /// to happen, which may cause further errors. 102 /// to happen, which may cause further errors.
96 Future get onComplete; 103 Future get onComplete;
97 104
105 /// The name of this live test without any group prefixes.
106 String get individualName {
107 var group = groups.last;
108 if (group.name == null) return test.name;
109 if (!test.name.startsWith(group.name)) return test.name;
110
111 // The test will have the same name as the group for virtual tests created
112 // to represent skipping the entire group.
113 if (test.name.length == group.name.length) return "";
114
115 return test.name.substring(group.name.length + 1);
116 }
117
98 /// Signals that this test should start running as soon as possible. 118 /// Signals that this test should start running as soon as possible.
99 /// 119 ///
100 /// A test may not start running immediately for various reasons specific to 120 /// A test may not start running immediately for various reasons specific to
101 /// the means by which it's defined. Until it starts running, [state] will 121 /// the means by which it's defined. Until it starts running, [state] will
102 /// continue to be marked [Status.pending]. 122 /// continue to be marked [Status.pending].
103 /// 123 ///
104 /// This returns the same [Future] as [onComplete]. It may not be called more 124 /// This returns the same [Future] as [onComplete]. It may not be called more
105 /// than once. 125 /// than once.
106 Future run(); 126 Future run();
107 127
108 /// Signals that this test should stop emitting events and release any 128 /// Signals that this test should stop emitting events and release any
109 /// resources it may have allocated. 129 /// resources it may have allocated.
110 /// 130 ///
111 /// Once [close] is called, [onComplete] will complete if it hasn't already 131 /// Once [close] is called, [onComplete] will complete if it hasn't already
112 /// and [onStateChange] and [onError] will close immediately. This means that, 132 /// and [onStateChange] and [onError] will close immediately. This means that,
113 /// if the test was running at the time [close] is called, it will never emit 133 /// if the test was running at the time [close] is called, it will never emit
114 /// a [Status.complete] state-change event. Once a test is closed, [expect] 134 /// a [Status.complete] state-change event. Once a test is closed, [expect]
115 /// and [expectAsync] will throw a [ClosedException] to help the test 135 /// and [expectAsync] will throw a [ClosedException] to help the test
116 /// terminate as quickly as possible. 136 /// terminate as quickly as possible.
117 /// 137 ///
118 /// This doesn't automatically happen after the test completes because there 138 /// This doesn't automatically happen after the test completes because there
119 /// may be more asynchronous work going on in the background that could 139 /// may be more asynchronous work going on in the background that could
120 /// produce new errors. 140 /// produce new errors.
121 /// 141 ///
122 /// Returns a [Future] that completes once all resources are released *and* 142 /// Returns a [Future] that completes once all resources are released *and*
123 /// the test has completed. This allows the caller to wait until the test's 143 /// the test has completed. This allows the caller to wait until the test's
124 /// tear-down logic has run. 144 /// tear-down logic has run.
125 Future close(); 145 Future close();
126 } 146 }
OLDNEW
« no previous file with comments | « lib/src/backend/invoker.dart ('k') | lib/src/backend/live_test_controller.dart » ('j') | no next file with comments »

Powered by Google App Engine