OLD | NEW |
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_controller; | 5 library test.backend.live_test_controller; |
6 | 6 |
7 import 'dart:async'; | 7 import 'dart:async'; |
8 import 'dart:collection'; | 8 import 'dart:collection'; |
9 | 9 |
10 import 'package:stack_trace/stack_trace.dart'; | 10 import 'package:stack_trace/stack_trace.dart'; |
11 | 11 |
| 12 import 'group.dart'; |
12 import 'live_test.dart'; | 13 import 'live_test.dart'; |
13 import 'state.dart'; | 14 import 'state.dart'; |
14 import 'suite.dart'; | 15 import 'suite.dart'; |
15 import 'test.dart'; | 16 import 'test.dart'; |
16 | 17 |
17 /// An implementation of [LiveTest] that's controlled by a [LiveTestController]. | 18 /// An implementation of [LiveTest] that's controlled by a [LiveTestController]. |
18 class _LiveTest extends LiveTest { | 19 class _LiveTest extends LiveTest { |
19 final LiveTestController _controller; | 20 final LiveTestController _controller; |
20 | 21 |
21 Suite get suite => _controller._suite; | 22 Suite get suite => _controller._suite; |
22 | 23 |
| 24 List<Group> get groups => _controller._groups; |
| 25 |
23 Test get test => _controller._test; | 26 Test get test => _controller._test; |
24 | 27 |
25 State get state => _controller._state; | 28 State get state => _controller._state; |
26 | 29 |
27 Stream<State> get onStateChange => | 30 Stream<State> get onStateChange => |
28 _controller._onStateChangeController.stream; | 31 _controller._onStateChangeController.stream; |
29 | 32 |
30 List<AsyncError> get errors => new UnmodifiableListView(_controller._errors); | 33 List<AsyncError> get errors => new UnmodifiableListView(_controller._errors); |
31 | 34 |
32 Stream<AsyncError> get onError => _controller._onErrorController.stream; | 35 Stream<AsyncError> get onError => _controller._onErrorController.stream; |
(...skipping 19 matching lines...) Expand all Loading... |
52 /// part it's the caller's responsibility to make sure everything gets | 55 /// part it's the caller's responsibility to make sure everything gets |
53 /// dispatched in the correct order. | 56 /// dispatched in the correct order. |
54 class LiveTestController { | 57 class LiveTestController { |
55 /// The [LiveTest] controlled by [this]. | 58 /// The [LiveTest] controlled by [this]. |
56 LiveTest get liveTest => _liveTest; | 59 LiveTest get liveTest => _liveTest; |
57 LiveTest _liveTest; | 60 LiveTest _liveTest; |
58 | 61 |
59 /// The test suite that's running [this]. | 62 /// The test suite that's running [this]. |
60 final Suite _suite; | 63 final Suite _suite; |
61 | 64 |
| 65 /// The groups containing [this]. |
| 66 final List<Group> _groups; |
| 67 |
62 /// The test that's being run. | 68 /// The test that's being run. |
63 final Test _test; | 69 final Test _test; |
64 | 70 |
65 /// The function that will actually start the test running. | 71 /// The function that will actually start the test running. |
66 final Function _onRun; | 72 final Function _onRun; |
67 | 73 |
68 /// A function to run when the test is closed. | 74 /// A function to run when the test is closed. |
69 /// | 75 /// |
70 /// This may be `null`. | 76 /// This may be `null`. |
71 final Function _onClose; | 77 final Function _onClose; |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
111 /// | 117 /// |
112 /// [onRun] is a function that's called from [LiveTest.run]. It should start | 118 /// [onRun] is a function that's called from [LiveTest.run]. It should start |
113 /// the test running. The controller takes care of ensuring that | 119 /// the test running. The controller takes care of ensuring that |
114 /// [LiveTest.run] isn't called more than once and that [LiveTest.onComplete] | 120 /// [LiveTest.run] isn't called more than once and that [LiveTest.onComplete] |
115 /// is returned. | 121 /// is returned. |
116 /// | 122 /// |
117 /// [onClose] is a function that's called the first time [LiveTest.close] is | 123 /// [onClose] is a function that's called the first time [LiveTest.close] is |
118 /// called. It should clean up any resources that have been allocated for the | 124 /// called. It should clean up any resources that have been allocated for the |
119 /// test and ensure that the test finishes quickly if it's still running. It | 125 /// test and ensure that the test finishes quickly if it's still running. It |
120 /// will only be called if [onRun] has been called first. | 126 /// will only be called if [onRun] has been called first. |
121 LiveTestController(this._suite, this._test, void onRun(), void onClose()) | 127 /// |
122 : _onRun = onRun, | 128 /// If [groups] is passed, it's used to populate the list of groups that |
123 _onClose = onClose { | 129 /// contain this test. Otherwise, `suite.group` is used. |
| 130 LiveTestController(Suite suite, this._test, void onRun(), void onClose(), |
| 131 {Iterable<Group> groups}) |
| 132 : _suite = suite, |
| 133 _onRun = onRun, |
| 134 _onClose = onClose, |
| 135 _groups = groups == null |
| 136 ? [suite.group] |
| 137 : new List.unmodifiable(groups) { |
124 _liveTest = new _LiveTest(this); | 138 _liveTest = new _LiveTest(this); |
125 } | 139 } |
126 | 140 |
127 /// Adds an error to the [LiveTest]. | 141 /// Adds an error to the [LiveTest]. |
128 /// | 142 /// |
129 /// This both adds the error to [LiveTest.errors] and emits it via | 143 /// This both adds the error to [LiveTest.errors] and emits it via |
130 /// [LiveTest.onError]. [stackTrace] is automatically converted into a [Chain] | 144 /// [LiveTest.onError]. [stackTrace] is automatically converted into a [Chain] |
131 /// if it's not one already. | 145 /// if it's not one already. |
132 void addError(error, StackTrace stackTrace) { | 146 void addError(error, StackTrace stackTrace) { |
133 if (_isClosed) return; | 147 if (_isClosed) return; |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
185 | 199 |
186 if (_runCalled) { | 200 if (_runCalled) { |
187 _onClose(); | 201 _onClose(); |
188 } else { | 202 } else { |
189 completer.complete(); | 203 completer.complete(); |
190 } | 204 } |
191 | 205 |
192 return completer.future; | 206 return completer.future; |
193 } | 207 } |
194 } | 208 } |
OLD | NEW |