OLD | NEW |
---|---|
1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, 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 // TODO(rnystrom): This code is gradually moving from a Java/JUnit style to | 5 // TODO(rnystrom): This code is gradually moving from a Java/JUnit style to |
6 // something closer to JS/Jasmine. Eventually, the UnitTestSuite class can go | 6 // something closer to JS/Jasmine. Eventually, the UnitTestSuite class can go |
7 // away completely (or become private to this library) and the only exposed API | 7 // away completely (or become private to this library) and the only exposed API |
8 // will be group()/test()/expect(). Until then, both ways are supported, which | 8 // will be group()/test()/expect(). Until then, both ways are supported, which |
9 // is why things look a bit weird in here. | 9 // is why things look a bit weird in here. |
10 | 10 |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
109 } | 109 } |
110 } | 110 } |
111 | 111 |
112 /** Enqueues an asynchronous test that waits for [callbacks] callbacks. */ | 112 /** Enqueues an asynchronous test that waits for [callbacks] callbacks. */ |
113 void addAsyncTest(TestFunction body, int callbacks) { | 113 void addAsyncTest(TestFunction body, int callbacks) { |
114 asyncTest(null, callbacks, body); | 114 asyncTest(null, callbacks, body); |
115 } | 115 } |
116 | 116 |
117 /** Runs all queued tests, one at a time. */ | 117 /** Runs all queued tests, one at a time. */ |
118 void runTests() { | 118 void runTests() { |
119 window.dynamic/*TODO(5389254)*/.postMessage('unittest-suite-start', '*'); | 119 window.postMessage('unittest-suite-start', '*'); |
120 // Isolate.bind makes sure the closure runs in the same isolate (i.e. this | 120 window.setTimeout(() { |
121 // one) where it has been created. | |
122 window.setTimeout(Isolate.bind(() { | |
123 assert (_currentTest == 0); | 121 assert (_currentTest == 0); |
124 // Listen for uncaught errors (see [_uncaughtError]). | 122 // Listen for uncaught errors (see [_uncaughtError]). |
125 // TODO(jacobr): remove this horrible hack when dartc bugs are fixed. | 123 // TODO(jacobr): remove this horrible hack when dartc bugs are fixed. |
126 try { | 124 try { |
127 window.dynamic.on.error.add(_onErrorClosure); | 125 window.dynamic.on.error.add(_onErrorClosure); |
128 } catch(var e) { | 126 } catch(var e) { |
129 window.dynamic.onerror = _onErrorClosure; | 127 window.dynamic.onerror = _onErrorClosure; |
130 } | 128 } |
131 _nextBatch(); | 129 _nextBatch(); |
132 }), 0); | 130 }, 0); |
Siggi Cherem (dart-lang)
2011/10/26 19:45:38
<< (fix indent)
| |
133 } | 131 } |
134 | 132 |
135 void _onError(e) { | 133 void _onError(e) { |
136 if (_currentTest < _tests.length) { | 134 if (_currentTest < _tests.length) { |
137 final testCase = _tests[_currentTest]; | 135 final testCase = _tests[_currentTest]; |
138 // TODO(vsm): figure out how to expose the stack trace here | 136 // TODO(vsm): figure out how to expose the stack trace here |
139 // Currently e.message works in dartium, but not in dartc. | 137 // Currently e.message works in dartium, but not in dartc. |
140 testCase.recordError('(DOM callback has errors) Caught ${e}', ''); | 138 testCase.recordError('(DOM callback has errors) Caught ${e}', ''); |
141 _uncaughtError = true; | 139 _uncaughtError = true; |
142 if (testCase.callbacks > 0) { | 140 if (testCase.callbacks > 0) { |
(...skipping 381 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
524 </tr>"""; | 522 </tr>"""; |
525 if (stackTrace != null) { | 523 if (stackTrace != null) { |
526 message += | 524 message += |
527 "<tr><td></td><td colspan='2'><pre>${stackTrace}</pre></td></tr>"; | 525 "<tr><td></td><td colspan='2'><pre>${stackTrace}</pre></td></tr>"; |
528 } | 526 } |
529 fail = true; | 527 fail = true; |
530 } | 528 } |
531 } | 529 } |
532 | 530 |
533 typedef void TestFunction(); | 531 typedef void TestFunction(); |
OLD | NEW |