Skip to content

Commit 1d01cc6

Browse files
committed
Hide implementation details of OutputLocation<T> from JsonFormatter.
1 parent a3ac553 commit 1d01cc6

File tree

2 files changed

+10
-10
lines changed

2 files changed

+10
-10
lines changed

library/test/src/console.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ pub fn list_tests_console(opts: &TestOpts, tests: Vec<TestDescAndFn>) -> io::Res
208208
Box::new(PrettyFormatter::new(&mut output, false, 0, false, None))
209209
}
210210
OutputFormat::Terse => Box::new(TerseFormatter::new(output, false, 0, false)),
211-
OutputFormat::Json => Box::new(JsonFormatter::new(output)),
211+
OutputFormat::Json => Box::new(JsonFormatter::new(&mut output)),
212212
};
213213
let mut st = ConsoleTestDiscoveryState::new(opts)?;
214214

@@ -335,7 +335,7 @@ pub fn run_tests_console(opts: &TestOpts, tests: Vec<TestDescAndFn>) -> io::Resu
335335
OutputFormat::Terse => {
336336
Box::new(TerseFormatter::new(output, opts.use_color(), max_name_len, is_multithreaded))
337337
}
338-
OutputFormat::Json => Box::new(JsonFormatter::new(output)),
338+
OutputFormat::Json => Box::new(JsonFormatter::new(&mut output)),
339339
OutputFormat::Junit => Box::new(JunitFormatter::new(output)),
340340
};
341341
let mut st = ConsoleTestState::new(opts)?;

library/test/src/formatters/json.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
1-
use std::{borrow::Cow, io, io::prelude::Write};
1+
use std::{borrow::Cow, io};
22

33
use super::OutputFormatter;
44
use crate::{
5-
console::{ConsoleTestDiscoveryState, ConsoleTestState, OutputLocation},
5+
console::{ConsoleTestDiscoveryState, ConsoleTestState, Output},
66
test_result::TestResult,
77
time,
88
types::TestDesc,
99
};
1010

11-
pub(crate) struct JsonFormatter<T> {
12-
out: OutputLocation<T>,
11+
pub(crate) struct JsonFormatter<'a> {
12+
out: &'a mut dyn Output,
1313
}
1414

15-
impl<T: Write> JsonFormatter<T> {
16-
pub fn new(out: OutputLocation<T>) -> Self {
15+
impl<'a> JsonFormatter<'a> {
16+
pub fn new(out: &'a mut dyn Output) -> Self {
1717
Self { out }
1818
}
1919

@@ -23,7 +23,7 @@ impl<T: Write> JsonFormatter<T> {
2323
// by issuing `write_all` calls line-by-line.
2424
assert_eq!(s.chars().last(), Some('\n'));
2525

26-
self.out.write_all(s.as_ref())
26+
self.out.write_plain(s)
2727
}
2828

2929
fn write_event(
@@ -56,7 +56,7 @@ impl<T: Write> JsonFormatter<T> {
5656
}
5757
}
5858

59-
impl<T: Write> OutputFormatter for JsonFormatter<T> {
59+
impl OutputFormatter for JsonFormatter<'_> {
6060
fn write_discovery_start(&mut self) -> io::Result<()> {
6161
self.writeln_message(concat!(r#"{ "type": "suite", "event": "discovery" }"#, "\n"))
6262
}

0 commit comments

Comments
 (0)