Skip to content

Commit

Permalink
test/utils: support RegEx in HeliosTest.fails
Browse files Browse the repository at this point in the history
  • Loading branch information
Randall committed Sep 29, 2024
1 parent 916b8c3 commit 185c510
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 8 deletions.
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
31 changes: 24 additions & 7 deletions test/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import { Program } from "../src/program/Program.js"
* modules?: string[]
* inputs: UplcData[]
* output: HeliosTestOutput
* fails?: boolean | RegExp
* }} HeliosTest
*/

Expand All @@ -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)

Expand Down Expand Up @@ -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()
}
Expand Down

0 comments on commit 185c510

Please sign in to comment.