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

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

Issue 2091173002: Add metadata to messages emitted by live tests. (Closed) Base URL: git@github.com:dart-lang/test@master
Patch Set: Created 4 years, 5 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/backend/live_test.dart ('k') | lib/src/backend/message.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 import 'dart:async'; 5 import 'dart:async';
6 import 'dart:collection'; 6 import 'dart:collection';
7 7
8 import 'package:stack_trace/stack_trace.dart'; 8 import 'package:stack_trace/stack_trace.dart';
9 9
10 import 'group.dart'; 10 import 'group.dart';
11 import 'live_test.dart'; 11 import 'live_test.dart';
12 import 'message.dart';
12 import 'state.dart'; 13 import 'state.dart';
13 import 'suite.dart'; 14 import 'suite.dart';
14 import 'test.dart'; 15 import 'test.dart';
15 16
16 /// An implementation of [LiveTest] that's controlled by a [LiveTestController]. 17 /// An implementation of [LiveTest] that's controlled by a [LiveTestController].
17 class _LiveTest extends LiveTest { 18 class _LiveTest extends LiveTest {
18 final LiveTestController _controller; 19 final LiveTestController _controller;
19 20
20 Suite get suite => _controller._suite; 21 Suite get suite => _controller._suite;
21 22
22 List<Group> get groups => _controller._groups; 23 List<Group> get groups => _controller._groups;
23 24
24 Test get test => _controller._test; 25 Test get test => _controller._test;
25 26
26 State get state => _controller._state; 27 State get state => _controller._state;
27 28
28 Stream<State> get onStateChange => 29 Stream<State> get onStateChange =>
29 _controller._onStateChangeController.stream; 30 _controller._onStateChangeController.stream;
30 31
31 List<AsyncError> get errors => new UnmodifiableListView(_controller._errors); 32 List<AsyncError> get errors => new UnmodifiableListView(_controller._errors);
32 33
33 Stream<AsyncError> get onError => _controller._onErrorController.stream; 34 Stream<AsyncError> get onError => _controller._onErrorController.stream;
34 35
35 Stream<String> get onPrint => _controller._onPrintController.stream; 36 Stream<Message> get onMessage => _controller._onMessageController.stream;
36 37
37 Future get onComplete => _controller.completer.future; 38 Future get onComplete => _controller.completer.future;
38 39
39 Future run() => _controller._run(); 40 Future run() => _controller._run();
40 41
41 Future close() => _controller._close(); 42 Future close() => _controller._close();
42 43
43 _LiveTest(this._controller); 44 _LiveTest(this._controller);
44 } 45 }
45 46
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
87 final _onStateChangeController = new StreamController<State> 88 final _onStateChangeController = new StreamController<State>
88 .broadcast(sync: true); 89 .broadcast(sync: true);
89 90
90 /// The controller for [LiveTest.onError]. 91 /// The controller for [LiveTest.onError].
91 /// 92 ///
92 /// This is synchronous to ensure that events are well-ordered across multiple 93 /// This is synchronous to ensure that events are well-ordered across multiple
93 /// streams. 94 /// streams.
94 final _onErrorController = new StreamController<AsyncError> 95 final _onErrorController = new StreamController<AsyncError>
95 .broadcast(sync: true); 96 .broadcast(sync: true);
96 97
97 /// The controller for [LiveTest.onPrint]. 98 /// The controller for [LiveTest.onMessage].
98 /// 99 ///
99 /// This is synchronous to ensure that events are well-ordered across multiple 100 /// This is synchronous to ensure that events are well-ordered across multiple
100 /// streams. 101 /// streams.
101 final _onPrintController = new StreamController<String>.broadcast(sync: true); 102 final _onMessageController =
103 new StreamController<Message>.broadcast(sync: true);
102 104
103 /// The completer for [LiveTest.onComplete]; 105 /// The completer for [LiveTest.onComplete];
104 final completer = new Completer(); 106 final completer = new Completer();
105 107
106 /// Whether [run] has been called. 108 /// Whether [run] has been called.
107 var _runCalled = false; 109 var _runCalled = false;
108 110
109 /// Whether [close] has been called. 111 /// Whether [close] has been called.
110 bool get _isClosed => _onErrorController.isClosed; 112 bool get _isClosed => _onErrorController.isClosed;
111 113
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
155 /// [LiveTest.state] and emits the new state via [LiveTest.onStateChanged]. If 157 /// [LiveTest.state] and emits the new state via [LiveTest.onStateChanged]. If
156 /// it's not different, this does nothing. 158 /// it's not different, this does nothing.
157 void setState(State newState) { 159 void setState(State newState) {
158 if (_isClosed) return; 160 if (_isClosed) return;
159 if (_state == newState) return; 161 if (_state == newState) return;
160 162
161 _state = newState; 163 _state = newState;
162 _onStateChangeController.add(newState); 164 _onStateChangeController.add(newState);
163 } 165 }
164 166
165 /// Emits a line printed by the test over [LiveTest.onPrint]. 167 /// Emits message over [LiveTest.onMessage].
166 void print(String line) { 168 void message(Message message) {
167 if (_onPrintController.hasListener) { 169 if (_onMessageController.hasListener) {
168 _onPrintController.add(line); 170 _onMessageController.add(message);
169 } else { 171 } else {
170 // Make sure all prints get surfaced one way or another to aid in 172 // Make sure all messages get surfaced one way or another to aid in
171 // debugging. 173 // debugging.
172 Zone.ROOT.print(line); 174 Zone.ROOT.print(message.text);
173 } 175 }
174 } 176 }
175 177
176 /// A wrapper for [_onRun] that ensures that it follows the guarantees for 178 /// A wrapper for [_onRun] that ensures that it follows the guarantees for
177 /// [LiveTest.run]. 179 /// [LiveTest.run].
178 Future _run() { 180 Future _run() {
179 if (_runCalled) { 181 if (_runCalled) {
180 throw new StateError("LiveTest.run() may not be called more than once."); 182 throw new StateError("LiveTest.run() may not be called more than once.");
181 } else if (_isClosed) { 183 } else if (_isClosed) {
182 throw new StateError("LiveTest.run() may not be called for a closed " 184 throw new StateError("LiveTest.run() may not be called for a closed "
(...skipping 14 matching lines...) Expand all
197 199
198 if (_runCalled) { 200 if (_runCalled) {
199 _onClose(); 201 _onClose();
200 } else { 202 } else {
201 completer.complete(); 203 completer.complete();
202 } 204 }
203 205
204 return completer.future; 206 return completer.future;
205 } 207 }
206 } 208 }
OLDNEW
« no previous file with comments | « lib/src/backend/live_test.dart ('k') | lib/src/backend/message.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698