Test Library
The test library is an augmented standard library, it contains all definitions in the standard library plus some additional modules and functions which help testing packages more thoroughly and debug regressions.
It defines the following modules:
test: a module with various testing helpers such ascatchand additional asserts.
The following items are re-exported in the global scope as well:
assert-panic: originallytest.assert-paniccatch: originallytest.catch
test
Contains the main testing utilities.
assert-panic
Ensures that a function panics.
Panics if the function does not panic, returns none otherwise.
Example
// panics with the given message
#assert-panic(() => {}, message: "Function did not panic!")
// catches the panic and keeps compilation running
#assert-panic(() => panic())
Parameters
assert-panic(
function,
message: str | auto,
)
function: function
requiredpositionalThe function to test.
message: str | autoThe error message when the assertion fails.
catch
Returns the panic message generated by a function, if there was any, returns none otherwise.
Example
#assert.eq(catch(() => {}), none)
#assert.eq(
catch(panics),
"panicked with: Invalid arg, expected `int`, got `str`",
)
Parameters
catch(
function,
)
function: function
requiredpositionalThe function to test.