Bruno Haible <[email protected]> writes:

>> Is removing LD_LIBRARY_PATH along with all other environment variables
>> causing the trouble? Yes.
>
> So, in summary, I think the best fix is to make the test a SKIP
> if one of these environment variables is set (cf.
> gnulib/build-aux/config.libpath):
>
>   LD_LIBRARY_PATH     (used in ELF systems)
>   LD_32_LIBRARY_PATH  (used in FreeBSD)
>   DYLD_LIBRARY_PATH   (used in macOS)
>   LIBPATH             (used in AIX, OS/2)
>   PATH                (only on Windows)

Makes sense to me, thanks for the explanation.

I pushed the attatched patch which skips the test of those, other than
PATH, are set.

Collin

>From bbde83899d6f76c50ad202879144432184e84293 Mon Sep 17 00:00:00 2001
Message-ID: <bbde83899d6f76c50ad202879144432184e84293.1758325355.git.collin.fu...@gmail.com>
From: Collin Funk <[email protected]>
Date: Fri, 19 Sep 2025 16:32:52 -0700
Subject: [PATCH] tests: env: skip a few tests if LD_LIBRARY_PATH is set

* tests/env/env-null.sh: Skip test if LD_LIBRARY_PATH or platform's
equivalent is set, since 'env -i' will unset it which may prevent
programs from running.
* tests/env/env-S.pl: Likewise.
Issue and suggested fix reported by Bruno Haible.
---
 tests/env/env-S.pl    | 13 +++++++++++++
 tests/env/env-null.sh | 10 ++++++++++
 2 files changed, 23 insertions(+)

diff --git a/tests/env/env-S.pl b/tests/env/env-S.pl
index 2d12c1843..6e01975c7 100755
--- a/tests/env/env-S.pl
+++ b/tests/env/env-S.pl
@@ -27,6 +27,19 @@ $env =~ m!^([-+\@\w./]+)$!
   or CuSkip::skip "unusual absolute builddir name; skipping this test\n";
 $env = $1;
 
+# We may depend on a library found in LD_LIBRARY_PATH, or an equivalent
+# environment variable.  Skip the test if it is set since unsetting it may
+# prevent us from running commands.
+foreach my $var (qw(LD_LIBRARY_PATH LD_32_LIBRARY_PATH DYLD_LIBRARY_PATH
+                    LIBPATH))
+  {
+    if (exists $ENV{$var})
+      {
+        CuSkip::skip ("programs may depend on $var being set; "
+                      . "skipping this test\n");
+      }
+  }
+
 # Turn off localization of executable's output.
 @ENV{qw(LANGUAGE LANG LC_ALL)} = ('C') x 3;
 
diff --git a/tests/env/env-null.sh b/tests/env/env-null.sh
index 27d8c5fb2..c62e87402 100755
--- a/tests/env/env-null.sh
+++ b/tests/env/env-null.sh
@@ -19,6 +19,16 @@
 . "${srcdir=.}/tests/init.sh"; path_prepend_ ./src
 print_ver_ env printenv
 
+# We may depend on a library found in LD_LIBRARY_PATH, or an equivalent
+# environment variable.  Skip the test if it is set since unsetting it may
+# prevent us from running commands.
+for var in LD_LIBRARY_PATH LD_32_LIBRARY_PATH DYLD_LIBRARY_PATH LIBPATH; do
+  eval val=\$$var
+  if test -n "$val"; then
+    skip_ "programs may depend on $var being set"
+  fi
+done
+
 # POSIX is clear that environ may, but need not be, sorted.
 # Environment variable values may contain newlines, which cannot be
 # observed by merely inspecting output from env.
-- 
2.51.0

Reply via email to