fix shellcheck errors in 2015/howe/prog-test.sh

This commit is contained in:
Landon Curt Noll committed 2024-03-10 23:54:49 -07:00
1 parent b4af162bf7
commit 26fbfa7966
1 file changed
+33 -29
+33 -29
View File
@@ -3,13 +3,14 @@
PROG="./prog" PROG="./prog"
args=$(getopt 'f:w' $*) args=$(getopt 'f:w' "$@")
if [ $? -ne 0 ]; then status="$?"
if [[ $status -ne 0 ]]; then
echo "usage: prog-test.sh [-w][-f flags]" echo "usage: prog-test.sh [-w][-f flags]"
exit 2 exit 2
fi fi
set -- $args set -- "$args"
while [ $# -gt 0 ]; do while [[ $# -gt 0 ]]; do
case "$1" in case "$1" in
-w) -w)
PROG="./prog-w64" PROG="./prog-w64"
@@ -20,6 +21,8 @@ while [ $# -gt 0 ]; do
--) --)
shift; break shift; break
;; ;;
*)
;;
esac esac
shift shift
done done
@@ -30,17 +33,18 @@ function distance
typeset B="$1"; shift typeset B="$1"; shift
typeset expect="$1"; shift typeset expect="$1"; shift
printf "$A" | sed -e 's/./&\ printf "%s" "$A" | sed -e 's/./&\
/g' >$A.tmp /g' >"$A.tmp"
printf "$B" | sed -e 's/./&\ printf "%s" "$B" | sed -e 's/./&\
/g' >$B.tmp /g' >"$B.tmp"
echo "<<< A='$A' B='$B' $@" echo "<<< A='$A' B='$B' $*"
typeset dist=$($PROG -d $@ $A.tmp $B.tmp | tr -d '\r') typeset dist
dist=$("$PROG" -d "$@" "$A.tmp" "$B.tmp" | tr -d '\r')
printf '>>> got=%d expect=%d ' "$dist" "$expect" printf '>>> got=%d expect=%d ' "$dist" "$expect"
if [ "$dist" -ne "$expect" ]; then if [[ "$dist" -ne "$expect" ]]; then
echo FAIL echo FAIL
return 1 return 1
fi fi
@@ -56,12 +60,12 @@ function dif
typeset expect="$1"; shift typeset expect="$1"; shift
echo "==== $A $B" echo "==== $A $B"
$PROG $A $B | tee patch.tmp "$PROG" "$A" "$B" | tee patch.tmp
typeset ex=$? typeset ex=$?
if [ "$expect" -eq 0 ]; then if [[ "$expect" -eq 0 ]]; then
printf "got=%d expect=%d " $ex $expect printf "got=%d expect=%d " "$ex" "$expect"
if [ $expect -ne $ex ]; then if [[ $expect -ne $ex ]]; then
echo FAIL echo FAIL
return 1 return 1
fi fi
@@ -70,7 +74,7 @@ function dif
fi fi
printf "forward patch " printf "forward patch "
cp $A copy.tmp cp "$A" copy.tmp
if ! patch -f -s copy.tmp patch.tmp ; then if ! patch -f -s copy.tmp patch.tmp ; then
echo FAIL echo FAIL
return 1 return 1
@@ -78,7 +82,7 @@ function dif
echo -OK- echo -OK-
printf "forward compare " printf "forward compare "
if ! cmp $B copy.tmp ; then if ! cmp "$B" copy.tmp ; then
echo FAIL echo FAIL
return 1 return 1
fi fi
@@ -92,7 +96,7 @@ function dif
echo -OK- echo -OK-
printf "reverse compare " printf "reverse compare "
if ! cmp $A copy.tmp ; then if ! cmp "$A" copy.tmp ; then
echo FAIL echo FAIL
return 1 return 1
fi fi
@@ -101,17 +105,17 @@ function dif
return 0 return 0
} }
distance "1" "1" 0 $flags distance "1" "1" 0 "$flags"
distance "1" "A" 2 $flags distance "1" "A" 2 "$flags"
distance "123" "ABCDE" 8 $flags distance "123" "ABCDE" 8 "$flags"
distance "ABCDE" "123" 8 $flags distance "ABCDE" "123" 8 "$flags"
distance "ABD" "ABCD" 1 $flags distance "ABD" "ABCD" 1 "$flags"
distance "ABCD" "ABD" 1 $flags distance "ABCD" "ABD" 1 "$flags"
distance "ABCD" "ACDBECFD" 4 $flags distance "ABCD" "ACDBECFD" 4 "$flags"
distance "ABCDEF" "ABXYEFCD" 6 $flags distance "ABCDEF" "ABXYEFCD" 6 "$flags"
distance "ABCDEFGHIJK" "ABCEFGIJKDEFGHIJK" 6 $flags distance "ABCDEFGHIJK" "ABCEFGIJKDEFGHIJK" 6 "$flags"
distance "ABCABBA" "CBABAC" 5 $flags distance "ABCABBA" "CBABAC" 5 "$flags"
distance "ACEBDABBABED" "ACBDEACBED" 6 $flags distance "ACEBDABBABED" "ACBDEACBED" 6 "$flags"
touch EMPTY.tmp touch EMPTY.tmp
dif 1.tmp 1.tmp 0 dif 1.tmp 1.tmp 0