test: target.triple.rustdocflags works for doctest

This commit is contained in:
Weihang Lo 2023-12-23 22:55:55 -05:00
parent ef39572305
commit 6131e991af
No known key found for this signature in database
GPG Key ID: D7DBF189825E82E7

View File

@ -184,3 +184,49 @@ fn target_triple_rustdocflags_works() {
.with_stderr_contains("[RUNNING] `rustdoc[..]--cfg[..]foo[..]`") .with_stderr_contains("[RUNNING] `rustdoc[..]--cfg[..]foo[..]`")
.run(); .run();
} }
#[cargo_test]
fn target_triple_rustdocflags_works_through_cargo_test() {
let host = rustc_host();
let host_env = rustc_host_env();
let p = project()
.file(
"src/lib.rs",
r#"
//! ```
//! assert!(cfg!(foo));
//! ```
"#,
)
.build();
// target.triple.rustdocflags in env works
p.cargo("test --doc -v")
.env(
&format!("CARGO_TARGET_{host_env}_RUSTDOCFLAGS"),
"--cfg=foo",
)
.with_stderr_contains("[RUNNING] `rustdoc[..]--test[..]--cfg[..]foo[..]`")
.with_stdout_contains(
"\
running 1 test
test src/lib.rs - (line 2) ... ok
test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out[..]",
)
.run();
// target.triple.rustdocflags in config works
p.cargo("test --doc -v")
.arg("--config")
.arg(format!("target.{host}.rustdocflags=['--cfg', 'foo']"))
.with_stderr_contains("[RUNNING] `rustdoc[..]--test[..]--cfg[..]foo[..]`")
.with_stdout_contains(
"\
running 1 test
test src/lib.rs - (line 2) ... ok
test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out[..]",
)
.run();
}