Crate fail [−] [src]
A fail point implementation for rust.
Fail points are code points that are used to inject errors by users at runtime. This crate is inspired by FreeBSD's failpoints. Unlike FreeBSD's implementation, this crate only supports the configuration from environment variables and API.
Installation
Add this to your Cargo.toml
:
[dependencies]
fail = "0.1"
Example
#[macro_use] extern crate fail; fn f1() { fail_point!("example", |_| {}); panic!(); } fn main() { fail::setup(); fail::cfg("rust_out::example", "return").unwrap(); f1(); fail::teardown(); }
The above example defines a fail point named "example" and then configures it as return
.
So the f1
function will return early and never panic. You can also configure it via the
FAILPOINTS=rust_out::example=return
environment variable. For more supported
configuration, see docs for macro fail_point
and setup
.
If you want to disable all the fail points at compile time, you can enable features no_fail
.
Macros
fail_point |
The only entry to define a fail point. |
Functions
cfg |
Set new actions to a fail point at runtime. |
remove |
Remove a fail point. |
setup |
Set up the fail point system. |
teardown |
Tear down the fail point system. |