Skip to content

Instantly share code, notes, and snippets.

@Megaprog
Created November 8, 2019 13:47
Show Gist options
  • Save Megaprog/a6f536e3a05d5e4bee3eac40bba576c5 to your computer and use it in GitHub Desktop.
Save Megaprog/a6f536e3a05d5e4bee3eac40bba576c5 to your computer and use it in GitHub Desktop.
Rust test deal with panic
#[test]
fn test_something_interesting() {
run_test(|| {
let true_or_false = do_the_test();
assert!(true_or_false);
})
}
fn run_test<T>(test: T) -> ()
where T: FnOnce() -> () + panic::UnwindSafe
{
setup();
let result = panic::catch_unwind(|| {
test()
});
teardown();
assert!(result.is_ok())
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment