test module
A minimal test framework. Register tests with test(), assert with equal / is_true / etc., and call run() to execute everything. The process exits with code 1 if any test fails — that's all CI needs.
A test file is just a Bnlang script: import test, register cases, call t.run().
import "test" as t;
t.test("addition", function () {
t.equal(2 + 2, 4);
});
t.test("upper case", function () {
t.equal("foo".to_upper(), "FOO");
});
t.run();
API
| Function | Description |
|---|---|
t.test(name, fn) | Register a test. fn takes no args; throw to fail. |
t.run() | Execute every registered test; print a summary; exit 1 on any failure. |
Assertions
| Function | Description |
|---|---|
t.equal(actual, expected) | Value compare. |
t.not_equal(actual, expected) | Opposite. |
t.is_true(v) / t.is_false(v) | Boolean checks. |
t.is_null(v) / t.not_null(v) | |
t.contains(haystack, needle) | Substring (for strings) or membership (for lists). |
t.throws(fn) | Assert fn() throws. |
t.throws_with(fn, substring) | Assert it throws and the message contains substring. |
Running tests
bnl tests/parser_spec.bnl
# Run a whole folder via your shell:
for f in tests/*.bnl; do bnl "$f" || exit 1; done
There is no test discovery binary — just run the file with bnl. See Using Bnlang's test framework for CI patterns.