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

Side by Side Diff: client/testing/unittest/unittestsuite.dart

Issue 8354006: Allow callbackDone while test is executed by runTest. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: '' Created 9 years, 2 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 | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 23 matching lines...) Expand all
34 /** 34 /**
35 * Whether an undetected error occurred while running the last test. This 35 * Whether an undetected error occurred while running the last test. This
36 * errors are commonly caused by DOM callbacks that were not guarded in a 36 * errors are commonly caused by DOM callbacks that were not guarded in a
37 * try-catch block. 37 * try-catch block.
38 */ 38 */
39 bool _uncaughtError; 39 bool _uncaughtError;
40 EventListener _onErrorClosure; 40 EventListener _onErrorClosure;
41 41
42 bool _queuedToRun = false; 42 bool _queuedToRun = false;
43 43
44 /** Whether a test is currently being executed by [runTest]. */
45 bool _testIsRunning = false;
46
44 // TODO(sigmund): remove isLayoutTest argument after converting all DOM tests 47 // TODO(sigmund): remove isLayoutTest argument after converting all DOM tests
45 // to use the named constructor below. 48 // to use the named constructor below.
46 // TODO(vsm): remove the ignoredWindow parameter once all tests are fixed. 49 // TODO(vsm): remove the ignoredWindow parameter once all tests are fixed.
47 UnitTestSuite([var ignoredWindow = null, bool isLayoutTest = false]) 50 UnitTestSuite([var ignoredWindow = null, bool isLayoutTest = false])
48 : _isLayoutTest = isLayoutTest, 51 : _isLayoutTest = isLayoutTest,
49 _tests = new List<TestCase>(), 52 _tests = new List<TestCase>(),
50 _currentTest = 0, 53 _currentTest = 0,
51 _callbacksCalled = 0 { 54 _callbacksCalled = 0 {
52 _onErrorClosure = (e) { _onError(e); }; 55 _onErrorClosure = (e) { _onError(e); };
53 if (_currentSuite != null) { 56 if (_currentSuite != null) {
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
151 testCase.recordError( 154 testCase.recordError(
152 "Can't call callbackDone() on a synchronous test", ''); 155 "Can't call callbackDone() on a synchronous test", '');
153 _uncaughtError = true; 156 _uncaughtError = true;
154 } else if (_callbacksCalled > testCase.callbacks) { 157 } else if (_callbacksCalled > testCase.callbacks) {
155 final expected = testCase.callbacks; 158 final expected = testCase.callbacks;
156 testCase.recordError( 159 testCase.recordError(
157 'More calls to callbackDone() than expected. ' 160 'More calls to callbackDone() than expected. '
158 + 'Actual: ${_callbacksCalled}, expected: ${expected}', ''); 161 + 'Actual: ${_callbacksCalled}, expected: ${expected}', '');
159 _uncaughtError = true; 162 _uncaughtError = true;
160 } else if (_callbacksCalled == testCase.callbacks) { 163 } else if (_callbacksCalled == testCase.callbacks) {
161 testCase.recordSuccess(); 164 testCase.recordSuccess();
Siggi Cherem (dart-lang) 2011/10/19 18:42:41 shouldn't this be inside the conditional too?
Anton Muhin 2011/10/19 18:51:58 I don't think so, but, please, double check: if te
Siggi Cherem (dart-lang) 2011/10/19 19:56:21 I think that might be covered in [runTests] also (
162 _currentTest++; 165 if (!_testIsRunning) {
163 _nextBatch(); 166 _currentTest++;
167 _nextBatch();
168 }
164 } 169 }
165 } 170 }
166 171
167 /** 172 /**
168 * Runs a batch of tests, yielding whenever an asynchronous test starts 173 * Runs a batch of tests, yielding whenever an asynchronous test starts
169 * running. Tests will resume executing when such asynchronous test calls 174 * running. Tests will resume executing when such asynchronous test calls
170 * [done] or if it fails with an exception. 175 * [done] or if it fails with an exception.
171 */ 176 */
172 void _nextBatch() { 177 void _nextBatch() {
173 while (_currentTest < _tests.length) { 178 while (_currentTest < _tests.length) {
174 final testCase = _tests[_currentTest]; 179 final testCase = _tests[_currentTest];
175 runTest(testCase); 180 runTest(testCase);
176 if (!testCase.isComplete() && testCase.callbacks > 0) { 181 if (!testCase.isComplete() && testCase.callbacks > 0) {
177 return; 182 return;
178 } 183 }
179 _currentTest++; 184 _currentTest++;
180 } 185 }
181 _completeTests(); 186 _completeTests();
182 } 187 }
183 188
184 /** Runs a single test. */ 189 /** Runs a single test. */
185 void runTest(TestCase testCase) { 190 void runTest(TestCase testCase) {
186 // TODO(sigmund): remove this declaration once dartc supports trapping error 191 // TODO(sigmund): remove this declaration once dartc supports trapping error
187 // traces. 192 // traces.
188 var trace = ''; 193 var trace = '';
189 _uncaughtError = false; 194 _uncaughtError = false;
190 _callbacksCalled = 0; 195 _callbacksCalled = 0;
191 try { 196 try {
197 _testIsRunning = true;
192 (testCase.test)(); 198 (testCase.test)();
193 if (!_uncaughtError) { 199 if (!_uncaughtError) {
194 if (testCase.callbacks == _callbacksCalled) { 200 if (testCase.callbacks == _callbacksCalled) {
195 testCase.recordSuccess(); 201 testCase.recordSuccess();
196 } 202 }
197 } 203 }
198 } catch (ExpectException e, var trace) { 204 } catch (ExpectException e, var trace) {
199 if (!_uncaughtError) { 205 if (!_uncaughtError) {
200 testCase.recordFail(e.message, trace.toString()); 206 testCase.recordFail(e.message, trace.toString());
201 } 207 }
202 } catch (var e, var trace) { 208 } catch (var e, var trace) {
203 if (!_uncaughtError) { 209 if (!_uncaughtError) {
204 testCase.recordError('Caught ${e}', trace.toString()); 210 testCase.recordError('Caught ${e}', trace.toString());
205 } 211 }
212 } finally {
213 _testIsRunning = false;
206 } 214 }
207 } 215 }
208 216
209 /** Publish results on the page and notify controller. */ 217 /** Publish results on the page and notify controller. */
210 void _completeTests() { 218 void _completeTests() {
211 try { 219 try {
212 window.dynamic.on.error.remove(_onErrorClosure); 220 window.dynamic.on.error.remove(_onErrorClosure);
213 } catch (var e) { 221 } catch (var e) {
214 // TODO(jacobr): remove this horrible hack to work around dartc bugs. 222 // TODO(jacobr): remove this horrible hack to work around dartc bugs.
215 window.dynamic.onerror = null; 223 window.dynamic.onerror = null;
(...skipping 302 matching lines...) Expand 10 before | Expand all | Expand 10 after
518 </tr>"""; 526 </tr>""";
519 if (stackTrace != null) { 527 if (stackTrace != null) {
520 message += 528 message +=
521 "<tr><td></td><td colspan='2'><pre>${stackTrace}</pre></td></tr>"; 529 "<tr><td></td><td colspan='2'><pre>${stackTrace}</pre></td></tr>";
522 } 530 }
523 fail = true; 531 fail = true;
524 } 532 }
525 } 533 }
526 534
527 typedef void TestFunction(); 535 typedef void TestFunction();
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698