Created
October 15, 2017 18:58
-
-
Save H2CO3/319d9343075dbd9b5090812657856c04 to your computer and use it in GitHub Desktop.
Protect against forgetting to call a test case evaluation function
This file contains hidden or 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
fn make_test_evaluator() -> Box<Fn(YourTestCaseTypeHere)> { | |
use std::cell::RefCell; | |
struct EvalGuard(bool); | |
impl Drop for EvalGuard { | |
fn drop(&mut self) { | |
if !self.0 { | |
panic!("Did not actually evaluate test cases"); | |
} | |
} | |
} | |
let eval_guard = RefCell::new(EvalGuard(false)); | |
Box::new(move |test_case: YourTestCaseTypeHere| { | |
assert!(test_case.does_stuff_correctly(), "doesn't do stuff correctly"); | |
eval_guard.borrow_mut().0 = true; | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment