Index: lib/unittest/unittest.dart |
=================================================================== |
--- lib/unittest/unittest.dart (revision 8218) |
+++ lib/unittest/unittest.dart (working copy) |
@@ -5,19 +5,19 @@ |
/** |
* A library for writing dart unit tests. |
* |
- * To import this library, specify the relative path to |
+ * To import this library, specify the relative path to |
* lib/unittest/unittest.dart. |
* |
* ##Concepts## |
* |
* * Tests: Tests are specified via the top-level function [test], they can be |
* organized together using [group]. |
- * * Checks: Test expectations can be specified via [expect] (see methods in |
- * [Expectation]), [expectThrow], or using assertions with the [Expect] |
- * class. |
+ * * Checks: Test expectations can be specified via [expect] |
* * Configuration: The framework can be adapted by calling [configure] with a |
* [Configuration]. Common configurations can be found in this package |
- * under: 'dom\_config.dart', 'html\_config.dart', and 'vm\_config.dart'. |
+ * under: 'dom\_config.dart', 'html\_config.dart', and 'vm\_config.dart'. 20 * under: 'dom\_config.dart' (deprecated), 'html\_config.dart' (for running |
+ * tests compiled to Javascript in a browser), and 'vm\_config.dart' (for |
+ * running native Dart tests on the VM). |
* |
* ##Examples## |
* |
@@ -67,7 +67,11 @@ |
* }); |
* } |
* |
- * Asynchronous tests: if callbacks expect between 0 and 2 positional arguments. |
+ * Asynchronous tests: if callbacks expect between 0 and 2 positional arguments, |
+ * depending on the suffix of expectAsyncX(). expectAsyncX() will wrap a |
+ * function into a new callback and will not consider the test complete until |
+ * that callback is run. A count argument can be provided to specify the number |
+ * of times the callback should be called (the default is 1). |
* |
* #import('path-to-dart/lib/unittest/unitest.dart'); |
* #import('dart:dom_deprecated'); |
@@ -91,6 +95,14 @@ |
* }); |
* } |
* |
+ * expectAsyncX() will wrap the callback code in a try/catch handler to handle |
+ * exceptions (treated as test failures). There may be times when the number of |
+ * times a callback should be called is non-deterministic. In this case a dummy |
+ * callback can be created with expectAsync0((){}) and this can be called from |
+ * the real callback when it is finally complete. In this case the body of the |
+ * callback should be protected within a call to guardAsync(); this will ensure |
+ * that exceptions are properly handled. |
+ * |
* Note: due to some language limitations we have to use different functions |
* depending on the number of positional arguments of the callback. In the |
* future, we plan to expose a single `expectAsync` function that can be used |
@@ -125,8 +137,17 @@ |
#import('dart:isolate'); |
+#source('collection_matchers.dart'); |
#source('config.dart'); |
-#source('expectation.dart'); |
+#source('core_matchers.dart'); |
+#source('description.dart'); |
+#source('expect.dart'); |
+#source('interfaces.dart'); |
+#source('map_matchers.dart'); |
+#source('matcher.dart'); |
+#source('numeric_matchers.dart'); |
+#source('operator_matchers.dart'); |
+#source('string_matchers.dart'); |
#source('test_case.dart'); |
/** [Configuration] used by the unittest library. */ |
@@ -179,9 +200,6 @@ |
/** If set, then all other test cases will be ignored. */ |
TestCase _soloTest; |
-/** Creates an expectation for the given value. */ |
-Expectation expect(value) => new Expectation(value); |
- |
/** |
* Evaluates the [function] and validates that it throws an exception. If |
* [callback] is provided, then it will be invoked with the thrown exception. |
@@ -334,7 +352,7 @@ |
calls++; |
if (calls > expectedCalls) { |
testCase.error( |
- 'Callback called more times than expected ($expectedCalls)', |
+ 'Callback called more times than expected ($calls > $expectedCalls)', |
''); |
_state = _UNCAUGHT_ERROR; |
return false; |
@@ -408,8 +426,8 @@ |
/** Called by subclasses to indicate that an asynchronous test completed. */ |
void callbackDone() { |
// TODO (gram): we defer this to give the nextBatch recursive |
- // stack a chance to unwind. This is a temporary hack but |
- // really a bunch of code here needs to be fixed. We have a |
+ // stack a chance to unwind. This is a temporary hack but |
+ // really a bunch of code here needs to be fixed. We have a |
// single array that is being iterated through by nextBatch(), |
// which is recursively invoked in the case of async tests that |
// run synchronously. Bad things can then happen. |
@@ -425,7 +443,9 @@ |
_state = _UNCAUGHT_ERROR; |
} else if ((_callbacksCalled == testCase.callbacks) && |
(_state != _RUNNING_TEST)) { |
- if (testCase.result == null) testCase.pass(); |
+ if (testCase.result == null) { |
+ testCase.pass(); |
+ } |
_currentTest++; |
_testRunner(); |
} |
@@ -433,7 +453,10 @@ |
}); |
} |
-/** Menchanism to notify that an error was caught outside of this library. */ |
+/** |
+ * Utility function that can be used to notify the test framework that an |
+ * error was caught outside of this library. |
+ */ |
void reportTestError(String msg, String trace) { |
if (_currentTest < _tests.length) { |
final testCase = _tests[_currentTest]; |