From 04adaa20ec137fc9fd58d8337bbe366511430805 Mon Sep 17 00:00:00 2001 From: Anders Eurenius Date: Thu, 7 Jul 2016 15:33:15 +0200 Subject: [PATCH] Shellcheck cleanliness Sadly, this also means we have to let go of some more shells, but that's a non-issue, since the problems with OS-X / BSD shell have meant specifying bash anyway. --- all_shells.sh | 6 ------ git-test | 37 ++++++++++++++++--------------------- test.sh | 12 ++++++------ 3 files changed, 22 insertions(+), 33 deletions(-) delete mode 100755 all_shells.sh diff --git a/all_shells.sh b/all_shells.sh deleted file mode 100755 index 68914ba..0000000 --- a/all_shells.sh +++ /dev/null @@ -1,6 +0,0 @@ -#!/bin/sh - -for sh in /bin/dash /bin/bash /bin/ksh /bin/mksh /bin/pdksh; do - echo Using $sh - $sh "$@" || exit $? -done diff --git a/git-test b/git-test index f10a0bc..e79b024 100755 --- a/git-test +++ b/git-test @@ -18,11 +18,11 @@ set -e VERSION=1.0.2 -NONGIT_OK=Yes -SUBDIRECTORY_OK=Yes -OPTIONS_KEEPDASHDASH= -OPTIONS_STUCKLONG=t -OPTIONS_SPEC="\ +export NONGIT_OK=Yes +export SUBDIRECTORY_OK=Yes +export OPTIONS_KEEPDASHDASH= +export OPTIONS_STUCKLONG=t +export OPTIONS_SPEC="\ git test [options] [refs...] git test --clear [refs...] @@ -96,7 +96,7 @@ progress () { else if [ -z "$GIT_QUIET" ]; then if [ -n "$verbose" ] ; then - printf "$CR" 1>& $ERR + printf "%s" "$CR" 1>& $ERR fi printf "%04d | %s | %s | " \ "$iteration" "$short" "$small" 1>& $OUT @@ -107,12 +107,9 @@ progress () { } -second_word() { - echo $2 -} - tree_of_commit() { - second_word $(git cat-file -p "$1" | grep tree) + words=( $(git cat-file -p "$1" | grep tree) ) + printf "%s" "${words[1]}" } make_output_dirs() { @@ -303,7 +300,7 @@ run_tests() { link_result - iteration=$(expr $iteration + 1) + iteration=$((iteration + 1)) done } @@ -429,8 +426,8 @@ if [ $action = clear ] ; then if test -z "$*" ; then rm -f "$cache"/*_fail "$cache"/*_pass else - refs="$(decide_refs "$@")" - commits="$(git rev-list --reverse $refs -- | tr "$NL" " ")" + refs=( $(decide_refs "$@") ) + commits="$(git rev-list --reverse "${refs[@]}" -- | tr "$NL" " ")" count="$(echo "$commits" | wc -w)" if test 1 -gt "$count" ; then @@ -467,17 +464,15 @@ or exit 5 fi -refs="$(decide_refs "$@")" -refs="${refs% }" -commits="$(git rev-list --reverse $refs -- | tr "$NL" " ")" -count="$(echo "$commits" | wc -w)" +refs=( $(decide_refs "$@") ) +commits=( $(git rev-list --reverse "${refs[@]}" -- | tr "$NL" " ") ) +count="$(echo "${commits[@]}" | wc -w)" if test 1 -gt "$count" ; then gettext 'List of commits to test is empty' 1>&2 exit elif test -z "$GIT_QUIET" ; then - eval_gettext "\$refs will test \$count commits -" + printf "$(eval_gettext "%s will test %d commits\n")" "${refs[*]}" "$count" fi trap "atexit_cleanup" INT TERM EXIT @@ -486,6 +481,6 @@ lock make_output_dirs -run_tests $commits +run_tests "${commits[@]}" exit 1 diff --git a/test.sh b/test.sh index 8f590d2..70d35fa 100644 --- a/test.sh +++ b/test.sh @@ -1,4 +1,4 @@ -#!/bin/sh +#!/bin/bash # # Copyright 2014-2015 Spotify AB. All rights reserved. # @@ -15,7 +15,7 @@ # the License. # export OPTIONS_SPEC="\ -sh $0 [options] +bash $0 [options] Run tests @@ -45,7 +45,7 @@ last="" pass=0 fail=0 -shshell=${shshell:-/bin/sh} +shshell=${shshell:-/bin/bash} total_argc=$# while [ $# != 0 ] @@ -98,16 +98,16 @@ dot() { if [ $quit -gt 0 ] && ! [ -n "$1" ]; then if [ $verb -lt 2 ]; then - echo "\n$last" + printf "\n%s\n" "$last" fi exit 5 fi } info() { - last="$@" + last="$*" if [ $verb -ge 2 ]; then - echo "$@" + printf "%s\n" "$@" fi }