From 0d174f92c3b8bab951f02b2c72b880f4e573dc93 Mon Sep 17 00:00:00 2001 From: Avery Pennarun Date: Fri, 12 Oct 2018 03:49:22 -0400 Subject: [PATCH] redo-sh: downgrade failures that affected dash; add a bash warning. I feel a little dirty doing this, but the way the code was before, redo almost always picked bash as the shell. bash is way too overpowered and this led to bashisms in do scripts unnecessarily. The two failures in dash are things that I would really like to have, but they haven't materialized after 6 years, so I guess we should be realistic. To appropriately penalize bash for asking for trouble, I added a warning about [ 1 == 1 ] syntax being valid (as opposed to the POSIX correct [ 1 = 1 ]). This allows dash to be selected ahead of bash. I also moved 'sh' to the end of the list, because although it's the weakest shell on some systems, on other systems it's just bash. And I put zsh in front of bash, because fewer people have zsh and we want them to test zsh. --- redo-sh.do | 4 ++-- t/dotparams.od | 2 +- t/shelltest.od | 20 ++++++++++++++++---- 3 files changed, 19 insertions(+), 7 deletions(-) diff --git a/redo-sh.do b/redo-sh.do index 0140e4d..468ddde 100644 --- a/redo-sh.do +++ b/redo-sh.do @@ -11,8 +11,8 @@ WARN= # powerful ones. We want weaker shells to take precedence, as long as they # pass the tests, because weaker shells are more likely to point out when you # use some non-portable feature. -for sh in dash sh /usr/xpg4/bin/sh ash posh mksh ksh ksh88 ksh93 pdksh \ - bash zsh busybox; do +for sh in dash /usr/xpg4/bin/sh ash posh mksh ksh ksh88 ksh93 pdksh \ + zsh bash busybox sh; do printf "%-30s" "Testing $sh..." FOUND=`which $sh 2>/dev/null` || { echo "missing"; continue; } diff --git a/t/dotparams.od b/t/dotparams.od index ab00bf4..36fa5f0 100644 --- a/t/dotparams.od +++ b/t/dotparams.od @@ -1,2 +1,2 @@ # call this as ". ./dotparams.od a b" from shelltest.od -[ "$1" = a ] && [ "$2" = b ] && [ "$#" = 2 ] || fail 115 +[ "$1" = a ] && [ "$2" = b ] && [ "$#" = 2 ] || warn 115 diff --git a/t/shelltest.od b/t/shelltest.od index c9059c6..1014032 100644 --- a/t/shelltest.od +++ b/t/shelltest.od @@ -111,7 +111,10 @@ f3=$(quiet_stderr eval ': ${f3:= g3=" a b" -[ "$f3" = "$g3" ] || fail 18 +# This is kind of a major problem, but rejecting dash and busybox sh because +# of this may cause more trouble than it's worth: people end up writing .do +# scripts with bashisms unnecessarily :( +[ "$f3" = "$g3" ] || warn 18 # Note: assignment of $@ in this context is unspecified (what do you even expect @@ -371,11 +374,20 @@ false . ./nothing.od || warn 114 # this is actually a bash/kshism, but is allowed by POSIX: the parameters to -# '.' should be passed to the sub-script. Because it's so useful, let's -# require it, even though it's not strictly required by POSIX. +# '.' should be passed to the sub-script. +# +# We used to require this, because it's so useful despite being optional in POSIX. +# But unfortunately, too many shells (including dash) can't do it, so we ended up +# always using bash, which leads people to write .do scripts with bashisms. set x y z -. ./dotparams.od a b || fail 115 +# dotparams.od might warn 115 +. ./dotparams.od a b || fail 117 [ "$1-$2-$3" = "x-y-z" ] || fail 116 +# Warn about the way bash allows '==' in its test command. +# This is the #1 bashism I've observed, and totally unnecessary, so let's +# dock it some points so it doesn't always end up as the primary shell. +[ 1 == 1 ] 2>/dev/null && warn 118 + [ -n "$FAIL" ] || exit 40 exit $FAIL