Skip to content

Commit 8ee5433

Browse files
committed
doc test supports silent output
Signed-off-by: hi-rustin <[email protected]>
1 parent 5ccb5a3 commit 8ee5433

File tree

2 files changed

+71
-0
lines changed

2 files changed

+71
-0
lines changed

src/cargo/ops/cargo_test.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,10 @@ fn run_doc_tests(
236236
p.arg("--test-args").arg(arg);
237237
}
238238

239+
if config.shell().verbosity() == Verbosity::Quiet {
240+
p.arg("--test-args").arg("--quiet");
241+
}
242+
239243
p.args(args);
240244

241245
if *unstable_opts {

tests/testsuite/test.rs

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,73 @@ fn cargo_test_quiet_no_harness() {
216216
p.cargo("test -q").with_stdout("").with_stderr("").run();
217217
}
218218

219+
#[cargo_test]
220+
fn cargo_doc_test_quiet() {
221+
let p = project()
222+
.file(
223+
"Cargo.toml",
224+
r#"
225+
[package]
226+
name = "foo"
227+
version = "0.1.0"
228+
authors = []
229+
"#,
230+
)
231+
.file(
232+
"src/lib.rs",
233+
r#"
234+
/// ```
235+
/// let result = foo::add(2, 3);
236+
/// assert_eq!(result, 5);
237+
/// ```
238+
pub fn add(a: i32, b: i32) -> i32 {
239+
a + b
240+
}
241+
242+
/// ```
243+
/// let result = foo::div(10, 2);
244+
/// assert_eq!(result, 5);
245+
/// ```
246+
///
247+
/// # Panics
248+
///
249+
/// The function panics if the second argument is zero.
250+
///
251+
/// ```rust,should_panic
252+
/// // panics on division by zero
253+
/// foo::div(10, 0);
254+
/// ```
255+
pub fn div(a: i32, b: i32) -> i32 {
256+
if b == 0 {
257+
panic!("Divide-by-zero error");
258+
}
259+
260+
a / b
261+
}
262+
263+
#[test] fn test_hello() {}
264+
"#,
265+
)
266+
.build();
267+
268+
p.cargo("test -q")
269+
.with_stdout(
270+
"
271+
running 1 test
272+
.
273+
test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out[..]
274+
275+
276+
running 3 tests
277+
...
278+
test result: ok. 3 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out[..]
279+
280+
",
281+
)
282+
.with_stderr("")
283+
.run();
284+
}
285+
219286
#[cargo_test]
220287
fn cargo_test_verbose() {
221288
let p = project()

0 commit comments

Comments
 (0)