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

Don't use eprint from logger implementations. #184

Merged
merged 1 commit into from Nov 18, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
15 changes: 6 additions & 9 deletions src/fmt/writer/termcolor/extern_impl.rs
Expand Up @@ -102,17 +102,14 @@ impl BufferWriter {

pub(in crate::fmt::writer) fn print(&self, buf: &Buffer) -> io::Result<()> {
if let Some(target) = self.test_target {
// This impl uses the `eprint` and `print` macros
// instead of `termcolor`'s buffer.
// This is so their output can be captured by `cargo test`
let log = String::from_utf8_lossy(buf.bytes());

// This impl writes directly to stderr / stdout instead of using
// `termcolor`'s buffer. This is so their output can be captured by
// `cargo test`
match target {
Target::Stderr => eprint!("{}", log),
Target::Stdout => print!("{}", log),
Target::Stderr => io::stderr().write_all(buf.bytes()),
Target::Stdout => io::stdout().write_all(buf.bytes()),
}

Ok(())
.map(|_| ())
} else {
self.inner.print(&buf.inner)
}
Expand Down
14 changes: 6 additions & 8 deletions src/fmt/writer/termcolor/shim_impl.rs
Expand Up @@ -28,17 +28,15 @@ impl BufferWriter {
}

pub(in crate::fmt::writer) fn print(&self, buf: &Buffer) -> io::Result<()> {
// This impl uses the `eprint` and `print` macros
// instead of using the streams directly.
// This is so their output can be captured by `cargo test`
let log = String::from_utf8_lossy(&buf.0);
use std::io::Write;

// This impl writes to stdout / stderr instead of using the streams
// directly. This is so their output can be captured by `cargo test`
match self.target {
Target::Stderr => eprint!("{}", log),
Target::Stdout => print!("{}", log),
Target::Stderr => io::stderr().write_all(&buf.0),
Target::Stdout => io::stdout().write_all(&buf.0),
}

Ok(())
.map(|_| ())
}
}

Expand Down