diff options
author | bptato <nincsnevem662@gmail.com> | 2024-12-15 20:02:44 +0100 |
---|---|---|
committer | bptato <nincsnevem662@gmail.com> | 2024-12-15 20:07:29 +0100 |
commit | 29b7fa17be7ea8565e7a582f92e50e5107b8da08 (patch) | |
tree | 1a1515dfa73324806bc52650806457873c98893e /test/asserts.js | |
parent | 167f8f764974bfabbbf68a013218c90c9cdfac0b (diff) | |
download | chawan-29b7fa17be7ea8565e7a582f92e50e5107b8da08.tar.gz |
Unify assert.js for tests
judging from the symlink, I probably meant to do this but forgot to finish it
Diffstat (limited to 'test/asserts.js')
-rw-r--r-- | test/asserts.js | 16 |
1 files changed, 11 insertions, 5 deletions
diff --git a/test/asserts.js b/test/asserts.js index 6ef3033a..1d0cb6ca 100644 --- a/test/asserts.js +++ b/test/asserts.js @@ -4,20 +4,26 @@ function assert(x, msg) { throw new TypeError("Assertion failed" + mymsg); } -function assert_throws(expr, error) { +function assertThrows(expr, error) { + let me; try { eval(expr); } catch (e) { - if (e instanceof Error) + if (e instanceof error) return; + me = e; } - throw new TypeError("Assertion failed"); + throw new TypeError("Assertion failed: expected " + error + ", got " + me + " for expression: " + expr); } -function assert_equals(a, b) { +function assertEquals(a, b) { assert(a === b, "Expected " + b + " but got " + a); } -function assert_instanceof(a, b) { +function assertNotEquals(a, b) { + assert(a !== b, "Expected " + b + " to have some different value"); +} + +function assertInstanceof(a, b) { assert(a instanceof b, a + " not an instance of " + b); } |