Testing
Mark functions with @test and run xs test. Assertions are built in. No test framework to install.
@test attribute
Decorate any function with @test (or equivalently #[test]) to register it as a test case. xs test discovers and runs them automatically.
Assertions
assert(cond, msg?) throws if the condition is falsy. assert_eq(a, b) throws an AssertionError and shows both values if they are not equal. Both are catchable with try/catch.
Running tests
xs test scans for files matching test_*.xs or *_test.xs and runs all @test functions in them.
xs test -- run all tests
xs test math -- run tests matching "math"
xs test --watch -- rerun on file changesSample output:
Running tests...
PASS test_math.xs (0.012s)
FAIL test_parser.xs (0.005s)
FAIL: test_addition
assert_eq: 3 != 4
Results: 1 passed, 1 failed, 2 total (0.017s)A test file fails if any assertion panics or an unhandled exception is thrown during a test function.
test stdlib module
For more control, import the test module and register tests programmatically:
test.assert_ne(a, b) asserts that a and b are not equal. test.summary() prints a summary and exits with code 1 if any test failed.