Chromium Code Reviews| Index: test/intl/assert.js | 
| diff --git a/test/intl/assert.js b/test/intl/assert.js | 
| index 3180e6f96e69db62c56f8eb7564bead6e9155a2d..4727f0f5a7ad8b07018042b798f4dd1d11ac00bd 100644 | 
| --- a/test/intl/assert.js | 
| +++ b/test/intl/assert.js | 
| @@ -87,14 +87,13 @@ function deepEquals(a, b) { | 
| return deepObjectEquals(a, b); | 
| } | 
| - | 
| /** | 
| - * Throws an exception, and prints the values in case of error. | 
| + * Throws an exception containing the user_message (if any) and the values. | 
| */ | 
| -function fail(expected, found) { | 
| +function fail(expected, found, user_message = '') { | 
| // TODO(cira): Replace String with PrettyPrint for objects and arrays. | 
| - var message = 'Failure: expected <' + String(expected) + '>, found <' + | 
| - String(found) + '>.'; | 
| + var message = 'Failure' + (user_message ? ' (' + user_message + ')' : "") + | 
| 
 
JF
2016/04/06 17:00:20
Mixing single and double quotes is odd :-)
 
Clemens Hammacher
2016/04/07 07:42:52
Done.
 
 | 
| + ': expected <' + String(expected) + '>, found <' + String(found) + '>.'; | 
| throw new Error(message); | 
| } | 
| @@ -102,9 +101,9 @@ function fail(expected, found) { | 
| /** | 
| * Throws if two variables have different types or values. | 
| */ | 
| -function assertEquals(expected, found) { | 
| +function assertEquals(expected, found, user_message = '') { | 
| if (!deepEquals(expected, found)) { | 
| - fail(expected, found); | 
| + fail(expected, found, user_message); | 
| } | 
| } | 
| @@ -112,21 +111,21 @@ function assertEquals(expected, found) { | 
| /** | 
| * Throws if value is false. | 
| */ | 
| -function assertTrue(value) { | 
| - assertEquals(true, value) | 
| +function assertTrue(value, user_message = '') { | 
| + assertEquals(true, value, user_message); | 
| } | 
| /** | 
| * Throws if value is true. | 
| */ | 
| -function assertFalse(value) { | 
| - assertEquals(false, value); | 
| +function assertFalse(value, user_message = '') { | 
| + assertEquals(false, value, user_message); | 
| } | 
| /** | 
| - * Returns true if code throws specified exception. | 
| + * Returns if the code throws the specified exception, throws otherwise. | 
| 
 
titzer
2016/04/06 18:22:10
You can just reword to "Runs {code} and asserts th
 
Clemens Hammacher
2016/04/07 07:42:52
Done.
 
 | 
| */ | 
| function assertThrows(code, type_opt, cause_opt) { | 
| var threwException = true; | 
| 
 
titzer
2016/04/06 18:22:10
I just noticed this variable is dead.
 
Clemens Hammacher
2016/04/07 07:42:52
Right, I will remove it.
 
 | 
| @@ -142,19 +141,21 @@ function assertThrows(code, type_opt, cause_opt) { | 
| assertInstanceof(e, type_opt); | 
| } | 
| if (arguments.length >= 3) { | 
| - assertEquals(e.type, cause_opt); | 
| + assertEquals(cause_opt, e.type, 'thrown exception type mismatch'); | 
| } | 
| // Success. | 
| return; | 
| } | 
| - throw new Error("Did not throw exception"); | 
| + var expected = arguments.length >= 3 ? cause_opt : | 
| + typeof type_opt == 'function' ? type_opt : 'any exception'; | 
| + fail(expected, "no exception", "expected thrown exception"); | 
| } | 
| /** | 
| * Throws an exception if code throws. | 
| 
 
titzer
2016/04/06 18:22:10
You can reword this similarly. "Runs {code} and as
 
Clemens Hammacher
2016/04/07 07:42:52
Done.
 
 | 
| */ | 
| -function assertDoesNotThrow(code, name_opt) { | 
| +function assertDoesNotThrow(code, user_message = '') { | 
| try { | 
| if (typeof code == 'function') { | 
| code(); | 
| @@ -162,7 +163,7 @@ function assertDoesNotThrow(code, name_opt) { | 
| eval(code); | 
| } | 
| } catch (e) { | 
| - fail("threw an exception: ", e.message || e, name_opt); | 
| + fail("no expection", "exception: " + String(e), user_message); | 
| } | 
| } |