Skip to content

Commit a5e20ad

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 a5daf82 commit a5e20ad

File tree

1 file changed

+62
-4
lines changed

1 file changed

+62
-4
lines changed

crates/anstream/src/_macros.rs

Lines changed: 62 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,22 @@
11
#[doc = include_str!("print.md")]
22
#[cfg(feature = "auto")]
3+
#[cfg(feature = "test")]
34
#[macro_export]
45
macro_rules! print {
56
($($arg:tt)*) => {{
6-
if cfg!(any(feature = "test", test)) {
7+
let target_stream = std::io::stdout();
8+
let buffer = $crate::_macros::to_adapted_string(&format_args!($($arg)*), &target_stream);
9+
::std::print!("{}", buffer)
10+
}};
11+
}
12+
13+
#[doc = include_str!("print.md")]
14+
#[cfg(feature = "auto")]
15+
#[cfg(not(feature = "test"))]
16+
#[macro_export]
17+
macro_rules! print {
18+
($($arg:tt)*) => {{
19+
if cfg!(test) {
720
let target_stream = std::io::stdout();
821
let buffer = $crate::_macros::to_adapted_string(&format_args!($($arg)*), &target_stream);
922
::std::print!("{}", buffer)
@@ -23,13 +36,29 @@ macro_rules! print {
2336

2437
#[doc = include_str!("println.md")]
2538
#[cfg(feature = "auto")]
39+
#[cfg(feature = "test")]
40+
#[macro_export]
41+
macro_rules! println {
42+
() => {
43+
$crate::print!("\n")
44+
};
45+
($($arg:tt)*) => {{
46+
let target_stream = std::io::stdout();
47+
let buffer = $crate::_macros::to_adapted_string(&format_args!($($arg)*), &target_stream);
48+
::std::println!("{}", buffer)
49+
}};
50+
}
51+
52+
#[doc = include_str!("println.md")]
53+
#[cfg(feature = "auto")]
54+
#[cfg(not(feature = "test"))]
2655
#[macro_export]
2756
macro_rules! println {
2857
() => {
2958
$crate::print!("\n")
3059
};
3160
($($arg:tt)*) => {{
32-
if cfg!(any(feature = "test", test)) {
61+
if cfg!(test) {
3362
let target_stream = std::io::stdout();
3463
let buffer = $crate::_macros::to_adapted_string(&format_args!($($arg)*), &target_stream);
3564
::std::println!("{}", buffer)
@@ -49,10 +78,23 @@ macro_rules! println {
4978

5079
#[doc = include_str!("eprint.md")]
5180
#[cfg(feature = "auto")]
81+
#[cfg(feature = "test")]
82+
#[macro_export]
83+
macro_rules! eprint {
84+
($($arg:tt)*) => {{
85+
let target_stream = std::io::stderr();
86+
let buffer = $crate::_macros::to_adapted_string(&format_args!($($arg)*), &target_stream);
87+
::std::eprint!("{}", buffer)
88+
}};
89+
}
90+
91+
#[doc = include_str!("eprint.md")]
92+
#[cfg(feature = "auto")]
93+
#[cfg(not(feature = "test"))]
5294
#[macro_export]
5395
macro_rules! eprint {
5496
($($arg:tt)*) => {{
55-
if cfg!(any(feature = "test", test)) {
97+
if cfg!(test) {
5698
let target_stream = std::io::stderr();
5799
let buffer = $crate::_macros::to_adapted_string(&format_args!($($arg)*), &target_stream);
58100
::std::eprint!("{}", buffer)
@@ -72,13 +114,29 @@ macro_rules! eprint {
72114

73115
#[doc = include_str!("eprintln.md")]
74116
#[cfg(feature = "auto")]
117+
#[cfg(feature = "test")]
118+
#[macro_export]
119+
macro_rules! eprintln {
120+
() => {
121+
$crate::eprint!("\n")
122+
};
123+
($($arg:tt)*) => {{
124+
let target_stream = std::io::stderr();
125+
let buffer = $crate::_macros::to_adapted_string(&format_args!($($arg)*), &target_stream);
126+
::std::eprintln!("{}", buffer)
127+
}};
128+
}
129+
130+
#[doc = include_str!("eprintln.md")]
131+
#[cfg(feature = "auto")]
132+
#[cfg(not(feature = "test"))]
75133
#[macro_export]
76134
macro_rules! eprintln {
77135
() => {
78136
$crate::eprint!("\n")
79137
};
80138
($($arg:tt)*) => {{
81-
if cfg!(any(feature = "test", test)) {
139+
if cfg!(test) {
82140
let target_stream = std::io::stderr();
83141
let buffer = $crate::_macros::to_adapted_string(&format_args!($($arg)*), &target_stream);
84142
::std::eprintln!("{}", buffer)

0 commit comments

Comments
 (0)