Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion src/cargo/ops/cargo_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
39 changes: 39 additions & 0 deletions tests/testsuite/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}