std.testing
Types
struct Bench
Functions
assert_throws
pub fn assert_throws(f: |()|, err: Error | |(Error)|)
[src]
#[track_caller]
pub fn assert_throws(f: |() throws|, err: Error | AssertErrFn) {
do {
try f();
assert false, "expected to throw an error";
} catch(e) {
switch (let t = err.(type)) {
case Error:
assert_eq e.error(), t.error();
case AssertErrFn:
t(e);
}
}
}
Assert the f
closure will throw an error with the given error.
assert_throws
pub fn assert_throws(f: |()|, err: Error | |(Error)|)
[src]
#[track_caller]
pub fn assert_throws(f: |() throws|, err: Error | AssertErrFn) {
do {
try f();
assert false, "expected to throw an error";
} catch(e) {
switch (let t = err.(type)) {
case Error:
assert_eq e.error(), t.error();
case AssertErrFn:
t(e);
}
}
}
Assert the f
closure will throw an error with the given error.
Assert the f
closure will throw an error with the given error.
nv,
use std.testing.assert_throws;
assert_throws(|| {
throw "error";
}, "error");
assert_throws(|| {
throw "error";
}, |err| {
assert err.error().contains("error");
});