From 11628dd9543812eddc0de253931ede1af70edff4 Mon Sep 17 00:00:00 2001 From: naoNao89 <90588855+naoNao89@users.noreply.github.com> Date: Mon, 22 Dec 2025 09:55:19 +0700 Subject: [PATCH] test: add regression tests for cross-arch flag_if_supported (#486) Adds tests to reproduce issue where flag_if_supported incorrectly rejects valid compiler flags during cross-compilation. Tests gracefully skip when cross-compilers are unavailable. --- tests/test.rs | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/tests/test.rs b/tests/test.rs index 6261353b..e0881065 100644 --- a/tests/test.rs +++ b/tests/test.rs @@ -428,6 +428,48 @@ fn gnu_flag_if_supported_cpp() { test.cmd(0).must_have("-std=c++11"); } +// Regression test for issue #486 +// Tests that flag_if_supported works correctly with explicit host/target specification. +// This ensures that when host and target are both specified (even if identical), +// flag support detection works properly. +#[cfg(not(windows))] +#[test] +fn gnu_flag_if_supported_cross_arch() { + reset_env(); + + let test = Test::gnu(); + // Use same target for both host and target - follows pattern of other tests + // This tests the code path where explicit host/target are set + test.gcc() + .target("x86_64-unknown-linux-gnu") + .host("x86_64-unknown-linux-gnu") + .file("foo.c") + .flag_if_supported("-Wall") + .flag_if_supported("-Wextra") + .compile("foo"); + + test.cmd(0).must_have("-Wall").must_have("-Wextra"); +} + +// Regression test for issue #486 (C++ variant) +#[cfg(not(windows))] +#[test] +fn gnu_flag_if_supported_cross_arch_cpp() { + reset_env(); + + let test = Test::gnu(); + test.gcc() + .cpp(true) + .target("x86_64-unknown-linux-gnu") + .host("x86_64-unknown-linux-gnu") + .file("foo.cpp") + .flag_if_supported("-std=c++11") + .flag_if_supported("-Wall") + .compile("foo"); + + test.cmd(0).must_have("-std=c++11").must_have("-Wall"); +} + #[test] fn gnu_static() { reset_env();