From a547d19af794a4e35007f0a393f229bc2e098af9 Mon Sep 17 00:00:00 2001 From: Greg Morenz Date: Mon, 1 Jul 2024 19:08:32 -0400 Subject: [PATCH] Add test verifying behavior in #10744 --- tests/testsuite/rustflags.rs | 44 ++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/tests/testsuite/rustflags.rs b/tests/testsuite/rustflags.rs index 507bca7c8e7..bd7bf6ef8d1 100644 --- a/tests/testsuite/rustflags.rs +++ b/tests/testsuite/rustflags.rs @@ -1587,3 +1587,47 @@ fn host_config_rustflags_with_target() { .arg("host.rustflags=[\"--cfg=foo\"]") .run(); } + +#[cargo_test] +fn target_applies_to_host_rustflags_works() { + // Ensures that rustflags are passed to the target when + // target_applies_to_host=false + let p = project() + .file( + "src/lib.rs", + r#"#[cfg(feature = "flag")] compile_error!("flag passed");"#, + ) + .build(); + + // Use RUSTFLAGS to pass an argument that would generate an error + // but it is ignored. + p.cargo("check") + .masquerade_as_nightly_cargo(&["target-applies-to-host"]) + .arg("-Ztarget-applies-to-host") + .env("CARGO_TARGET_APPLIES_TO_HOST", "false") + .env("RUSTFLAGS", r#"--cfg feature="flag""#) + .with_status(0) + .run(); +} + +#[cargo_test] +fn target_applies_to_host_rustdocflags_works() { + // Ensures that rustflags are passed to the target when + // target_applies_to_host=false + let p = project() + .file( + "src/lib.rs", + r#"#[cfg(feature = "flag")] compile_error!("flag passed");"#, + ) + .build(); + + // Use RUSTFLAGS to pass an argument that would generate an error + // but it is ignored. + p.cargo("doc") + .masquerade_as_nightly_cargo(&["target-applies-to-host"]) + .arg("-Ztarget-applies-to-host") + .env("CARGO_TARGET_APPLIES_TO_HOST", "false") + .env("RUSTDOCFLAGS", r#"--cfg feature="flag""#) + .with_status(0) + .run(); +}