From 9cca022465b6bee5f766cf317c150e791f105dbe Mon Sep 17 00:00:00 2001 From: Lukas Mai Date: Wed, 31 Jul 2024 21:55:33 +0200 Subject: [PATCH] t/porting/cpphdrcheck.t: fix cc version fallback MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The `unless ($ver)` check doesn't work as intended because `` `$cc -V 2>&1` `` captures stderr (intentionally, for Sun C). This means with gcc or clang `$ver` ends up containing a true-ish string, either gcc: error: unrecognized command-line option ā€˜-Vā€™ gcc: fatal error: no input files compilation terminated. or clang: error: argument to '-V' is missing (expected 1 value) clang: error: no input files so the `$cc --version` fallback never runs. Checking for a non-zero exit status and the word "error" in the output seems to work reliably, though. --- t/porting/cpphdrcheck.t | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/t/porting/cpphdrcheck.t b/t/porting/cpphdrcheck.t index 88c7496b0832..861fe176d5c9 100644 --- a/t/porting/cpphdrcheck.t +++ b/t/porting/cpphdrcheck.t @@ -124,7 +124,7 @@ sub find_ccpp ($cc) { # intel C, Sun C # Sun C sends -V output to stderr my $ver = `$cc -V 2>&1`; - unless ($ver) { + if (!$ver || ($? && $ver =~ /\berror\b/)) { # gcc, clang $ver = `$cc --version 2>$devnull`; }