Skip to content

Commit

Permalink
test(util): add a test_dbg! macro (#333)
Browse files Browse the repository at this point in the history
This was cherry-picked out of PR #332
  • Loading branch information
hawkw committed Oct 8, 2022
1 parent 07359bf commit dad0e0d
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 0 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions util/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ tracing = { git = "https://github.com/tokio-rs/tracing", default_features = fals
[target.'cfg(loom)'.dependencies]
loom = "0.5.5"

[target.'cfg(loom)'.dev-dependencies]
tracing_01 = { package = "tracing", version = "0.1.36" }

[package.metadata.docs.rs]
all-features = true
rustdoc-args = ["--cfg", "docsrs"]
37 changes: 37 additions & 0 deletions util/src/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,3 +66,40 @@ macro_rules! unreachable_unchecked {
}
});
}

#[cfg(test)]
macro_rules! test_dbg {
($x:expr) => {
match $x {
x => {
test_trace!(
location = %core::panic::Location::caller(),
"{} = {x:?}",
stringify!($x)
);
x
}
}
};
}

#[cfg(not(test))]
macro_rules! test_dbg {
($x:expr) => {
$x
};
}

#[cfg(all(test, not(loom)))]
macro_rules! test_trace {
($($arg:tt)+) => {
tracing::trace!($($arg)+);
};
}

#[cfg(all(test, loom))]
macro_rules! test_trace {
($($arg:tt)+) => {
tracing_01::trace!($($arg)+);
};
}

0 comments on commit dad0e0d

Please sign in to comment.