OLD | NEW |
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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 /// This library is used for testing asynchronous tests. | 5 /// This library is used for testing asynchronous tests. |
6 /// If a test is asynchronous, it needs to notify the testing driver | 6 /// If a test is asynchronous, it needs to notify the testing driver |
7 /// about this (otherwise tests may get reported as passing [after main() | 7 /// about this (otherwise tests may get reported as passing [after main() |
8 /// finished] even if the asynchronous operations fail). | 8 /// finished] even if the asynchronous operations fail). |
9 /// Tests which can't use the unittest framework should use the helper functions | 9 /// Tests which can't use the unittest framework should use the helper functions |
10 /// in this library. | 10 /// in this library. |
11 /// This library provides four methods | 11 /// This library provides four methods |
12 /// - asyncStart(): Needs to be called before an asynchronous operation is | 12 /// - asyncStart(): Needs to be called before an asynchronous operation is |
13 /// scheduled. | 13 /// scheduled. |
14 /// - asyncEnd(): Needs to be called as soon as the asynchronous operation | 14 /// - asyncEnd(): Needs to be called as soon as the asynchronous operation |
15 /// ended. | 15 /// ended. |
16 /// - asyncSuccess(_): Variant of asyncEnd useful together with Future.then. | 16 /// - asyncSuccess(_): Variant of asyncEnd useful together with Future.then. |
17 /// - asyncTest(f()): Helper method that wraps a computation that returns a | 17 /// - asyncTest(f()): Helper method that wraps a computation that returns a |
18 /// Future with matching calls to asyncStart() and | 18 /// Future with matching calls to asyncStart() and |
19 /// asyncSuccess(_). | 19 /// asyncSuccess(_). |
20 /// After the last asyncStart() called was matched with a corresponding | 20 /// After the last asyncStart() called was matched with a corresponding |
21 /// asyncEnd() or asyncSuccess(_) call, the testing driver will be notified that | 21 /// asyncEnd() or asyncSuccess(_) call, the testing driver will be notified that |
22 /// the tests is done. | 22 /// the tests is done. |
23 | 23 |
24 library async_helper; | 24 library async_helper; |
25 | 25 |
26 // TODO(kustermann): This is problematic because we rely on a working | 26 // TODO(kustermann): This is problematic because we rely on a working |
27 // 'dart:isolate' (i.e. it is in particular problematic with dart2js). | 27 // 'dart:isolate' (i.e. it is in particular problematic with dart2js). |
28 // It would be nice if we could use a different mechanism for different | 28 // It would be nice if we could use a different mechanism for different |
29 // runtimes. | 29 // runtimes. |
30 import 'dart:fletch'; | 30 import 'dart:dartino'; |
31 | 31 |
32 bool _initialized = false; | 32 bool _initialized = false; |
33 Port _port = null; | 33 Port _port = null; |
34 int _asyncLevel = 0; | 34 int _asyncLevel = 0; |
35 | 35 |
36 Exception _buildException(String msg) { | 36 Exception _buildException(String msg) { |
37 return new Exception('Fatal: $msg. This is most likely a bug in your test.'); | 37 return new Exception('Fatal: $msg. This is most likely a bug in your test.'); |
38 } | 38 } |
39 | 39 |
40 void _waitForMessage(Port port) { | 40 void _waitForMessage(Port port) { |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
94 | 94 |
95 /** | 95 /** |
96 * Helper method for performing asynchronous tests involving [:Future:]. | 96 * Helper method for performing asynchronous tests involving [:Future:]. |
97 * | 97 * |
98 * [f] must return a [:Future:] for the test computation. | 98 * [f] must return a [:Future:] for the test computation. |
99 */ | 99 */ |
100 void asyncTest(f()) { | 100 void asyncTest(f()) { |
101 asyncStart(); | 101 asyncStart(); |
102 f().then(asyncSuccess); | 102 f().then(asyncSuccess); |
103 } | 103 } |
OLD | NEW |