testimony

index

Overview

The test framework every build carries. A suite makes one tally with new, runs its cases through that and ends with conclude, which prints the tally and exits the process. A case passes when it returns, fails when it raises, and skips when it raises what skip makes. A skip is counted apart and printed with its reason, so a green run says what it did not check; the suite still exits 0.

Functions

NameSignature
assert_equalassert_equal(expected, actual, msg)
assert_trueassert_true(value, msg)
assert_falseassert_false(value, msg)
assert_nilassert_nil(value, msg)
assert_not_nilassert_not_nil(value, msg)
assert_errorassert_error(fn, expected_pattern, msg)
assert_matchassert_match(pattern, str, msg)
skipskip(reason)
newnew(description) -> tally

assert_equal(expected, actual, msg)

Assert deep equality

Tables compare by their contents, recursively, cycles included. Raises msg, or the two values formatted, at the caller.

assert_true(value, msg)

Assert a truthy value

assert_false(value, msg)

Assert a falsy value

assert_nil(value, msg)

Assert nil

assert_not_nil(value, msg)

Assert a value that is not nil

assert_error(fn, expected_pattern, msg)

Assert that a function raises

Calls fn under pcall and raises when it returns, or when its error does not match expected_pattern.

assert_match(pattern, str, msg)

Assert that a string matches a pattern

str is compared through tostring.

skip(reason)

Skip the running case

Raises the skip value out of the case: that counts the case as skipped and keeps the reason for conclude to print. A case's own pcall that re-raises with error(e, 0) passes it on. Call it after the case's cleanup: nothing closes a handle the raise jumps over.

new(description) -> tally

Make the tally for one suite

tally:that(name, fn) runs the case fn at once and counts it; tally:conclude() prints the counts, the skips with their reasons and the failures with their errors, then exits the process: 0 when nothing failed, 1 otherwise. The counts stand on tally.tests: run, passed, failed and skipped, with failures a list of { name, error } and skips a list of { name, reason }.