From fc9eed4836dfc88fe2893c81b015ab440cea2ba6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lauren=C8=9Biu=20Nicola?= Date: Mon, 8 Mar 2021 22:19:44 +0200 Subject: Use upstream cov-mark --- crates/test_utils/src/lib.rs | 2 -- crates/test_utils/src/mark.rs | 78 ------------------------------------------- 2 files changed, 80 deletions(-) delete mode 100644 crates/test_utils/src/mark.rs (limited to 'crates/test_utils/src') diff --git a/crates/test_utils/src/lib.rs b/crates/test_utils/src/lib.rs index 6041ab5e4..c5f859790 100644 --- a/crates/test_utils/src/lib.rs +++ b/crates/test_utils/src/lib.rs @@ -6,8 +6,6 @@ //! * Extracting markup (mainly, `$0` markers) out of fixture strings. //! * marks (see the eponymous module). -#[macro_use] -pub mod mark; pub mod bench_fixture; mod fixture; diff --git a/crates/test_utils/src/mark.rs b/crates/test_utils/src/mark.rs deleted file mode 100644 index 97f5a93ad..000000000 --- a/crates/test_utils/src/mark.rs +++ /dev/null @@ -1,78 +0,0 @@ -//! This module implements manually tracked test coverage, which is useful for -//! quickly finding a test responsible for testing a particular bit of code. -//! -//! See -//! for details, but the TL;DR is that you write your test as -//! -//! ``` -//! #[test] -//! fn test_foo() { -//! mark::check!(test_foo); -//! } -//! ``` -//! -//! and in the code under test you write -//! -//! ``` -//! # use test_utils::mark; -//! # fn some_condition() -> bool { true } -//! fn foo() { -//! if some_condition() { -//! mark::hit!(test_foo); -//! } -//! } -//! ``` -//! -//! This module then checks that executing the test indeed covers the specified -//! function. This is useful if you come back to the `foo` function ten years -//! later and wonder where the test are: now you can grep for `test_foo`. -use std::sync::atomic::{AtomicUsize, Ordering}; - -#[macro_export] -macro_rules! _hit { - ($ident:ident) => {{ - #[cfg(test)] - { - extern "C" { - #[no_mangle] - static $ident: std::sync::atomic::AtomicUsize; - } - unsafe { - $ident.fetch_add(1, std::sync::atomic::Ordering::SeqCst); - } - } - }}; -} -pub use _hit as hit; - -#[macro_export] -macro_rules! _check { - ($ident:ident) => { - #[no_mangle] - static $ident: std::sync::atomic::AtomicUsize = std::sync::atomic::AtomicUsize::new(0); - let _checker = $crate::mark::MarkChecker::new(&$ident); - }; -} -pub use _check as check; - -pub struct MarkChecker { - mark: &'static AtomicUsize, - value_on_entry: usize, -} - -impl MarkChecker { - pub fn new(mark: &'static AtomicUsize) -> MarkChecker { - let value_on_entry = mark.load(Ordering::Relaxed); - MarkChecker { mark, value_on_entry } - } -} - -impl Drop for MarkChecker { - fn drop(&mut self) { - if std::thread::panicking() { - return; - } - let value_on_exit = self.mark.load(Ordering::Relaxed); - assert!(value_on_exit > self.value_on_entry, "mark was not hit") - } -} -- cgit v1.2.3