aboutsummaryrefslogtreecommitdiff
path: root/crates/test_utils/src
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2020-05-20 12:03:18 +0100
committerGitHub <[email protected]>2020-05-20 12:03:18 +0100
commite3373629cd80404388c5da52f991e18f2d715d8d (patch)
treef916c9d90a5b1817db4aed2c60db2ce4809dab1f /crates/test_utils/src
parent4d3fd62f897da50db1b203b86f45b9d2cd272b4d (diff)
parentecac5d7de2192873c24b7b06d4964d188d8abe6a (diff)
Merge #4520
4520: Marks 2.0 r=matklad a=matklad The main benefit here is that we no longer need to declare marks. The main drawback is that this is ~~glorious~~ horrible. WDYT? Co-authored-by: Aleksey Kladov <[email protected]>
Diffstat (limited to 'crates/test_utils/src')
-rw-r--r--crates/test_utils/src/lib.rs2
-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 b1e3c328f..be2cfbaa2 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]
10pub mod marks; 10pub mod mark;
11 11
12use std::{ 12use 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 @@
29use std::sync::atomic::{AtomicUsize, Ordering}; 29use std::sync::atomic::{AtomicUsize, Ordering};
30 30
31#[macro_export] 31#[macro_export]
32macro_rules! tested_by { 32macro_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}
46pub use _hit as hit;
47 47
48#[macro_export] 48#[macro_export]
49macro_rules! covers { 49macro_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]
60macro_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}
56pub use _check as check;
69 57
70pub struct MarkChecker { 58pub struct MarkChecker {
71 mark: &'static AtomicUsize, 59 mark: &'static AtomicUsize,