Skip to content

Commit ad3f458

Browse files
committed
fix(stream): Respect 'test' feature
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...
1 parent 0b8d105 commit ad3f458

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

crates/anstream/src/_macros.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@
6060
#[macro_export]
6161
macro_rules! print {
6262
($($arg:tt)*) => {{
63-
if cfg!(any(feature = "test", test)) {
63+
if cfg!(test) || $crate::_macros::FEATURE_TEST_ACTIVATED {
6464
let target_stream = std::io::stdout();
6565
let buffer = $crate::_macros::to_adapted_string(&format_args!($($arg)*), &target_stream);
6666
::std::print!("{}", buffer)
@@ -132,7 +132,7 @@ macro_rules! println {
132132
$crate::print!("\n")
133133
};
134134
($($arg:tt)*) => {{
135-
if cfg!(any(feature = "test", test)) {
135+
if cfg!(test) || $crate::_macros::FEATURE_TEST_ACTIVATED {
136136
let target_stream = std::io::stdout();
137137
let buffer = $crate::_macros::to_adapted_string(&format_args!($($arg)*), &target_stream);
138138
::std::println!("{}", buffer)
@@ -183,7 +183,7 @@ macro_rules! println {
183183
#[macro_export]
184184
macro_rules! eprint {
185185
($($arg:tt)*) => {{
186-
if cfg!(any(feature = "test", test)) {
186+
if cfg!(test) || $crate::_macros::FEATURE_TEST_ACTIVATED {
187187
let target_stream = std::io::stderr();
188188
let buffer = $crate::_macros::to_adapted_string(&format_args!($($arg)*), &target_stream);
189189
::std::eprint!("{}", buffer)
@@ -237,7 +237,7 @@ macro_rules! eprintln {
237237
$crate::eprint!("\n")
238238
};
239239
($($arg:tt)*) => {{
240-
if cfg!(any(feature = "test", test)) {
240+
if cfg!(test) || $crate::_macros::FEATURE_TEST_ACTIVATED {
241241
let target_stream = std::io::stderr();
242242
let buffer = $crate::_macros::to_adapted_string(&format_args!($($arg)*), &target_stream);
243243
::std::eprintln!("{}", buffer)
@@ -343,6 +343,9 @@ macro_rules! panic {
343343
}};
344344
}
345345

346+
#[cfg(feature = "auto")]
347+
pub const FEATURE_TEST_ACTIVATED: bool = cfg!(feature = "test");
348+
346349
#[cfg(feature = "auto")]
347350
pub fn to_adapted_string(
348351
display: &dyn std::fmt::Display,

0 commit comments

Comments
 (0)