std::testing
Helpers for tests.
testing.check(expr) checks expr as assert expr does and returns a
Result<Subject, AssertionFailure> where assert would fail the test, so
a test can inspect or render the failure. Clock names the clock a test
group runs under.
Import with import std::testing.
Exports
Section titled “Exports”Types
enum Clock
Section titled “enum Clock”enum Clock System Virtual end
Which clock a group runs under, declared as clock Clock.Virtual
or clock Clock.System beside the group’s boot and setup.
Tests that wait are slow when they pass and unreliable when the machine is busy. A virtual clock jumps forward whenever every task in the test is blocked, so waiting costs nothing and takes the same path every run, and work that can never finish is reported as a deadlock rather than hanging.
It is not the default, because a virtual clock changes behavior.
Waiting on something outside the program (reading input, a real network
call) never lets the clock move and is reported as a deadlock.
Background work still running when a test ends is an error, where under
the real clock it carries into the next test. Instant.now starts at
midnight on 1 January 2000.
A group without a clock line runs under System, so each group that
wants virtual time declares it.
Variants
-
SystemThe real clock. The default.
-
VirtualA clock that only advances when every task in the test is blocked.
Clock.inspect
Section titled “Clock.inspect”impl Debug for Clock
fn inspect(value: Clock) -> String
impl Debug.inspect
testing.check
Section titled “testing.check”fn check<T>(subject: T) -> Result<T, AssertionFailure>
Returns Ok(subject) when subject would pass assert, and otherwise
Err(failure), the AssertionFailure that nomi test would report.
assert testing.check(1 == 1)
refute testing.check(1 == 2)