On Sun, Jul 31, 2016 at 10:17 AM, Assaf Gordon <assafgor...@gmail.com> wrote:
> Hello Jim
>
>> On Jul 31, 2016, at 03:08, Jim Meyering <j...@meyering.net> wrote:
>>
>> diffutils snapshot:
>>  http://meyering.net/diff/diffutils-3.3.50-0353.tar.xz
>>
>
> The "colors" test seems to succeed on Fedora/CentOS/SUSE systems (of various 
> versions), but fail on others (Ubuntu, Debian, FreeBSD, Mac OS X).
>
> Attached are logs from 3 systems. From a cursory look it seems the exact same 
> failure, but I haven't looked deeper.
> No other test failures found, but I'll have more results later today.

Hi Assaf,
Thank you for all the speedy testing.
I've looked into the failure on a Debian system for which /bin/sh is
dash 0.5.8-2.2.
dash's printf builtin handles \e differently -- that's easy to work
around: use \033, which *is* portable.
More surprising is that this generates no output:

  dash -c 'f() { local t=$(printf '\''\t\t'\''); printf "$t"; }; f'

I.e., piping it into wc -c prints 0.
With bash, it prints the expected pair of TAB bytes.
I found that I could work around this nonsensical behavior by hoisting
the "tab=..." definition up/out of those two functions, or by adding
standard-says-never-necessary double quotes like this:

  dash -c 'f() { local t="$(printf '\''\t\t'\'')"; printf "$t"; }; f'

However, I prefer not to work around it here (and in every other test
script where this comes up), and will insulate all of our test scripts
by rejecting any shell with that misbehavior, so plan to adjust
init.sh to select another shell when it finds this flaw.

On second thought, I will make the local change now, and sleep on the
idea of making init.sh reject dash.
Done in the attached patch.
From 8020a16ff4cd7aa1d3e4bb65f9345e950098a556 Mon Sep 17 00:00:00 2001
From: Jim Meyering <meyer...@fb.com>
Date: Sun, 31 Jul 2016 17:33:34 -0700
Subject: [PATCH] tests: colors: fix a portability problem and work around a
 shell bug

* tests/colors (e): Fix a portability bug: use printf '\033'
rather than '\e' to generate the required byte sequence, since
for some shells (at least dash 0.5.8), the latter doesn't work.
Work around a shell bug whereby "local tab=$(printf '\t')"
would result in an empty value for "$tab": hoist each "tab"
definition up/out of its function to global scope.
Reported by Assaf Gordon in http://debbugs.gnu.org/24116#8
---
 tests/colors | 34 +++++++++++++++++-----------------
 1 file changed, 17 insertions(+), 17 deletions(-)

diff --git a/tests/colors b/tests/colors
index 881c1b8..881ef5a 100755
--- a/tests/colors
+++ b/tests/colors
@@ -12,16 +12,17 @@ echo b > b

 epoch='1970-01-01 00:00:00'
 touch --date="$epoch" a b
+e=$(printf '\033')
+tab=$(printf '\t')

 gen_exp_u()
 {
-    local tab=$(printf '\t')
     local epoch_plus="$epoch.000000000 +0000"
-    local rs=$(printf "\e[${rs}m")
-    local hd=$(printf "\e[${hd}m")
-    local ad=$(printf "\e[${ad}m")
-    local de=$(printf "\e[${de}m")
-    local ln=$(printf "\e[${ln}m")
+    local rs=$(printf "$e[${rs}m")
+    local hd=$(printf "$e[${hd}m")
+    local ad=$(printf "$e[${ad}m")
+    local de=$(printf "$e[${de}m")
+    local ln=$(printf "$e[${ln}m")
     printf '%s' \
 "$hd--- a$tab$epoch_plus
 +++ b$tab$epoch_plus
@@ -33,13 +34,12 @@ $ad+b$rs

 gen_exp_c()
 {
-    local tab=$(printf '\t')
     local epoch_posix_1003_1_2001="Thu Jan  1 00:00:00 1970"
-    local rs=$(printf "\e[${rs}m")
-    local hd=$(printf "\e[${hd}m")
-    local ad=$(printf "\e[${ad}m")
-    local de=$(printf "\e[${de}m")
-    local ln=$(printf "\e[${ln}m")
+    local rs=$(printf "$e[${rs}m")
+    local hd=$(printf "$e[${hd}m")
+    local ad=$(printf "$e[${ad}m")
+    local de=$(printf "$e[${de}m")
+    local ln=$(printf "$e[${ln}m")
     printf '%s' \
 "$hd*** a$tab$epoch_posix_1003_1_2001
 --- b$tab$epoch_posix_1003_1_2001
@@ -63,11 +63,11 @@ gen_exp_default()

 gen_exp_default_colors()
 {
-    local rs=$(printf "\e[${rs}m")
-    local hd=$(printf "\e[${hd}m")
-    local ad=$(printf "\e[${ad}m")
-    local de=$(printf "\e[${de}m")
-    local ln=$(printf "\e[${ln}m")
+    local rs=$(printf "$e[${rs}m")
+    local hd=$(printf "$e[${hd}m")
+    local ad=$(printf "$e[${ad}m")
+    local de=$(printf "$e[${de}m")
+    local ln=$(printf "$e[${ln}m")
     printf '%s' \
 "${ln}1c1$rs
 $de< a$rs
-- 
2.8.0-rc2

Reply via email to