]> git.ipfire.org Git - thirdparty/gnulib.git/commitdiff
tests: avoid grep in init.sh
authorPaul Eggert <eggert@cs.ucla.edu>
Sun, 21 Sep 2025 20:49:18 +0000 (13:49 -0700)
committerPaul Eggert <eggert@cs.ucla.edu>
Sun, 21 Sep 2025 20:49:18 +0000 (13:49 -0700)
* tests/init.sh (warn_, gl_shell_test_script_):
Avoid the use of grep, as that introduces an unwanted dependency.
On older systems like Solaris there can be many greps and they
can be buggy, so it’s better to not rely on them in a central
part of the test harness.

ChangeLog
tests/init.sh

index feb005dfbe6869f9f671061f602188f44e3c9288..270fa5168dc84bd9d510f61a0d54cfca907e825c 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,12 @@
 2025-09-21  Paul Eggert  <eggert@cs.ucla.edu>
 
+       tests: avoid grep in init.sh
+       * tests/init.sh (warn_, gl_shell_test_script_):
+       Avoid the use of grep, as that introduces an unwanted dependency.
+       On older systems like Solaris there can be many greps and they
+       can be buggy, so it’s better to not rely on them in a central
+       part of the test harness.
+
        tests: avoid test failure due to rmdir race
        * tests/init.sh (remove_tmp_): If the rm -rf fails, wait a second
        and try again.  This works around a problem I observed on Solaris
index 1c81eb753715529dfdb1bb41d0581556281afc26..21a438987bbd03da9914f7fa248190de3de7e0c5 100644 (file)
@@ -103,7 +103,11 @@ warn_ ()
   case $IFS in
     ' '*) printf '%s\n' "$*" >&2
           test $stderr_fileno_ = 2 \
-            || { printf '%s\n' "$*" | sed 1q >&$stderr_fileno_ ; } ;;
+            || { local args=$*
+                 local firstline=${args%%"$gl_init_sh_nl_"*}
+                 printf '%s\n' "$firstline" >&$stderr_fileno_
+               }
+          ;;
     *) (IFS=' '; warn_ "$@");;
   esac
 }
@@ -160,12 +164,12 @@ fi
 #  ? - not ok
 gl_shell_test_script_='
 test $(echo y) = y || exit 1
-LC_ALL=en_US.UTF-8 printf "\\351" 2>/dev/null \
-  | LC_ALL=C tr "\\351" x | LC_ALL=C grep "^x$" > /dev/null \
-  || exit 1
-printf "\\351" 2>/dev/null \
-  | LC_ALL=C tr "\\351" x | LC_ALL=C grep "^x$" > /dev/null \
-  || exit 1
+case $({ LC_ALL=en_US.UTF-8 printf "\\351"
+         printf "\\351\\n"
+       } 2>/dev/null | LC_ALL=C tr "\\351" x) in
+  xx) ;;
+  *) exit 1;;
+esac
 f_local_() { local v=1; }; f_local_ || exit 1
 f_dash_local_fail_() { local t=$(printf " 1"); }; f_dash_local_fail_
 score_=10