τau /

testing

module
testing = import("testing")

testing - a small test runner.

A test file declares its cases and hands them to Main, which runs them all and exits non zero if any of them failed:

testing = import("testing")
cmp = import("cmp")
testing.Main([
	["Equal on lists", fn(t) {
		t.AssertEq(cmp.Equal([1, 2], [1, 2]), true)
	}],
	["Compare", fn(t) {
		t.AssertEq(cmp.Compare(2, 3), -1)
	}],
])

There are no exceptions, so a failed assertion records the failure and the case keeps going: to stop it, return right after t.Fatal.

Run = fn(name, f)source

Run runs one case and returns its t, already reported.

Name = namevaluesource

Error = fn(msg)source

Error records a failure and lets the case carry on.

Fatal = fn(msg)source

Fatal records a failure meant to end the case. Nothing can interrupt a function from the outside, so return right after calling it.

Assert = fn(cond, msg)source

Assert fails the case if cond isn't true.

AssertEq = fn(got, want)source

AssertEq fails the case unless got and want hold the same value, compared structurally.

AssertNe = fn(got, want)source

AssertNe is AssertEq the other way round.

AssertError = fn(x)source

AssertError fails the case unless x is an error.

Skip = fn(msg)source

Skip marks the case as not run.

Failed = fn()source

Main = fn(cases)source

Main runs every [name, function] pair and exits: 0 when they all pass, 1 as soon as one of them doesn't.