From 84b701dac94e4135f59f069a8c155bb9b7922788 Mon Sep 17 00:00:00 2001 From: niklas Date: Mon, 4 Jul 2022 11:30:14 +0200 Subject: [PATCH] Change Pipe to always use the test (uncolored) semantics Pipe only worked in test contexts before. --- src/fmt/writer/mod.rs | 2 +- src/fmt/writer/termcolor/extern_impl.rs | 23 +++++++++-------------- 2 files changed, 10 insertions(+), 15 deletions(-) diff --git a/src/fmt/writer/mod.rs b/src/fmt/writer/mod.rs index 5bb53539..2b56772e 100644 --- a/src/fmt/writer/mod.rs +++ b/src/fmt/writer/mod.rs @@ -193,7 +193,7 @@ impl Builder { let writer = match mem::take(&mut self.target) { WritableTarget::Stderr => BufferWriter::stderr(self.is_test, color_choice), WritableTarget::Stdout => BufferWriter::stdout(self.is_test, color_choice), - WritableTarget::Pipe(pipe) => BufferWriter::pipe(self.is_test, color_choice, pipe), + WritableTarget::Pipe(pipe) => BufferWriter::pipe(color_choice, pipe), }; Writer { diff --git a/src/fmt/writer/termcolor/extern_impl.rs b/src/fmt/writer/termcolor/extern_impl.rs index f7ed8a5c..fbe37a77 100644 --- a/src/fmt/writer/termcolor/extern_impl.rs +++ b/src/fmt/writer/termcolor/extern_impl.rs @@ -71,19 +71,19 @@ impl Formatter { pub(in crate::fmt::writer) struct BufferWriter { inner: termcolor::BufferWriter, - test_target: Option, + uncolored_target: Option, } pub(in crate::fmt) struct Buffer { inner: termcolor::Buffer, - has_test_target: bool, + has_uncolored_target: bool, } impl BufferWriter { pub(in crate::fmt::writer) fn stderr(is_test: bool, write_style: WriteStyle) -> Self { BufferWriter { inner: termcolor::BufferWriter::stderr(write_style.into_color_choice()), - test_target: if is_test { + uncolored_target: if is_test { Some(WritableTarget::Stderr) } else { None @@ -94,7 +94,7 @@ impl BufferWriter { pub(in crate::fmt::writer) fn stdout(is_test: bool, write_style: WriteStyle) -> Self { BufferWriter { inner: termcolor::BufferWriter::stdout(write_style.into_color_choice()), - test_target: if is_test { + uncolored_target: if is_test { Some(WritableTarget::Stdout) } else { None @@ -103,30 +103,25 @@ impl BufferWriter { } pub(in crate::fmt::writer) fn pipe( - is_test: bool, write_style: WriteStyle, pipe: Box>, ) -> Self { BufferWriter { // The inner Buffer is never printed from, but it is still needed to handle coloring and other formating inner: termcolor::BufferWriter::stderr(write_style.into_color_choice()), - test_target: if is_test { - Some(WritableTarget::Pipe(pipe)) - } else { - None - }, + uncolored_target: Some(WritableTarget::Pipe(pipe)), } } pub(in crate::fmt::writer) fn buffer(&self) -> Buffer { Buffer { inner: self.inner.buffer(), - has_test_target: self.test_target.is_some(), + has_uncolored_target: self.uncolored_target.is_some(), } } pub(in crate::fmt::writer) fn print(&self, buf: &Buffer) -> io::Result<()> { - if let Some(target) = &self.test_target { + if let Some(target) = &self.uncolored_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` @@ -164,7 +159,7 @@ impl Buffer { fn set_color(&mut self, spec: &ColorSpec) -> io::Result<()> { // Ignore styles for test captured logs because they can't be printed - if !self.has_test_target { + if !self.has_uncolored_target { self.inner.set_color(spec) } else { Ok(()) @@ -173,7 +168,7 @@ impl Buffer { fn reset(&mut self) -> io::Result<()> { // Ignore styles for test captured logs because they can't be printed - if !self.has_test_target { + if !self.has_uncolored_target { self.inner.reset() } else { Ok(())