Created
November 8, 2019 13:47
-
-
Save Megaprog/a6f536e3a05d5e4bee3eac40bba576c5 to your computer and use it in GitHub Desktop.
Rust test deal with panic
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#[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