diff --git a/2015/howe/prog-test.sh b/2015/howe/prog-test.sh index d5411829e..55a8293cd 100755 --- a/2015/howe/prog-test.sh +++ b/2015/howe/prog-test.sh @@ -3,13 +3,14 @@ PROG="./prog" -args=$(getopt 'f:w' $*) -if [ $? -ne 0 ]; then +args=$(getopt 'f:w' "$@") +status="$?" +if [[ $status -ne 0 ]]; then echo "usage: prog-test.sh [-w][-f flags]" exit 2 fi -set -- $args -while [ $# -gt 0 ]; do +set -- "$args" +while [[ $# -gt 0 ]]; do case "$1" in -w) PROG="./prog-w64" @@ -20,6 +21,8 @@ while [ $# -gt 0 ]; do --) shift; break ;; + *) + ;; esac shift done @@ -30,17 +33,18 @@ function distance typeset B="$1"; shift typeset expect="$1"; shift - printf "$A" | sed -e 's/./&\ -/g' >$A.tmp - printf "$B" | sed -e 's/./&\ -/g' >$B.tmp + printf "%s" "$A" | sed -e 's/./&\ +/g' >"$A.tmp" + printf "%s" "$B" | sed -e 's/./&\ +/g' >"$B.tmp" - echo "<<< A='$A' B='$B' $@" - typeset dist=$($PROG -d $@ $A.tmp $B.tmp | tr -d '\r') + echo "<<< A='$A' B='$B' $*" + typeset dist + dist=$("$PROG" -d "$@" "$A.tmp" "$B.tmp" | tr -d '\r') printf '>>> got=%d expect=%d ' "$dist" "$expect" - if [ "$dist" -ne "$expect" ]; then + if [[ "$dist" -ne "$expect" ]]; then echo FAIL return 1 fi @@ -56,12 +60,12 @@ function dif typeset expect="$1"; shift echo "==== $A $B" - $PROG $A $B | tee patch.tmp + "$PROG" "$A" "$B" | tee patch.tmp typeset ex=$? - if [ "$expect" -eq 0 ]; then - printf "got=%d expect=%d " $ex $expect - if [ $expect -ne $ex ]; then + if [[ "$expect" -eq 0 ]]; then + printf "got=%d expect=%d " "$ex" "$expect" + if [[ $expect -ne $ex ]]; then echo FAIL return 1 fi @@ -70,7 +74,7 @@ function dif fi printf "forward patch " - cp $A copy.tmp + cp "$A" copy.tmp if ! patch -f -s copy.tmp patch.tmp ; then echo FAIL return 1 @@ -78,7 +82,7 @@ function dif echo -OK- printf "forward compare " - if ! cmp $B copy.tmp ; then + if ! cmp "$B" copy.tmp ; then echo FAIL return 1 fi @@ -92,7 +96,7 @@ function dif echo -OK- printf "reverse compare " - if ! cmp $A copy.tmp ; then + if ! cmp "$A" copy.tmp ; then echo FAIL return 1 fi @@ -101,17 +105,17 @@ function dif return 0 } -distance "1" "1" 0 $flags -distance "1" "A" 2 $flags -distance "123" "ABCDE" 8 $flags -distance "ABCDE" "123" 8 $flags -distance "ABD" "ABCD" 1 $flags -distance "ABCD" "ABD" 1 $flags -distance "ABCD" "ACDBECFD" 4 $flags -distance "ABCDEF" "ABXYEFCD" 6 $flags -distance "ABCDEFGHIJK" "ABCEFGIJKDEFGHIJK" 6 $flags -distance "ABCABBA" "CBABAC" 5 $flags -distance "ACEBDABBABED" "ACBDEACBED" 6 $flags +distance "1" "1" 0 "$flags" +distance "1" "A" 2 "$flags" +distance "123" "ABCDE" 8 "$flags" +distance "ABCDE" "123" 8 "$flags" +distance "ABD" "ABCD" 1 "$flags" +distance "ABCD" "ABD" 1 "$flags" +distance "ABCD" "ACDBECFD" 4 "$flags" +distance "ABCDEF" "ABXYEFCD" 6 "$flags" +distance "ABCDEFGHIJK" "ABCEFGIJKDEFGHIJK" 6 "$flags" +distance "ABCABBA" "CBABAC" 5 "$flags" +distance "ACEBDABBABED" "ACBDEACBED" 6 "$flags" touch EMPTY.tmp dif 1.tmp 1.tmp 0