Skip to content

Commit 84b701d

Browse files
niklasjplatte
authored andcommitted
Change Pipe to always use the test (uncolored) semantics
Pipe only worked in test contexts before.
1 parent 9edf205 commit 84b701d

File tree

2 files changed

+10
-15
lines changed

2 files changed

+10
-15
lines changed

src/fmt/writer/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ impl Builder {
193193
let writer = match mem::take(&mut self.target) {
194194
WritableTarget::Stderr => BufferWriter::stderr(self.is_test, color_choice),
195195
WritableTarget::Stdout => BufferWriter::stdout(self.is_test, color_choice),
196-
WritableTarget::Pipe(pipe) => BufferWriter::pipe(self.is_test, color_choice, pipe),
196+
WritableTarget::Pipe(pipe) => BufferWriter::pipe(color_choice, pipe),
197197
};
198198

199199
Writer {

src/fmt/writer/termcolor/extern_impl.rs

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -71,19 +71,19 @@ impl Formatter {
7171

7272
pub(in crate::fmt::writer) struct BufferWriter {
7373
inner: termcolor::BufferWriter,
74-
test_target: Option<WritableTarget>,
74+
uncolored_target: Option<WritableTarget>,
7575
}
7676

7777
pub(in crate::fmt) struct Buffer {
7878
inner: termcolor::Buffer,
79-
has_test_target: bool,
79+
has_uncolored_target: bool,
8080
}
8181

8282
impl BufferWriter {
8383
pub(in crate::fmt::writer) fn stderr(is_test: bool, write_style: WriteStyle) -> Self {
8484
BufferWriter {
8585
inner: termcolor::BufferWriter::stderr(write_style.into_color_choice()),
86-
test_target: if is_test {
86+
uncolored_target: if is_test {
8787
Some(WritableTarget::Stderr)
8888
} else {
8989
None
@@ -94,7 +94,7 @@ impl BufferWriter {
9494
pub(in crate::fmt::writer) fn stdout(is_test: bool, write_style: WriteStyle) -> Self {
9595
BufferWriter {
9696
inner: termcolor::BufferWriter::stdout(write_style.into_color_choice()),
97-
test_target: if is_test {
97+
uncolored_target: if is_test {
9898
Some(WritableTarget::Stdout)
9999
} else {
100100
None
@@ -103,30 +103,25 @@ impl BufferWriter {
103103
}
104104

105105
pub(in crate::fmt::writer) fn pipe(
106-
is_test: bool,
107106
write_style: WriteStyle,
108107
pipe: Box<Mutex<dyn io::Write + Send + 'static>>,
109108
) -> Self {
110109
BufferWriter {
111110
// The inner Buffer is never printed from, but it is still needed to handle coloring and other formating
112111
inner: termcolor::BufferWriter::stderr(write_style.into_color_choice()),
113-
test_target: if is_test {
114-
Some(WritableTarget::Pipe(pipe))
115-
} else {
116-
None
117-
},
112+
uncolored_target: Some(WritableTarget::Pipe(pipe)),
118113
}
119114
}
120115

121116
pub(in crate::fmt::writer) fn buffer(&self) -> Buffer {
122117
Buffer {
123118
inner: self.inner.buffer(),
124-
has_test_target: self.test_target.is_some(),
119+
has_uncolored_target: self.uncolored_target.is_some(),
125120
}
126121
}
127122

128123
pub(in crate::fmt::writer) fn print(&self, buf: &Buffer) -> io::Result<()> {
129-
if let Some(target) = &self.test_target {
124+
if let Some(target) = &self.uncolored_target {
130125
// This impl uses the `eprint` and `print` macros
131126
// instead of `termcolor`'s buffer.
132127
// This is so their output can be captured by `cargo test`
@@ -164,7 +159,7 @@ impl Buffer {
164159

165160
fn set_color(&mut self, spec: &ColorSpec) -> io::Result<()> {
166161
// Ignore styles for test captured logs because they can't be printed
167-
if !self.has_test_target {
162+
if !self.has_uncolored_target {
168163
self.inner.set_color(spec)
169164
} else {
170165
Ok(())
@@ -173,7 +168,7 @@ impl Buffer {
173168

174169
fn reset(&mut self) -> io::Result<()> {
175170
// Ignore styles for test captured logs because they can't be printed
176-
if !self.has_test_target {
171+
if !self.has_uncolored_target {
177172
self.inner.reset()
178173
} else {
179174
Ok(())

0 commit comments

Comments
 (0)