Module std::test
Assertions for #[test]s and for any code that checks itself. Each failure is a Panic
(raise), which fails the test. assert_eq and assert_ne format the two values by their
Display impls into a String (hence Alloc in their rows; equal values allocate nothing)
and panic through panic_detail: a handler of the Panic sees assert_eq failed, and the
root's halt reads assert_eq failed: left 3, right 4. They take the values, as a call takes
its arguments: a scalar, a Str or a byte view &[u8] is copied, and a value that owns memory
is moved and dropped. Rust's #[should_panic] is written as a test that calls expect_panic.
Source: std/test.weir; committed interface: std/test.iface. Index
- fn
assert: Panics withmunlessc. - fn
assert_eq: Panics withassert_eq failedunlessleftequalsright; the root's halt names both. - fn
assert_ne: Panics withassert_ne failedifleftequalsright; the root's halt names both. - fn
expect_panic: Runsf, which must panic, and answers its panic message;freturning panics instead.f's panic unwinds only to here (std::panic::catch_panic), running destructors and guards.
fn assert
pub fn assert(c: Bool, m: Str) with Panic {panic: raise} migrates cross
Panics with m unless c.
Committed interface (std/test.iface):
bound Panic: Panic cross
aborts: Panic.panic
scheduling point: Panic not quiet
fn assert_eq
pub fn assert_eq<T: Eq + Display>(left: T, right: T) with
Panic {panic: raise} migrates cross,
Alloc,
Panics with assert_eq failed unless left equals right; the root's halt names both.
Committed interface (std/test.iface):
bound Panic: Panic cross
bound Alloc: Alloc any
bound Eq: Eq<T> any row {Diverge}
may diverge
aborts: Panic.panic, Alloc.alloc
scheduling point: Eq not quiet | Panic not quiet
destroys values of T
reads regions _
writes regions type T
loan of Alloc across the backing of left
loan of Alloc across the backing of right
loan of Eq across the backing of left
loan of Eq across the backing of right
fn assert_ne
pub fn assert_ne<T: Eq + Display>(left: T, right: T) with
Panic {panic: raise} migrates cross,
Alloc,
Panics with assert_ne failed if left equals right; the root's halt names both.
Committed interface (std/test.iface):
bound Panic: Panic cross
bound Alloc: Alloc any
bound Eq: Eq<T> any row {Diverge}
may diverge
aborts: Panic.panic, Alloc.alloc
scheduling point: Eq not quiet | Panic not quiet
destroys values of T
reads regions _
writes regions type T
loan of Alloc across the backing of left
loan of Alloc across the backing of right
loan of Eq across the backing of left
loan of Eq across the backing of right
fn expect_panic
pub fn expect_panic<T>(f: fn() -> T with Panic) -> Str with Panic {panic: raise} migrates cross
Runs f, which must panic, and answers its panic message; f returning panics instead.
f's panic unwinds only to here (std::panic::catch_panic), running destructors and guards.
Committed interface (std/test.iface):
bound Panic: Panic cross
aborts: Panic.panic
scheduling point: Panic not quiet
holds what may not move at a scheduling point: always
destroys values of T
callback f: envelope {A, S}; pinned: Panic not portable