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 /// Helper utilities for testing. | 5 /// Helper utilities for testing. |
6 import "dart:async"; | 6 import "dart:async"; |
7 | 7 |
8 import "package:async/async.dart"; | 8 import "package:async/async.dart"; |
9 import "package:test/test.dart"; | 9 import "package:test/test.dart"; |
10 | 10 |
11 /// A zero-millisecond timer should wait until after all microtasks. | 11 /// A zero-millisecond timer should wait until after all microtasks. |
12 Future flushMicrotasks() => new Future.delayed(Duration.ZERO); | 12 Future flushMicrotasks() => new Future.delayed(Duration.ZERO); |
13 | 13 |
| 14 typedef void OptionalArgAction([a, b]); |
| 15 |
14 /// A generic unreachable callback function. | 16 /// A generic unreachable callback function. |
15 /// | 17 /// |
16 /// Returns a function that fails the test if it is ever called. | 18 /// Returns a function that fails the test if it is ever called. |
17 unreachable(String name) => ([a, b]) => fail("Unreachable: $name"); | 19 OptionalArgAction unreachable(String name) => |
| 20 ([a, b]) => fail("Unreachable: $name"); |
18 | 21 |
19 // TODO(nweiz): Use the version of this in test when test#418 is fixed. | 22 // TODO(nweiz): Use the version of this in test when test#418 is fixed. |
20 /// A matcher that runs a callback in its own zone and asserts that that zone | 23 /// A matcher that runs a callback in its own zone and asserts that that zone |
21 /// emits an error that matches [matcher]. | 24 /// emits an error that matches [matcher]. |
22 Matcher throwsZoned(matcher) => predicate((callback) { | 25 Matcher throwsZoned(matcher) => predicate((callback) { |
23 var firstError = true; | 26 var firstError = true; |
24 runZoned(callback, onError: expectAsync((error, stackTrace) { | 27 runZoned(callback, onError: expectAsync((error, stackTrace) { |
25 if (firstError) { | 28 if (firstError) { |
26 expect(error, matcher); | 29 expect(error, matcher); |
27 firstError = false; | 30 firstError = false; |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
99 stream.listen(add, onError: addError, onDone: completer.complete); | 102 stream.listen(add, onError: addError, onDone: completer.complete); |
100 return completer.future; | 103 return completer.future; |
101 } | 104 } |
102 | 105 |
103 Future close() { | 106 Future close() { |
104 _isClosed = true; | 107 _isClosed = true; |
105 _doneCompleter.complete(new Future.microtask(_onDone)); | 108 _doneCompleter.complete(new Future.microtask(_onDone)); |
106 return done; | 109 return done; |
107 } | 110 } |
108 } | 111 } |
OLD | NEW |