Skip to content

Commit bb43cd3

Browse files
committed
test(util): add a test_dbg! macro (#333)
This was cherry-picked out of PR #332
1 parent 5283cf9 commit bb43cd3

File tree

3 files changed

+41
-0
lines changed

3 files changed

+41
-0
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

util/Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ tracing = { git = "https://github.com/tokio-rs/tracing", default_features = fals
2727
[target.'cfg(loom)'.dependencies]
2828
loom = "0.5.5"
2929

30+
[target.'cfg(loom)'.dev-dependencies]
31+
tracing_01 = { package = "tracing", version = "0.1.36" }
32+
3033
[package.metadata.docs.rs]
3134
all-features = true
3235
rustdoc-args = ["--cfg", "docsrs"]

util/src/macros.rs

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,3 +66,40 @@ macro_rules! unreachable_unchecked {
6666
}
6767
});
6868
}
69+
70+
#[cfg(test)]
71+
macro_rules! test_dbg {
72+
($x:expr) => {
73+
match $x {
74+
x => {
75+
test_trace!(
76+
location = %core::panic::Location::caller(),
77+
"{} = {x:?}",
78+
stringify!($x)
79+
);
80+
x
81+
}
82+
}
83+
};
84+
}
85+
86+
#[cfg(not(test))]
87+
macro_rules! test_dbg {
88+
($x:expr) => {
89+
$x
90+
};
91+
}
92+
93+
#[cfg(all(test, not(loom)))]
94+
macro_rules! test_trace {
95+
($($arg:tt)+) => {
96+
tracing::trace!($($arg)+);
97+
};
98+
}
99+
100+
#[cfg(all(test, loom))]
101+
macro_rules! test_trace {
102+
($($arg:tt)+) => {
103+
tracing_01::trace!($($arg)+);
104+
};
105+
}

0 commit comments

Comments
 (0)