From caadd7d7f035bd55dff0803408b400430cc0f8c7 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Mon, 19 Jul 2021 15:03:52 +0200 Subject: [PATCH 1/2] Correctly handle --nocapture option for rustdoc --- src/cargo/ops/cargo_test.rs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/cargo/ops/cargo_test.rs b/src/cargo/ops/cargo_test.rs index 9fcb94f1336..d5c18d8be07 100644 --- a/src/cargo/ops/cargo_test.rs +++ b/src/cargo/ops/cargo_test.rs @@ -233,7 +233,15 @@ fn run_doc_tests( } for arg in test_args { - p.arg("--test-args").arg(arg); + // We special-case "--nocapture" because rustdoc needs to handle it directly. + if *arg == "--nocapture" { + // FIXME(GuillaumeGomez): remove the `unstable-options` once rustdoc stabilizes the + // `--nocapture` option. + p.arg("-Z").arg("unstable-options"); + p.arg(arg); + } else { + p.arg("--test-args").arg(arg); + } } p.args(args); From 0b39bb9fe16fd154a15defdbc7a08a4fb1b19cdc Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Mon, 19 Jul 2021 15:07:03 +0200 Subject: [PATCH 2/2] Add test for rustdoc --nocapture --- tests/testsuite/test.rs | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/tests/testsuite/test.rs b/tests/testsuite/test.rs index 5ed6198c864..3896138dd10 100644 --- a/tests/testsuite/test.rs +++ b/tests/testsuite/test.rs @@ -4388,3 +4388,42 @@ fn test_workspaces_cwd() { .with_stdout_contains("test test_integration_deep_cwd ... ok") .run(); } + +#[cargo_test] +fn doctest_nocapture() { + let p = project() + .file( + "Cargo.toml", + r#" + [package] + name = "foo" + version = "0.0.1" + authors = [] + [features] + bar = [] + "#, + ) + .file( + "src/lib.rs", + r#" + /// ```rust + /// println!("hello cake!"); + /// ``` + pub fn hello() {} + "#, + ) + .build(); + + p.cargo("test -- --nocapture") + .with_stderr( + "\ +[COMPILING] foo [..] +[FINISHED] test [unoptimized + debuginfo] target(s) in [..] +[RUNNING] [..] (target/debug/deps/foo[..][EXE]) +[DOCTEST] foo", + ) + .with_stdout_contains("running 0 tests") + .with_stdout_contains("test [..] ... ok") + .with_stdout_contains("hello cake!") + .run(); +}