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

Side by Side Diff: tests/async_helper.dart

Issue 16958006: Added async_helper and fixed broken asynchronous test. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 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 | Annotate | Revision Log
« no previous file with comments | « pkg/intl/test/intl_message_basic_example_test.dart ('k') | tests/html/indexeddb_2_test.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // BSD-style license that can be found in the LICENSE file.
4
5 /// This library is used for testing asynchronous tests.
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()
8 /// finished] even if the asynchronous operations fail).
9 /// Tests which can't use the unittest framework should use the helper functions
10 /// in this library.
11 /// This library provides two methods
12 /// - asyncStart(): Needs to be called before an asynchronous operation is
13 /// scheduled.
14 /// - asyncEnd(): Needs to be called as soon as the asynchronous operation
15 /// ended.
16 /// After the last asyncStart() called was matched with a corresponding
17 /// asyncEnd() call, the testing driver will be notified that the tests is done.
18
19 library async_helper;
20
21
22 bool _initialized = false;
23 int _asyncLevel = 0;
24
25 Exception _buildException(String msg) {
26 return new Exception('Fatal: $msg. This is most likely a bug in your test.');
27 }
28
29 void asyncStart() {
30 if (_initialized && _asyncLevel == 0) {
31 throw _buildException('asyncStart() was called even though we are done '
32 'with testing.');
33 }
34 if (!_initialized) {
35 print('unittest-suite-wait-for-done');
36 _initialized = true;
37 }
38 _asyncLevel++;
39 }
40
41 void asyncEnd() {
42 if (_asyncLevel <= 0) {
43 if (!_initialized) {
44 throw _buildException('asyncEnd() was called before asyncStart().');
45 } else {
46 throw _buildException('asyncEnd() was called more often than '
47 'asyncStart().');
48 }
49 }
50 _asyncLevel--;
51 if (_asyncLevel == 0) {
52 print('unittest-suite-done');
53 }
54 }
OLDNEW
« no previous file with comments | « pkg/intl/test/intl_message_basic_example_test.dart ('k') | tests/html/indexeddb_2_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698