Closed OAGr closed 1 month ago
I wanted to add throw checking code to sTest
, but couldn't, because of this.
toThrowAnyError: {
||
if fnThrewError(
actual
) then true else "Expected to throw an error, but no error was thrown"
},
toNotThrow: {
||
if !fnThrewError(
actual
) then true else "Expected not to throw an error, but an error was thrown"
},
errorTests = describe(
"Error Throwing Tests",
[
test(
"throws any error",
{|| expect({|| throw("SomeError")}).toThrowAnyError()}
),
test("doesn't throw any error", {|| expect({|| 2 + 2}).toNotThrow()}),
test(
"fails when expecting an error but none is thrown",
{|| expect({|| 2 + 2}).toThrowAnyError()}
),
test(
"fails when expecting no error but one is thrown",
{|| expect({|| throw("UnexpectedError")}).toNotThrow()}
),
]
)
Yeah, try(...)
doesn't unwind the stack properly, minimal example where this is visible in the stacktrace:
Description of suggestion or shortcoming:
I'm trying to write tests, in Squiggle, using sTest, to flag if an error was caught or not.
The problem is that when doing that, I'm getting a weird error.
See this. The badExample fails with a
JS Exception: Error: Internal error: invalid capture id 1
error.This seems like an interpreter thing. The LLMs like using try/catch in testing a lot, so this breaks a bunch of tests.
Depends on https://github.com/quantified-uncertainty/squiggle/issues/3391