From 185c510f78a0fdd44cf882365ad67dda7aa9e8a2 Mon Sep 17 00:00:00 2001 From: Randall Date: Sun, 29 Sep 2024 08:39:54 -0700 Subject: [PATCH] test/utils: support RegEx in HeliosTest.fails --- package.json | 4 +++- test/utils.js | 31 ++++++++++++++++++++++++------- 2 files changed, 27 insertions(+), 8 deletions(-) diff --git a/package.json b/package.json index e94e0ff9..04c76dc9 100644 --- a/package.json +++ b/package.json @@ -16,7 +16,9 @@ "test:pretty": "prettier . --check", "test:suite": "node --stack-trace-limit=50 --test", "test:types": "tsc -p jsconfig.json --noEmit", - "test:version": "node -e \"import('./src/index.js').then(m => {if (m.VERSION != process.env.npm_package_version) {throw new Error(\\\"version mismatch\\\")}})\"" + "test:version": "node -e \"import('./src/index.js').then(m => {if (m.VERSION != process.env.npm_package_version) {throw new Error(\\\"version mismatch\\\")}})\"", + "testing": "node --stack-trace-limit=50 --test --watch", + "testing:debug": "node --inspect-brk --stack-trace-limit=50 --test-concurrency=1 --test --watch" }, "repository": { "type": "git", diff --git a/test/utils.js b/test/utils.js index 81bbaaa9..4ba533d6 100644 --- a/test/utils.js +++ b/test/utils.js @@ -29,6 +29,7 @@ import { Program } from "../src/program/Program.js" * modules?: string[] * inputs: UplcData[] * output: HeliosTestOutput + * fails?: boolean | RegExp * }} HeliosTest */ @@ -54,13 +55,27 @@ export function compileAndRunMany(testVector) { */ export function compileAndRun(test) { it(test.description, () => { - const program = new Program(test.main, { - moduleSources: test.modules, - isTestnet: true - }) - - const uplc0 = program.compile(false) + const initialTest = () => { + const program = new Program(test.main, { + moduleSources: test.modules, + isTestnet: true + }) + const uplc0 = program.compile(false) + return [program, uplc0] + } + if (true == test.fails) { + throws(initialTest) + return + } else if (test.fails) { + // console.log("checking for failure message", test.fails) + // NOTE: node's test library doesn't seem to correctly check for throwing with string input + // ... despite claiming to do so. When it works, we can update the type of test.fails above + // ... to include string. Meanwhile, pass a RegExp to check for the error message. + throws(initialTest, test.fails) + return + } + const [program, uplc0] = initialTest() const args = test.inputs.map((d) => new UplcDataValue(d)) const result0 = uplc0.eval(args) @@ -227,8 +242,10 @@ export function evalTypes(test) { }) } - if (test.fails) { + if (true == typeof test.fails) { throws(construct) + } else if (test.fails) { + throws(construct, test.fails) } else { construct() }