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

Unified Diff: lib/unittest/expect.dart

Issue 10679005: Initial version of mocking support. There is still quite a bit of (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 years, 6 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | lib/unittest/mock.dart » ('j') | lib/unittest/mock.dart » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/unittest/expect.dart
===================================================================
--- lib/unittest/expect.dart (revision 9135)
+++ lib/unittest/expect.dart (working copy)
@@ -17,7 +17,9 @@
* If the assertion fails, then the default behavior is to throw an
* [ExpectException], but this behavior can be changed by calling
* [configureExpectHandler] and providing an alternative handler that
- * implements the [IFailureHandler] interface.
+ * implements the [IFailureHandler] interface. It is also possible to
+ * pass a [failureHandler] to [expect] as a final parameter for fine-
+ * grained control.
*
* expect() is a 3rd generation assertion mechanism, drawing
* inspiration from [Hamcrest] and Ladislav Thon's [dart-matchers]
@@ -27,7 +29,8 @@
* [Hamcrest] http://http://code.google.com/p/hamcrest/
* [dart-matchers] https://github.com/Ladicek/dart-matchers
*/
-void expect(actual, [matcher = isTrue, String reason = null]) {
+void expect(actual, [matcher = isTrue, String reason = null,
+ failureHandler = null]) {
matcher = wrapMatcher(matcher);
var doesMatch;
try {
@@ -39,9 +42,14 @@
}
}
if (!doesMatch) {
- // Make sure we have a failure handler configured.
- configureExpectHandler(_assertFailureHandler);
- _assertFailureHandler.failMatch(actual, matcher, reason);
+ if (failureHandler == null) {
+ // Make sure we have a failure handler configured.
+ if (_assertFailureHandler == null) {
+ configureExpectHandler();
+ }
+ failureHandler = _assertFailureHandler;
+ }
+ failureHandler.failMatch(actual, matcher, reason);
}
}
@@ -92,6 +100,13 @@
_assertFailureHandler = handler;
}
+FailureHandler getFailureHandler() {
Siggi Cherem (dart-lang) 2012/06/26 21:35:44 please use a getter, or change to getOrCreateFailu
gram 2012/06/26 23:39:59 Done.
+ if (_assertFailureHandler == null) {
+ configureExpectHandler();
+ }
+ return _assertFailureHandler;
+}
+
// The error message formatter for failed asserts.
ErrorFormatter _assertErrorFormatter = null;
« no previous file with comments | « no previous file | lib/unittest/mock.dart » ('j') | lib/unittest/mock.dart » ('J')

Powered by Google App Engine
This is Rietveld 408576698