std::testing
Assertions that say what failed, and a runner for a file of tests. An assertion that fails prints both values to stderr and returns FAILED, so try ends the test there.
Source: std/testing.volt
Types
error std::testing::test_error
error test_error| Variant | |
|---|---|
FAILED | an assertion failed (what and why are on stderr) |
struct std::testing::test
struct testone test: a name and a body that fails by returning an error
| Field | |
|---|---|
name: str | |
body: fn() -> !void |
Functions
std::testing::assert
fn assert(ok: bool, what: str = "") -> test_error!voidfails unless ok
std::testing::assert_eq
<T: type> fn assert_eq(left: T, right: T, what: str = "") -> test_error!voidfails unless left equals right (by eq, so a type's own eq counts). Both are taken by value, so an owned value (a std::string) moves in: pass copy s, or compare s.as_str()
std::testing::assert_ne
<T: type> fn assert_ne(left: T, right: T, what: str = "") -> test_error!voidfails if left equals right
std::testing::assert_near
fn assert_near(left: f64, right: f64, tolerance: f64, what: str = "") -> test_error!voidfails unless left and right are at most tolerance (0 or more) apart. Equal infinities are near; NaN is never near anything
std::testing::run
fn run(tests: test[..]) -> i32runs every test, even after one fails, printing test NAME ... ok or ... FAILED for each and a count at the end. Returns the exit code: 0 when all passed, 1 otherwise
std::testing::run_main
fn run_main(tests: test[..]) -> i32the main of a --test build (the compiler writes it from the program's test blocks): runs the tests whose names contain the program's first argument, or all of them without one