From f8d1b30ad3fe1d5fa0f172031de7c937b235f3ba Mon Sep 17 00:00:00 2001 From: Weihang Lo Date: Tue, 1 Nov 2022 14:56:20 +0000 Subject: [PATCH] test(rustdocflags): shouldn't be affected by rustflags from target.cfg --- tests/testsuite/rustdocflags.rs | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/tests/testsuite/rustdocflags.rs b/tests/testsuite/rustdocflags.rs index 44175de40..891c88a6f 100644 --- a/tests/testsuite/rustdocflags.rs +++ b/tests/testsuite/rustdocflags.rs @@ -122,3 +122,35 @@ fn whitespace() { let contents = p.read_file("target/doc/foo/index.html"); assert!(contents.contains(SPACED_VERSION)); } + +#[cargo_test] +fn not_affected_by_target_rustflags() { + let cfg = if cfg!(windows) { "windows" } else { "unix" }; + let p = project() + .file("src/lib.rs", "") + .file( + ".cargo/config", + &format!( + r#" + [target.'cfg({cfg})'] + rustflags = ["-D", "missing-docs"] + + [build] + rustdocflags = ["--cfg", "foo"] + "#, + ), + ) + .build(); + + // `cargo build` should fail due to missing docs. + p.cargo("build -v") + .with_status(101) + .with_stderr_contains("[RUNNING] `rustc [..] -D missing-docs[..]`") + .run(); + + // This is wrong behaviour. `cargo doc` shouldn't fail. + p.cargo("doc -v") + .with_status(101) + .with_stderr_contains("[RUNNING] `rustdoc [..] -D missing-docs[..]`") + .run(); +}