| 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'; |
| (...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 152 } | 152 } |
| 153 | 153 |
| 154 /// Emits a line printed by the test over [LiveTest.onPrint]. | 154 /// Emits a line printed by the test over [LiveTest.onPrint]. |
| 155 void print(String line) => _onPrintController.add(line); | 155 void print(String line) => _onPrintController.add(line); |
| 156 | 156 |
| 157 /// A wrapper for [_onRun] that ensures that it follows the guarantees for | 157 /// A wrapper for [_onRun] that ensures that it follows the guarantees for |
| 158 /// [LiveTest.run]. | 158 /// [LiveTest.run]. |
| 159 Future _run() { | 159 Future _run() { |
| 160 if (_runCalled) { | 160 if (_runCalled) { |
| 161 throw new StateError("LiveTest.run() may not be called more than once."); | 161 throw new StateError("LiveTest.run() may not be called more than once."); |
| 162 } else if (_isClosed) { |
| 163 throw new StateError("LiveTest.run() may not be called for a closed " |
| 164 "test."); |
| 162 } | 165 } |
| 163 _runCalled = true; | 166 _runCalled = true; |
| 164 | 167 |
| 165 _onRun(); | 168 _onRun(); |
| 166 return liveTest.onComplete; | 169 return liveTest.onComplete; |
| 167 } | 170 } |
| 168 | 171 |
| 169 /// A wrapper for [_onClose] that ensures that all controllers are closed. | 172 /// A wrapper for [_onClose] that ensures that all controllers are closed. |
| 170 Future _close() { | 173 Future _close() { |
| 171 if (_isClosed) return completer.future; | 174 if (_isClosed) return completer.future; |
| 172 | 175 |
| 173 _onStateChangeController.close(); | 176 _onStateChangeController.close(); |
| 174 _onErrorController.close(); | 177 _onErrorController.close(); |
| 175 | 178 |
| 176 if (_runCalled) { | 179 if (_runCalled) { |
| 177 _onClose(); | 180 _onClose(); |
| 178 } else { | 181 } else { |
| 179 completer.complete(); | 182 completer.complete(); |
| 180 } | 183 } |
| 181 | 184 |
| 182 return completer.future; | 185 return completer.future; |
| 183 } | 186 } |
| 184 } | 187 } |
| OLD | NEW |