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

Side by Side Diff: pkg/unittest/lib/unittest.dart

Issue 12393017: Fix issue with async callbacks that get called synchronously while running test case function causi… (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 years, 9 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/unittest/lib/src/test_case.dart ('k') | pkg/unittest/test/unittest_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
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 /** 5 /**
6 * A library for writing dart unit tests. 6 * A library for writing dart unit tests.
7 * 7 *
8 * To import this library, use the pub package manager. 8 * To import this library, use the pub package manager.
9 * Create a pubspec.yaml file in your project and add 9 * Create a pubspec.yaml file in your project and add
10 * a dependency on unittest with the following lines: 10 * a dependency on unittest with the following lines:
(...skipping 344 matching lines...) Expand 10 before | Expand all | Expand 10 after
355 } 355 }
356 356
357 shouldCallBack() { 357 shouldCallBack() {
358 ++actualCalls; 358 ++actualCalls;
359 if (testCase.isComplete) { 359 if (testCase.isComplete) {
360 // Don't run if the test is done. We don't throw here as this is not 360 // Don't run if the test is done. We don't throw here as this is not
361 // the current test, but we do mark the old test as having an error 361 // the current test, but we do mark the old test as having an error
362 // if it previously passed. 362 // if it previously passed.
363 if (testCase.result == PASS) { 363 if (testCase.result == PASS) {
364 testCase.error( 364 testCase.error(
365 'Callback ${id}called after test case ${testCase.description} ' 365 'Callback ${id}called ($actualCalls) after test case '
366 'has already been marked as done.', ''); 366 '${testCase.description} has already been marked as '
367 '${testCase.result}.', '');
367 } 368 }
368 return false; 369 return false;
369 } else if (maxExpectedCalls >= 0 && actualCalls > maxExpectedCalls) { 370 } else if (maxExpectedCalls >= 0 && actualCalls > maxExpectedCalls) {
370 throw new TestFailure('Callback ${id}called more times than expected ' 371 throw new TestFailure('Callback ${id}called more times than expected '
371 '($maxExpectedCalls).'); 372 '($maxExpectedCalls).');
372 } 373 }
373 return true; 374 return true;
374 } 375 }
375 376
376 after() { 377 after() {
377 if (!complete) { 378 if (!complete) {
378 if (minExpectedCalls > 0 && actualCalls < minExpectedCalls) return; 379 if (minExpectedCalls > 0 && actualCalls < minExpectedCalls) return;
379 if (isDone != null && !isDone()) return; 380 if (isDone != null && !isDone()) return;
380 381
381 // Mark this callback as complete and remove it from the testcase 382 // Mark this callback as complete and remove it from the testcase
382 // oustanding callback count; if that hits zero the testcase is done. 383 // oustanding callback count; if that hits zero the testcase is done.
383 complete = true; 384 complete = true;
384 if (--testCase.callbackFunctionsOutstanding == 0 && 385 testCase.markCallbackComplete();
385 !testCase.isComplete) {
386 testCase.pass();
387 }
388 } 386 }
389 } 387 }
390 388
391 invoke([arg0 = sentinel, arg1 = sentinel, arg2 = sentinel, 389 invoke([arg0 = sentinel, arg1 = sentinel, arg2 = sentinel,
392 arg3 = sentinel, arg4 = sentinel]) { 390 arg3 = sentinel, arg4 = sentinel]) {
393 return guardAsync(() { 391 return guardAsync(() {
394 if (!shouldCallBack()) { 392 if (!shouldCallBack()) {
395 return; 393 return;
396 } else if (arg0 == sentinel) { 394 } else if (arg0 == sentinel) {
397 return callback(); 395 return callback();
(...skipping 406 matching lines...) Expand 10 before | Expand all | Expand 10 after
804 802
805 /** 803 /**
806 * Lazily initializes the test library if not already initialized. 804 * Lazily initializes the test library if not already initialized.
807 */ 805 */
808 void ensureInitialized() { 806 void ensureInitialized() {
809 if (_initialized) { 807 if (_initialized) {
810 return; 808 return;
811 } 809 }
812 _initialized = true; 810 _initialized = true;
813 // Hook our async guard into the matcher library. 811 // Hook our async guard into the matcher library.
814 wrapAsync = expectAsync1; 812 wrapAsync = (f, [id]) => expectAsync1(f, id: id);
815 813
816 _tests = <TestCase>[]; 814 _tests = <TestCase>[];
817 _testRunner = _nextBatch; 815 _testRunner = _nextBatch;
818 _uncaughtErrorMessage = null; 816 _uncaughtErrorMessage = null;
819 817
820 if (_config == null) { 818 if (_config == null) {
821 _config = new Configuration(); 819 _config = new Configuration();
822 } 820 }
823 _config.onInit(); 821 _config.onInit();
824 822
(...skipping 30 matching lines...) Expand all
855 } 853 }
856 854
857 /** Enable a test by ID. */ 855 /** Enable a test by ID. */
858 void enableTest(int testId) => _setTestEnabledState(testId, true); 856 void enableTest(int testId) => _setTestEnabledState(testId, true);
859 857
860 /** Disable a test by ID. */ 858 /** Disable a test by ID. */
861 void disableTest(int testId) => _setTestEnabledState(testId, false); 859 void disableTest(int testId) => _setTestEnabledState(testId, false);
862 860
863 /** Signature for a test function. */ 861 /** Signature for a test function. */
864 typedef dynamic TestFunction(); 862 typedef dynamic TestFunction();
OLDNEW
« no previous file with comments | « pkg/unittest/lib/src/test_case.dart ('k') | pkg/unittest/test/unittest_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698