Hi Paul,

> I'm thinking we should install the attached patch into Gnulib. The basic idea 
> is
> that running these test scripts in random locales is likely more trouble than
> it's worth.

No no no. Applied to grep's init.sh, it would reduce the test coverage of
grep. But applied to gnulib's init.sh, it would reduce the test coverage of
gettext, libunistring, coreutils, findutils, gzip, and many other packages.
I *vehemently* object against that.

> the patch to grep that you
> proposed wouldn't suffice, because the test scripts have several other uses of
> printf with octal escapes outside of ASCII range, and they'd all have to be
> changed.

Yeah, sure. But we have learned to write "LC_ALL=C tr ..." instead of "tr ...".
We can also learn to write "LC_ALL=C printf ..." instead of "printf ...".

Alternatively, you may define printf as a shell function in init.cfg.

> Also, I worry that for platforms where printf is a builtin, "LC_ALL=C printf
> '\202'" won't work as POSIX requires because historically setting environment
> variables has been buggy for shell builtins.

On the AIX 7.2 /bin/sh, I verified that 'LC_ALL=C printf ...' works,
On the other shells, printf of octals is known to be locale independent,
therefore it doesn't matter whether the LC_ALL=C assignment has an effect
on the printf command or not.

> which cwould seem to require that the shell itself, not merely the printf
> command, be in a locale that is compatible with the byte sequence in question.

If that is the case - which I doubt, because why would backquote expansion
or other things a shell does work differently in an UTF-8 locale -, the fix
would be to let init.sh respawn with a different shell. The respawning condition
in init.sh lines 159..175 could be extended to include printf '\351'.
I've verified that the attached patch fixes the two reported tests from the
'grep' test suite.

Should I push that?

Bruno
>From 23106e7111ae86d959c738a22df4cba1c94221bf Mon Sep 17 00:00:00 2001
From: Bruno Haible <br...@clisp.org>
Date: Thu, 26 Dec 2019 12:29:20 +0100
Subject: [PATCH] test-framework-sh: Avoid /bin/sh on AIX 7.2 due to its printf
 built-in.

Reported by Paul Eggert in
<https://lists.gnu.org/archive/html/grep-devel/2019-12/msg00020.html>.

* tests/init.sh (gl_shell_test_script_): Add a test of printf of an
octal escape sequence in a UTF-8 locale.
---
 ChangeLog     | 8 ++++++++
 tests/init.sh | 3 +++
 2 files changed, 11 insertions(+)

diff --git a/ChangeLog b/ChangeLog
index 70b4662..4c5f7f2 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2019-12-26  Bruno Haible  <br...@clisp.org>
+
+	test-framework-sh: Avoid /bin/sh on AIX 7.2 due to its printf built-in.
+	Reported by Paul Eggert in
+	<https://lists.gnu.org/archive/html/grep-devel/2019-12/msg00020.html>.
+	* tests/init.sh (gl_shell_test_script_): Add a test of printf of an
+	octal escape sequence in a UTF-8 locale.
+
 2019-12-26  Paul Eggert  <egg...@cs.ucla.edu>
 
 	mbrtowc: port better to narrow-wchar_t platforms
diff --git a/tests/init.sh b/tests/init.sh
index 8ca5c90..e66851b 100644
--- a/tests/init.sh
+++ b/tests/init.sh
@@ -129,6 +129,8 @@ else
 fi
 
 # We require $(...) support unconditionally.
+# We require that the printf built-in works correctly regarding octal escapes;
+# this eliminates /bin/sh on AIX 7.2.
 # We require non-surprising "local" semantics (this eliminates dash).
 # This takes the admittedly draconian step of eliminating dash, because the
 # assignment tab=$(printf '\t') works fine, yet preceding it with "local "
@@ -158,6 +160,7 @@ fi
 #  ? - not ok
 gl_shell_test_script_='
 test $(echo y) = y || exit 1
+LC_ALL=en_US.UTF-8 printf '\351' 2>/dev/null | od -t x1 | grep e9 > /dev/null || exit 1
 f_local_() { local v=1; }; f_local_ || exit 1
 f_dash_local_fail_() { local t=$(printf " 1"); }; f_dash_local_fail_
 score_=10
-- 
2.7.4

Reply via email to