Commit e27ef0a6 authored by marja's avatar marja Committed by Commit bot

Fix mjsunit oddities (new try).

1) assertInstanceOf(o, Foo, Bar) used to produce this error message:

Failure: expected <o> is not an instance of <Foo> but of < Bar>> found <undefined>

Fixed:

Failure: <o> is not an instance of <Foo> but of <Bar>

2) assertDoesNotThrow("throw 1") used to produce this error message:

Failure: expected <threw an exception: > found <1>

Fixed:

Failure: threw an exception: 1

3) assertDoesNotThrow("...", SomeError) was not doing what you'd
think it does, so removed the last parameter.

BUG=

Review-Url: https://codereview.chromium.org/2424743003
Cr-Commit-Position: refs/heads/master@{#40347}
parent 6d266f00
......@@ -33,7 +33,7 @@ assertThrows("12 = 12", ReferenceError);
assertThrows("x++ = 12", ReferenceError);
assertThrows("eval('var x') = 12", ReferenceError);
assertThrows("if (false) 12 = 12", ReferenceError);
assertDoesNotThrow("if (false) eval('var x') = 12", ReferenceError);
assertDoesNotThrow("if (false) eval('var x') = 12");
// Pre- and post-fix operations:
assertThrows("12++", ReferenceError);
......@@ -46,20 +46,20 @@ assertThrows("if (false) 12++", ReferenceError);
assertThrows("if (false) 12--", ReferenceError);
assertThrows("if (false) ++12", ReferenceError);
assertThrows("if (false) --12", ReferenceError);
assertDoesNotThrow("if (false) ++(eval('12'))", ReferenceError);
assertDoesNotThrow("if (false) (eval('12'))++", ReferenceError);
assertDoesNotThrow("if (false) ++(eval('12'))");
assertDoesNotThrow("if (false) (eval('12'))++");
// For in:
assertThrows("for (12 in [1]) print(12);", SyntaxError);
assertThrows("for (eval('var x') in [1]) print(12);", ReferenceError);
assertThrows("if (false) for (12 in [1]) print(12);", SyntaxError);
assertDoesNotThrow("if (false) for (eval('0') in [1]) print(12);", ReferenceError);
assertDoesNotThrow("if (false) for (eval('0') in [1]) print(12);");
// For:
assertThrows("for (12 = 1;;) print(12);", ReferenceError);
assertThrows("for (eval('var x') = 1;;) print(12);", ReferenceError);
assertThrows("if (false) for (12 = 1;;) print(12);", ReferenceError);
assertDoesNotThrow("if (false) for (eval('var x') = 1;;) print(12);", ReferenceError);
assertDoesNotThrow("if (false) for (eval('var x') = 1;;) print(12);");
// Assignments to 'this'.
assertThrows("this = 42", ReferenceError);
......
......@@ -204,6 +204,11 @@ var assertMatches;
}
function failWithMessage(message) {
throw new MjsUnitAssertionError(message);
}
function fail(expectedText, found, name_opt) {
var message = "Fail" + "ure";
if (name_opt) {
......@@ -364,7 +369,7 @@ var assertMatches;
if (typeof type_opt === 'function') {
assertInstanceof(e, type_opt);
} else if (type_opt !== void 0) {
fail("invalid use of assertThrows, maybe you want assertThrowsEquals");
failWithMessage("invalid use of assertThrows, maybe you want assertThrowsEquals");
}
if (arguments.length >= 3) {
assertEquals(e.type, cause_opt);
......@@ -372,7 +377,7 @@ var assertMatches;
// Success.
return;
}
throw new MjsUnitAssertionError("Did not throw exception");
failWithMessage("Did not throw exception");
};
......@@ -383,7 +388,7 @@ var assertMatches;
assertEquals(val, e);
return;
}
throw new MjsUnitAssertionError("Did not throw exception");
failWithMessage("Did not throw exception");
};
......@@ -394,9 +399,9 @@ var assertMatches;
if (typeof actualConstructor === "function") {
actualTypeName = actualConstructor.name || String(actualConstructor);
}
fail("Object <" + PrettyPrint(obj) + "> is not an instance of <" +
failWithmessage("Object <" + PrettyPrint(obj) + "> is not an instance of <" +
(type.name || type) + ">" +
(actualTypeName ? " but of < " + actualTypeName + ">" : ""));
(actualTypeName ? " but of <" + actualTypeName + ">" : ""));
}
};
......@@ -409,7 +414,7 @@ var assertMatches;
eval(code);
}
} catch (e) {
fail("threw an exception: ", e.message || e, name_opt);
failWithMessage("threw an exception: " + (e.message || e));
}
};
......@@ -419,7 +424,7 @@ var assertMatches;
if (name_opt) {
message += " - " + name_opt;
}
throw new MjsUnitAssertionError(message);
failWithMessage(message);
};
assertContains = function(sub, value, name_opt) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment