diff options
Diffstat (limited to 'crates/test_utils')
-rw-r--r-- | crates/test_utils/src/lib.rs | 2 | ||||
-rw-r--r-- | crates/test_utils/src/mark.rs (renamed from crates/test_utils/src/marks.rs) | 46 |
2 files changed, 18 insertions, 30 deletions
diff --git a/crates/test_utils/src/lib.rs b/crates/test_utils/src/lib.rs index 45abfead9..1bd97215c 100644 --- a/crates/test_utils/src/lib.rs +++ b/crates/test_utils/src/lib.rs | |||
@@ -7,7 +7,7 @@ | |||
7 | //! * marks (see the eponymous module). | 7 | //! * marks (see the eponymous module). |
8 | 8 | ||
9 | #[macro_use] | 9 | #[macro_use] |
10 | pub mod marks; | 10 | pub mod mark; |
11 | 11 | ||
12 | use std::{ | 12 | use std::{ |
13 | fs, | 13 | fs, |
diff --git a/crates/test_utils/src/marks.rs b/crates/test_utils/src/mark.rs index c3185e860..7c309a894 100644 --- a/crates/test_utils/src/marks.rs +++ b/crates/test_utils/src/mark.rs | |||
@@ -7,18 +7,18 @@ | |||
7 | //! ``` | 7 | //! ``` |
8 | //! #[test] | 8 | //! #[test] |
9 | //! fn test_foo() { | 9 | //! fn test_foo() { |
10 | //! covers!(test_foo); | 10 | //! mark::check!(test_foo); |
11 | //! } | 11 | //! } |
12 | //! ``` | 12 | //! ``` |
13 | //! | 13 | //! |
14 | //! and in the code under test you write | 14 | //! and in the code under test you write |
15 | //! | 15 | //! |
16 | //! ``` | 16 | //! ``` |
17 | //! # use test_utils::tested_by; | 17 | //! # use test_utils::mark; |
18 | //! # fn some_condition() -> bool { true } | 18 | //! # fn some_condition() -> bool { true } |
19 | //! fn foo() { | 19 | //! fn foo() { |
20 | //! if some_condition() { | 20 | //! if some_condition() { |
21 | //! tested_by!(test_foo); | 21 | //! mark::hit!(test_foo); |
22 | //! } | 22 | //! } |
23 | //! } | 23 | //! } |
24 | //! ``` | 24 | //! ``` |
@@ -29,43 +29,31 @@ | |||
29 | use std::sync::atomic::{AtomicUsize, Ordering}; | 29 | use std::sync::atomic::{AtomicUsize, Ordering}; |
30 | 30 | ||
31 | #[macro_export] | 31 | #[macro_export] |
32 | macro_rules! tested_by { | 32 | macro_rules! _hit { |
33 | ($ident:ident; force) => {{ | ||
34 | { | ||
35 | // sic! use call-site crate | ||
36 | crate::marks::$ident.fetch_add(1, std::sync::atomic::Ordering::SeqCst); | ||
37 | } | ||
38 | }}; | ||
39 | ($ident:ident) => {{ | 33 | ($ident:ident) => {{ |
40 | #[cfg(test)] | 34 | #[cfg(test)] |
41 | { | 35 | { |
42 | // sic! use call-site crate | 36 | extern "C" { |
43 | crate::marks::$ident.fetch_add(1, std::sync::atomic::Ordering::SeqCst); | 37 | #[no_mangle] |
38 | static $ident: std::sync::atomic::AtomicUsize; | ||
39 | } | ||
40 | unsafe { | ||
41 | $ident.fetch_add(1, std::sync::atomic::Ordering::SeqCst); | ||
42 | } | ||
44 | } | 43 | } |
45 | }}; | 44 | }}; |
46 | } | 45 | } |
46 | pub use _hit as hit; | ||
47 | 47 | ||
48 | #[macro_export] | 48 | #[macro_export] |
49 | macro_rules! covers { | 49 | macro_rules! _check { |
50 | // sic! use call-site crate | ||
51 | ($ident:ident) => { | 50 | ($ident:ident) => { |
52 | $crate::covers!(crate::$ident) | 51 | #[no_mangle] |
53 | }; | 52 | static $ident: std::sync::atomic::AtomicUsize = std::sync::atomic::AtomicUsize::new(0); |
54 | ($krate:ident :: $ident:ident) => { | 53 | let _checker = $crate::mark::MarkChecker::new(&$ident); |
55 | let _checker = $crate::marks::MarkChecker::new(&$krate::marks::$ident); | ||
56 | }; | ||
57 | } | ||
58 | |||
59 | #[macro_export] | ||
60 | macro_rules! marks { | ||
61 | ($($ident:ident)*) => { | ||
62 | $( | ||
63 | #[allow(bad_style)] | ||
64 | pub static $ident: std::sync::atomic::AtomicUsize = | ||
65 | std::sync::atomic::AtomicUsize::new(0); | ||
66 | )* | ||
67 | }; | 54 | }; |
68 | } | 55 | } |
56 | pub use _check as check; | ||
69 | 57 | ||
70 | pub struct MarkChecker { | 58 | pub struct MarkChecker { |
71 | mark: &'static AtomicUsize, | 59 | mark: &'static AtomicUsize, |