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

Unified Diff: pkg/expect/lib/expect.dart

Issue 692463002: Make Expect.throws not accept arguments that fail to be called. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Don't call f. It might succeede through noSuchMethod. Created 6 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/expect/lib/expect.dart
diff --git a/pkg/expect/lib/expect.dart b/pkg/expect/lib/expect.dart
index 20d216f1a6020596e46531b46351ecd0b01b5bea..562af8d8c1936b4bbd1c482243b00c2d69afd949 100644
--- a/pkg/expect/lib/expect.dart
+++ b/pkg/expect/lib/expect.dart
@@ -346,19 +346,23 @@ class Expect {
static void throws(void f(),
[_CheckExceptionFn check = null,
String reason = null]) {
+ String msg = reason == null ? "" : "($reason)";
+ if (f is! _Nullary) {
+ // Only throws from executing the funtion body should count as throwing.
+ // The failure to even call `f` should throw outside the try/catch.
+ _fail("Expect.throws$msg: Funciton f not callable with zero arguments");
+ }
try {
f();
} catch (e, s) {
if (check != null) {
if (!check(e)) {
- String msg = reason == null ? "" : reason;
- _fail("Expect.throws($msg): Unexpected '$e'\n$s");
+ _fail("Expect.throws$msg: Unexpected '$e'\n$s");
}
}
return;
}
- String msg = reason == null ? "" : reason;
- _fail('Expect.throws($msg) fails');
+ _fail('Expect.throws$msg fails: Did not throw');
}
static String _getMessage(String reason)
@@ -372,6 +376,7 @@ class Expect {
bool _identical(a, b) => identical(a, b);
typedef bool _CheckExceptionFn(exception);
+typedef _Nullary(); // Expect.throws argument must be this type.
class ExpectException implements Exception {
ExpectException(this.message);
« 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