diff options
author | Fabrice Bellard <fabrice@bellard.org> | 2025-04-05 18:05:15 +0200 |
---|---|---|
committer | Fabrice Bellard <fabrice@bellard.org> | 2025-04-05 18:06:08 +0200 |
commit | 159fe289e3b26727f7d85ce062689afb668230c1 (patch) | |
tree | 6f6fe163432c5320a38e4e817e6b0f9faeb09267 /tests | |
parent | c1bf4e99db34ab123a7da0cc6892aa5523ed406d (diff) | |
download | quickjs-159fe289e3b26727f7d85ce062689afb668230c1.tar.gz quickjs-159fe289e3b26727f7d85ce062689afb668230c1.zip |
fixed module cyclic imports (#329)
Diffstat (limited to 'tests')
-rw-r--r-- | tests/assert.js | 49 | ||||
-rw-r--r-- | tests/fixture_cyclic_import.js | 2 | ||||
-rw-r--r-- | tests/test_cyclic_import.js | 12 |
3 files changed, 63 insertions, 0 deletions
diff --git a/tests/assert.js b/tests/assert.js new file mode 100644 index 0000000..c8240c8 --- /dev/null +++ b/tests/assert.js @@ -0,0 +1,49 @@ +export function assert(actual, expected, message) { + if (arguments.length === 1) + expected = true; + + if (typeof actual === typeof expected) { + if (actual === expected) { + if (actual !== 0 || (1 / actual) === (1 / expected)) + return; + } + if (typeof actual === 'number') { + if (isNaN(actual) && isNaN(expected)) + return; + } + if (typeof actual === 'object') { + if (actual !== null && expected !== null + && actual.constructor === expected.constructor + && actual.toString() === expected.toString()) + return; + } + } + throw Error("assertion failed: got |" + actual + "|" + + ", expected |" + expected + "|" + + (message ? " (" + message + ")" : "")); +} + +export function assertThrows(err, func) +{ + var ex; + ex = false; + try { + func(); + } catch(e) { + ex = true; + assert(e instanceof err); + } + assert(ex, true, "exception expected"); +} + +export function assertArrayEquals(a, b) +{ + if (!Array.isArray(a) || !Array.isArray(b)) + return assert(false); + + assert(a.length, b.length); + + a.forEach((value, idx) => { + assert(b[idx], value); + }); +} diff --git a/tests/fixture_cyclic_import.js b/tests/fixture_cyclic_import.js new file mode 100644 index 0000000..bac80d8 --- /dev/null +++ b/tests/fixture_cyclic_import.js @@ -0,0 +1,2 @@ +import * as a from "./test_cyclic_import.js" +export function f(x) { return 2 * a.g(x) } diff --git a/tests/test_cyclic_import.js b/tests/test_cyclic_import.js new file mode 100644 index 0000000..bf51d9b --- /dev/null +++ b/tests/test_cyclic_import.js @@ -0,0 +1,12 @@ +/*--- +negative: + phase: resolution + type: SyntaxError +---*/ +// FIXME(bnoordhuis) shouldn't throw SyntaxError but that's still better +// than segfaulting, see https://github.com/quickjs-ng/quickjs/issues/567 +import {assert} from "./assert.js" +import {f} from "./fixture_cyclic_import.js" +export {f} +export function g(x) { return x + 1 } +assert(f(1), 4) |