summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorJim Meyering <meyering@fb.com>2016-07-31 17:33:34 -0700
committerJim Meyering <meyering@fb.com>2016-07-31 17:38:43 -0700
commit55596fcd4846a802da9bce831547a9a01e4cbe15 (patch)
tree68e371d1e4b36fffa69a83edcb52d0c0d8e72ced /tests
parent0353af91a02d1bd14b18d10293f1ef27dd6c0a58 (diff)
downloaddiffutils-55596fcd4846a802da9bce831547a9a01e4cbe15.tar.gz
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
Diffstat (limited to 'tests')
-rwxr-xr-xtests/colors34
1 files 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