Skip to content

Commit

Permalink
fix(stream): Respect 'test' feature
Browse files Browse the repository at this point in the history
We were putting it into the generated code, not our code, causing it to
be an "unexpected cfg".

It would be nice to use the macro's cfgs in the generated code...
  • Loading branch information
epage committed Nov 4, 2024
1 parent 0b8d105 commit ad3f458
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions crates/anstream/src/_macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
#[macro_export]
macro_rules! print {
($($arg:tt)*) => {{
if cfg!(any(feature = "test", test)) {
if cfg!(test) || $crate::_macros::FEATURE_TEST_ACTIVATED {
let target_stream = std::io::stdout();
let buffer = $crate::_macros::to_adapted_string(&format_args!($($arg)*), &target_stream);
::std::print!("{}", buffer)
Expand Down Expand Up @@ -132,7 +132,7 @@ macro_rules! println {
$crate::print!("\n")
};
($($arg:tt)*) => {{
if cfg!(any(feature = "test", test)) {
if cfg!(test) || $crate::_macros::FEATURE_TEST_ACTIVATED {
let target_stream = std::io::stdout();
let buffer = $crate::_macros::to_adapted_string(&format_args!($($arg)*), &target_stream);
::std::println!("{}", buffer)
Expand Down Expand Up @@ -183,7 +183,7 @@ macro_rules! println {
#[macro_export]
macro_rules! eprint {
($($arg:tt)*) => {{
if cfg!(any(feature = "test", test)) {
if cfg!(test) || $crate::_macros::FEATURE_TEST_ACTIVATED {
let target_stream = std::io::stderr();
let buffer = $crate::_macros::to_adapted_string(&format_args!($($arg)*), &target_stream);
::std::eprint!("{}", buffer)
Expand Down Expand Up @@ -237,7 +237,7 @@ macro_rules! eprintln {
$crate::eprint!("\n")
};
($($arg:tt)*) => {{
if cfg!(any(feature = "test", test)) {
if cfg!(test) || $crate::_macros::FEATURE_TEST_ACTIVATED {
let target_stream = std::io::stderr();
let buffer = $crate::_macros::to_adapted_string(&format_args!($($arg)*), &target_stream);
::std::eprintln!("{}", buffer)
Expand Down Expand Up @@ -343,6 +343,9 @@ macro_rules! panic {
}};
}

#[cfg(feature = "auto")]
pub const FEATURE_TEST_ACTIVATED: bool = cfg!(feature = "test");

#[cfg(feature = "auto")]
pub fn to_adapted_string(
display: &dyn std::fmt::Display,
Expand Down

0 comments on commit ad3f458

Please sign in to comment.