test

Checks for your own tests. Put them in files ending in _test.tb and run tb test.

import test

Example

import test

test.equal(1 + 1, 2, "maths still works")
test.true("tb".upper() == "TB", "upper() works")
test.raises(fn() { throw "boom" })
say(test.results())

Functions

equal(actual, expected, message?)

returns bool

Check that two values are the same (lists and maps are compared item by item).

not_equal(a, b, message?)

returns bool

Check that two values are different.

true(value, message?)

returns bool

Check that a value is true (anything but false and nil).

false(value, message?)

returns bool

Check that a value is false or nil.

raises(fn, part?)

returns map or nil

Check that calling fn() stops with an error (whose message contains part, if given). Gives back the error map.

case(name, fn)

Run one named test. If fn stops with an error, that counts as a failure and the other cases still run.

results()

returns map

How many checks passed and failed so far: {"passed", "failed"}.