Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

anstream::println!() shows output during tests #88

Closed
robertwahler opened this issue Apr 8, 2023 · 1 comment · Fixed by #133
Closed

anstream::println!() shows output during tests #88

robertwahler opened this issue Apr 8, 2023 · 1 comment · Fixed by #133
Labels
C-bug Category: Things not working as expected

Comments

@robertwahler
Copy link

When running anstream::println!("should this show?"); in a unit test, I would have thought that no output would show on stdout unless running the test via cargo test -- --nocapture but it shows regardless of the no capture flag. I'm pretty new to rust so I may be missing something obvious. Thanks!

@robertwahler robertwahler changed the title anstream::println!() shows output durning tests anstream::println!() shows output during tests Apr 8, 2023
@epage epage added the C-bug Category: Things not working as expected label Apr 10, 2023
@epage
Copy link
Collaborator

epage commented Apr 10, 2023

The standard library's println uses a semi-public-but-unstable API for the test crate to capture output

See https://github.com/rust-lang/rust/blob/master/library/std/src/io/stdio.rs#L979

To support this, we'd need to special case print/println/eprint/eprintln to call the original if #[cfg(test)]. This would require making some of the logic shuffled around to allow the logic to wrap around other macros and not just streams. The conditional behavior for the error handling should be preserved in the non-test case. As broken pipes for tests is likely to be a problem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: Things not working as expected
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants