Index: test/mjsunit/mjsunit.js |
diff --git a/test/mjsunit/mjsunit.js b/test/mjsunit/mjsunit.js |
index 27f4d3942ad035fe9f743702381c7e6cff783737..9b07953c8aa22a24cd1386e1f212027dab0c7e2f 100644 |
--- a/test/mjsunit/mjsunit.js |
+++ b/test/mjsunit/mjsunit.js |
@@ -93,6 +93,10 @@ var assertNotNull; |
// to the type property on the thrown exception. |
var assertThrows; |
+// Assert that the passed function throws an exception. |
+// The exception is checked against the second argument using assertEquals. |
+var assertThrowsEquals; |
+ |
// Assert that the passed function or eval code does not throw an exception. |
var assertDoesNotThrow; |
@@ -353,6 +357,8 @@ var assertUnoptimized; |
} catch (e) { |
if (typeof type_opt === 'function') { |
assertInstanceof(e, type_opt); |
+ } else if (type_opt !== void 0) { |
+ fail("invalid use of assertThrows, maybe you want assertThrowsEquals"); |
} |
if (arguments.length >= 3) { |
assertEquals(e.type, cause_opt); |
@@ -364,6 +370,17 @@ var assertUnoptimized; |
}; |
+ assertThrowsEquals = function assertThrowsEquals(fun, val) { |
+ try { |
+ fun(); |
+ } catch(e) { |
+ assertEquals(val, e); |
+ return; |
+ } |
+ throw new MjsUnitAssertionError("Did not throw exception"); |
+ }; |
+ |
+ |
assertInstanceof = function assertInstanceof(obj, type) { |
if (!(obj instanceof type)) { |
var actualTypeName = null; |