mirror of
https://github.com/tc39/test262.git
synced 2025-10-21 15:53:50 +02:00
74 lines
2.4 KiB
JavaScript
74 lines
2.4 KiB
JavaScript
/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */
|
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
/*---
|
|
defines: [assertThrowsValue, assertThrownErrorContains, assertThrowsInstanceOfWithMessageCheck, assertThrowsInstanceOf]
|
|
allow_unused: True
|
|
---*/
|
|
|
|
(function() {
|
|
const undefined = void 0;
|
|
|
|
if (typeof globalThis.assertThrowsValue === 'undefined') {
|
|
globalThis.assertThrowsValue = function assertThrowsValue(f, val, msg) {
|
|
var fullmsg;
|
|
try {
|
|
f();
|
|
} catch (exc) {
|
|
if ((exc === val) === (val === val) && (val !== 0 || 1 / exc === 1 / val))
|
|
return;
|
|
fullmsg = "Assertion failed: expected exception " + val + ", got " + exc;
|
|
}
|
|
if (fullmsg === undefined)
|
|
fullmsg = "Assertion failed: expected exception " + val + ", no exception thrown";
|
|
if (msg !== undefined)
|
|
fullmsg += " - " + msg;
|
|
throw new Error(fullmsg);
|
|
};
|
|
}
|
|
|
|
if (typeof globalThis.assertThrownErrorContains === 'undefined') {
|
|
globalThis.assertThrownErrorContains = function assertThrownErrorContains(thunk, substr) {
|
|
try {
|
|
thunk();
|
|
} catch (e) {
|
|
// Do not test error messages
|
|
return;
|
|
}
|
|
throw new Error("Expected error containing " + substr + ", no exception thrown");
|
|
};
|
|
}
|
|
|
|
if (typeof globalThis.assertThrowsInstanceOfWithMessageCheck === 'undefined') {
|
|
globalThis.assertThrowsInstanceOfWithMessageCheck = function assertThrowsInstanceOfWithMessageCheck(f, ctor, check, msg) {
|
|
var fullmsg;
|
|
try {
|
|
f();
|
|
} catch (exc) {
|
|
if (!(exc instanceof ctor))
|
|
fullmsg = `Assertion failed: expected exception ${ctor.name}, got ${exc}`;
|
|
else {
|
|
// Do not test error messages
|
|
return;
|
|
}
|
|
}
|
|
|
|
if (fullmsg === undefined)
|
|
fullmsg = `Assertion failed: expected exception ${ctor.name}, no exception thrown`;
|
|
if (msg !== undefined)
|
|
fullmsg += " - " + msg;
|
|
|
|
throw new Error(fullmsg);
|
|
};
|
|
}
|
|
|
|
if (typeof globalThis.assertThrowsInstanceOf === 'undefined') {
|
|
globalThis.assertThrowsInstanceOf = function assertThrowsInstanceOf(f, ctor, msg) {
|
|
assertThrowsInstanceOfWithMessageCheck(f, ctor, _ => true, msg);
|
|
};
|
|
}
|
|
})();
|