From e654f7d1fe5f8facc8e36a3b1c2a1816e54f9deb Mon Sep 17 00:00:00 2001 From: Weihang Lo Date: Sat, 23 Dec 2023 22:55:55 -0500 Subject: [PATCH] test: `target.triple.rustdocflags` works for doctest --- tests/testsuite/rustdocflags.rs | 46 +++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/tests/testsuite/rustdocflags.rs b/tests/testsuite/rustdocflags.rs index 6c5ae0652e71..5042969f1f11 100644 --- a/tests/testsuite/rustdocflags.rs +++ b/tests/testsuite/rustdocflags.rs @@ -184,3 +184,49 @@ fn target_triple_rustdocflags_works() { .with_stderr_contains("[RUNNING] `rustdoc[..]--cfg[..]foo[..]`") .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(); +}