use std::sync::atomic::{AtomicUsize, Ordering};
pub enum CallCountVerifier {
WithCount {
counter: &'static AtomicUsize,
expected: usize,
},
Dummy,
}
impl Drop for CallCountVerifier {
fn drop(&mut self) {
if let CallCountVerifier::WithCount { counter, expected } = self {
let call_times = counter.load(Ordering::SeqCst);
if call_times != *expected {
if std::thread::panicking() {
return;
}
panic!(
"Fake function was expected to be called {expected} time(s), but it is actually called {call_times} time(s)"
);
}
}
}
}