Kite

test

std/test — writing tests, and what a failure says.

A test is a pub function whose name starts with test_ and which returns (int, error). kitec test file.kite finds them, runs each, and reports.

Assertions return an error, so check propagates the first failure and a test reads as a list of claims:

pub fn test_adding() -> (int, error) {
    check test.equal_int(add(2, 2), 4, "two and two")
    check test.is_true(add(1, 1) == 2, "one and one")
    return 0, nil
}

There is no assertion that traps: a failed test should report and let the rest run, and a trap is not catchable in Kite by design.

is_true

pub fn is_true(cond: bool, what: str) -> error

Passes when cond holds.

is_false

pub fn is_false(cond: bool, what: str) -> error

equal_int

pub fn equal_int(found: int, want: int, what: str) -> error

equal_str

pub fn equal_str(found: str, want: str, what: str) -> error

equal_bool

pub fn equal_bool(found: bool, want: bool, what: str) -> error

equal_float

pub fn equal_float(found: float, want: float, tolerance: float, what: str) -> error

Floats compare within a tolerance, because comparing them exactly is almost never what is meant — the compiler warns about == on floats for the same reason.

equal_ints

pub fn equal_ints(found: [int], want: [int], what: str) -> error

equal_strs

pub fn equal_strs(found: [str], want: [str], what: str) -> error

failed

pub fn failed(err: error, what: str) -> error

Passes when an error happened, which is what a test of a failure path wants: a function that should have refused and did not is a bug.

ok

pub fn ok(err: error, what: str) -> error

Passes when nothing went wrong, carrying the message onwards when it did.

fail

pub fn fail(what: str) -> error

Fails outright, for a branch that should not have been reached.