add more braces
This commit is contained in:
parent
2b0974d305
commit
b1ea7ed294
135
urchin
135
urchin
@ -280,8 +280,8 @@ report_outcome() {
|
|||||||
result=$(echo "${line}" | cut -f3)
|
result=$(echo "${line}" | cut -f3)
|
||||||
file_elapsed=$(echo "$line" | cut -f4)
|
file_elapsed=$(echo "$line" | cut -f4)
|
||||||
|
|
||||||
prevdir=$currentdir
|
prevdir="${currentdir}"
|
||||||
currentdir="$(dirname -- "$path")"
|
currentdir="$(dirname -- "${path}")"
|
||||||
|
|
||||||
# Number of files that have run, including this one
|
# Number of files that have run, including this one
|
||||||
n=$(($n + 1))
|
n=$(($n + 1))
|
||||||
@ -290,84 +290,84 @@ report_outcome() {
|
|||||||
eval "old_count=${result}s"
|
eval "old_count=${result}s"
|
||||||
eval "${result}s=$(($old_count+1))"
|
eval "${result}s=$(($old_count+1))"
|
||||||
|
|
||||||
if $tap_format; then
|
if "${tap_format}"; then
|
||||||
if [ "$result" = not_ok ]; then
|
if [ "${result}" = not_ok ]; then
|
||||||
not='not '
|
not='not '
|
||||||
else
|
else
|
||||||
not=''
|
not=''
|
||||||
fi
|
fi
|
||||||
if [ "$result" = skip ]; then
|
if [ "${result}" = skip ]; then
|
||||||
skip='# SKIP'
|
skip='# SKIP'
|
||||||
else
|
else
|
||||||
skip=''
|
skip=''
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if test -z "$the_shell"; then
|
if test -z "${the_shell}"; then
|
||||||
the_shell='File is not executable.'
|
the_shell='File is not executable.'
|
||||||
fi
|
fi
|
||||||
echo "${not}ok $n - ${path} ($the_shell) ${skip}"
|
echo "${not}ok $n - ${path} (${the_shell}) ${skip}"
|
||||||
if $verbose || [ "$result" = not_ok ]; then
|
if "${verbose}" || [ "${result}" = not_ok ]; then
|
||||||
echo '# ------------ Begin output ------------'
|
echo '# ------------ Begin output ------------'
|
||||||
sed 's/^/# /' "$(stdout_file "$abspath" "$the_shell")"
|
sed 's/^/# /' "$(stdout_file "${abspath}" "${the_shell}")"
|
||||||
echo '# ------------ End output ------------'
|
echo '# ------------ End output ------------'
|
||||||
fi
|
fi
|
||||||
echo "# Previous test took $file_elapsed seconds."
|
echo "# Previous test took ${file_elapsed} seconds."
|
||||||
else
|
else
|
||||||
if test "$prevdir" != "$currentdir"; then
|
if test "${prevdir}" != "${currentdir}"; then
|
||||||
echo
|
echo
|
||||||
fi
|
fi
|
||||||
if test "$prevpath" != "$path"; then
|
if test "${prevpath}" != "${path}"; then
|
||||||
printf "$(dirname -- "$path")/\n> $(basename -- "$path")\n"
|
printf "$(dirname -- "${path}")/\n> $(basename -- "${path}")\n"
|
||||||
fi
|
fi
|
||||||
case "$result" in
|
case "${result}" in
|
||||||
ok)
|
ok)
|
||||||
# On success, print a green '✓'
|
# On success, print a green '✓'
|
||||||
printf '\033[32m✓ \033[0m'
|
printf '\033[32m✓ \033[0m'
|
||||||
echo "${the_shell} ($file_elapsed $(plural second $file_elapsed))"
|
echo "${the_shell} ("${file_elapsed}" $(plural second $file_elapsed))"
|
||||||
;;
|
;;
|
||||||
not_ok)
|
not_ok)
|
||||||
# On not_ok, print a red '✗'
|
# On not_ok, print a red '✗'
|
||||||
printf '\033[31m✗ \033[0m'
|
printf '\033[31m✗ \033[0m'
|
||||||
echo "${the_shell} ($file_elapsed $(plural second $file_elapsed))"
|
echo "${the_shell} ("${file_elapsed}" $(plural second $file_elapsed))"
|
||||||
;;
|
;;
|
||||||
skip)
|
skip)
|
||||||
if test -z "$the_shell"; then
|
if test -z "${the_shell}"; then
|
||||||
echo ' (File is not executable.)'
|
echo ' (File is not executable.)'
|
||||||
else
|
else
|
||||||
echo " ${the_shell} ($file_elapsed $(plural second $file_elapsed))"
|
echo " ${the_shell} ("${file_elapsed}" $(plural second $file_elapsed))"
|
||||||
fi
|
fi
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
if $verbose || test "$result" = not_ok; then
|
if "${verbose}" || test "${result}" = not_ok; then
|
||||||
sed 's/^/ # /' "$(stdout_file "$abspath" "$the_shell")"
|
sed 's/^/ # /' "$(stdout_file "${abspath}" "${the_shell}")"
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
prevpath="$path"
|
prevpath="${path}"
|
||||||
done < $sorted_log_file
|
done < "${sorted_log_file}"
|
||||||
rm $sorted_log_file
|
rm "${sorted_log_file}"
|
||||||
|
|
||||||
if $tap_format; then
|
if "${tap_format}"; then
|
||||||
echo "# Full test suite took $elapsed $(plural second $elapsed)."
|
echo "# Full test suite took ${elapsed} $(plural second ${elapsed})."
|
||||||
echo 1..$n
|
echo 1.."${n}"
|
||||||
else
|
else
|
||||||
echo
|
echo
|
||||||
echo "Done, took $elapsed $(plural second $elapsed)."
|
echo "Done, took ${elapsed} $(plural second ${elapsed})."
|
||||||
printf '%s\n' "$oks $(plural test "$oks") passed."
|
printf '%s\n' "${oks} $(plural test "${oks}") passed."
|
||||||
printf '%s\n' "$skips $(plural test "$skips") skipped."
|
printf '%s\n' "${skips} $(plural test "${skips}") skipped."
|
||||||
|
|
||||||
# If any tests are not ok, print the message in red.
|
# If any tests are not ok, print the message in red.
|
||||||
if [ $not_oks -gt 0 ] ; then
|
if [ "${not_oks}" -gt 0 ] ; then
|
||||||
printf '\033[31m'
|
printf '\033[31m'
|
||||||
fi
|
fi
|
||||||
printf '%s\n' "$not_oks $(plural test "$not_oks") failed."
|
printf '%s\n' "${not_oks} $(plural test "${not_oks}") failed."
|
||||||
printf '\033[m\n'
|
printf '\033[m\n'
|
||||||
fi
|
fi
|
||||||
test "$not_oks" -eq '0'
|
test "${not_oks}" -eq '0'
|
||||||
}
|
}
|
||||||
|
|
||||||
has_shebang_line() {
|
has_shebang_line() {
|
||||||
head -n 1 "$1" | grep -qE '^#!'
|
head -n 1 "${1}" | grep -qE '^#!'
|
||||||
}
|
}
|
||||||
|
|
||||||
USAGE="usage: $0 [<options>] <test directory>"
|
USAGE="usage: $0 [<options>] <test directory>"
|
||||||
@ -375,12 +375,12 @@ USAGE="usage: $0 [<options>] <test directory>"
|
|||||||
urchin_help() {
|
urchin_help() {
|
||||||
cat <<EOF
|
cat <<EOF
|
||||||
|
|
||||||
$USAGE
|
${USAGE}
|
||||||
|
|
||||||
By default, Urchin checks for the following shells and runs every
|
By default, Urchin checks for the following shells and runs every
|
||||||
particular test file once per shell.
|
particular test file once per shell.
|
||||||
|
|
||||||
$(echo "$DEFAULT_SHELLS" | sed 's/ /\n /g')
|
$(echo "${DEFAULT_SHELLS}" | sed 's/ /\n /g')
|
||||||
|
|
||||||
On each run,
|
On each run,
|
||||||
|
|
||||||
@ -430,16 +430,16 @@ plural () {
|
|||||||
# Make $1 a plural according to the number $2.
|
# Make $1 a plural according to the number $2.
|
||||||
# If $3 is supplied, use that instead of "${1}s".
|
# If $3 is supplied, use that instead of "${1}s".
|
||||||
# Result is written to stdout.
|
# Result is written to stdout.
|
||||||
if [ "$2" = 1 ]
|
if [ "${2}" = 1 ]
|
||||||
then
|
then
|
||||||
printf '%s\n' "$1"
|
printf '%s\n' "${1}"
|
||||||
else
|
else
|
||||||
printf '%s\n' "${3-${1}s}"
|
printf '%s\n' "${3-${1}s}"
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
validate_strings() {
|
validate_strings() {
|
||||||
test $(echo "$1" | wc -l) -eq 1 || {
|
test $(echo "${1}" | wc -l) -eq 1 || {
|
||||||
echo '$1 may not contain tab or newline characters.' >&2
|
echo '$1 may not contain tab or newline characters.' >&2
|
||||||
echo 'If this is really a problem, tell me, and I may fix it.' >&2
|
echo 'If this is really a problem, tell me, and I may fix it.' >&2
|
||||||
urchin_exit 11
|
urchin_exit 11
|
||||||
@ -447,43 +447,43 @@ validate_strings() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
cycle_shell=true
|
cycle_shell=true
|
||||||
shell_list=$urchin_tmp/shell_list
|
shell_list="${urchin_tmp}"/shell_list
|
||||||
run_in_series=false
|
run_in_series=false
|
||||||
force=false
|
force=false
|
||||||
exit_on_not_ok=false
|
exit_on_not_ok=false
|
||||||
tap_format=false
|
tap_format=false
|
||||||
verbose=false
|
verbose=false
|
||||||
while [ $# -gt 0 ]
|
while [ "${#}" -gt 0 ]
|
||||||
do
|
do
|
||||||
case "$1" in
|
case "${1}" in
|
||||||
-b|--run-in-series) run_in_series=true;;
|
-b|--run-in-series) run_in_series=true;;
|
||||||
-e|--exit-on-fail) exit_on_not_ok=true;;
|
-e|--exit-on-fail) exit_on_not_ok=true;;
|
||||||
-f|--force) force=true;;
|
-f|--force) force=true;;
|
||||||
-s|--shell)
|
-s|--shell)
|
||||||
shift
|
shift
|
||||||
shell_for_sh_tests=$1
|
shell_for_sh_tests="${1}"
|
||||||
|
|
||||||
which "$shell_for_sh_tests" > /dev/null || {
|
which "${shell_for_sh_tests}" > /dev/null || {
|
||||||
echo "Cannot find specified shell: '$shell_for_sh_tests'" >&2
|
echo "Cannot find specified shell: '${shell_for_sh_tests}'" >&2
|
||||||
urchin_help >&2
|
urchin_help >&2
|
||||||
urchin_exit 11
|
urchin_exit 11
|
||||||
}
|
}
|
||||||
|
|
||||||
validate_strings "$shell_for_sh_tests" 'Shell paths'
|
validate_strings "${shell_for_sh_tests}" 'Shell paths'
|
||||||
if echo "$shell_for_sh_tests" | grep \ > /dev/null; then
|
if echo "${shell_for_sh_tests}" | grep \ > /dev/null; then
|
||||||
echo "Warning: It is best if shell paths contain no spaces so that
|
echo "Warning: It is best if shell paths contain no spaces so that
|
||||||
you don't need to quote the TEST_SHELL variable." > /dev/stderr
|
you don't need to quote the TEST_SHELL variable." > /dev/stderr
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo "$shell_for_sh_tests" >> "$shell_list"
|
echo "${shell_for_sh_tests}" >> "${shell_list}"
|
||||||
;;
|
;;
|
||||||
-n|--disable-cycling) cycle_shell=false;;
|
-n|--disable-cycling) cycle_shell=false;;
|
||||||
-t|--tap) tap_format=true;;
|
-t|--tap) tap_format=true;;
|
||||||
-T|--timeout) shift; urchin_timeout="$1" ;;
|
-T|--timeout) shift; urchin_timeout="${1}" ;;
|
||||||
-v|--verbose) verbose=true;;
|
-v|--verbose) verbose=true;;
|
||||||
-h|--help) urchin_help
|
-h|--help) urchin_help
|
||||||
urchin_exit 0;;
|
urchin_exit 0;;
|
||||||
--version) echo "$VERSION"
|
--version) echo "${VERSION}"
|
||||||
urchin_exit;;
|
urchin_exit;;
|
||||||
-*) urchin_help >&2
|
-*) urchin_help >&2
|
||||||
urchin_exit 11;;
|
urchin_exit 11;;
|
||||||
@ -492,13 +492,13 @@ you don't need to quote the TEST_SHELL variable." > /dev/stderr
|
|||||||
shift
|
shift
|
||||||
done
|
done
|
||||||
|
|
||||||
if ! $cycle_shell && test -f "$shell_list"; then
|
if ! "${cycle_shell}" && test -f "${shell_list}"; then
|
||||||
echo "The -n/--disable-cycling and -s/--shell options clash with each other." >&2
|
echo "The -n/--disable-cycling and -s/--shell options clash with each other." >&2
|
||||||
urchin_exit 11
|
urchin_exit 11
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# If -s was not passed, use the available default shells.
|
# If -s was not passed, use the available default shells.
|
||||||
if ! test -f "$shell_list"; then
|
if ! test -f "${shell_list}"; then
|
||||||
if $cycle_shell; then
|
if $cycle_shell; then
|
||||||
for shell in $DEFAULT_SHELLS; do
|
for shell in $DEFAULT_SHELLS; do
|
||||||
if which $shell > /dev/null; then
|
if which $shell > /dev/null; then
|
||||||
@ -511,43 +511,43 @@ if ! test -f "$shell_list"; then
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
# Verify argument for main stuff
|
# Verify argument for main stuff
|
||||||
if [ "$#" != '1' ] || [ ! -e "$1" ]; then
|
if [ "${#}" != '1' ] || [ ! -e "${1}" ]; then
|
||||||
if [ -n "$1" ] && [ ! -e "$1" ]; then
|
if [ -n "${1}" ] && [ ! -e "${1}" ]; then
|
||||||
echo "No such file or directory: '$1'" >&2
|
echo "No such file or directory: '${1}'" >&2
|
||||||
fi
|
fi
|
||||||
echo "$USAGE" >&2
|
echo "${USAGE}" >&2
|
||||||
urchin_exit 11
|
urchin_exit 11
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Warn about strange sort commands
|
# Warn about strange sort commands
|
||||||
weird_string='\n- c\n-- b\n--- c\n---- a\n'
|
weird_string='\n- c\n-- b\n--- c\n---- a\n'
|
||||||
if test $(printf "$weird_string" | sort | tr -d '[ \n-]') != cbca; then
|
if test $(printf "${weird_string}" | sort | tr -d '[ \n-]') != cbca; then
|
||||||
echo 'Your version of sort sorts in dictionary order (-d) by default.
|
echo 'Your version of sort sorts in dictionary order (-d) by default.
|
||||||
Depending on how you name your tests, your Urchin output may look strange.
|
Depending on how you name your tests, your Urchin output may look strange.
|
||||||
If this is a problem, install BusyBox or BSD coreutils.' >&2
|
If this is a problem, install BusyBox or BSD coreutils.' >&2
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if test -n "$urchin_timeout"; then
|
if test -n "${urchin_timeout}"; then
|
||||||
# Choose the timeout command
|
# Choose the timeout command
|
||||||
if timeout -t 0 true; then
|
if timeout -t 0 true; then
|
||||||
TIMEOUT="timeout -t $urchin_timeout"
|
TIMEOUT="timeout -t ${urchin_timeout}"
|
||||||
elif timeout 0 true; then
|
elif timeout 0 true; then
|
||||||
TIMEOUT="timeout $urchin_timeout"
|
TIMEOUT="timeout ${urchin_timeout}"
|
||||||
else
|
else
|
||||||
echo I couldn\'t figure out to use your version of timeout >&2
|
echo I couldn\'t figure out to use your version of timeout >&2
|
||||||
urchin_exit 1
|
urchin_exit 1
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if $exit_on_not_ok && ! $run_in_series; then
|
if "${exit_on_not_ok}" && ! "${run_in_series}"; then
|
||||||
echo 'You must also pass -b/--series in order to use -e/--exit-on-fail.' >&2
|
echo 'You must also pass -b/--series in order to use -e/--exit-on-fail.' >&2
|
||||||
urchin_exit 11
|
urchin_exit 11
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Run or present the Molly guard.
|
# Run or present the Molly guard.
|
||||||
root="$(urchin_root "$1")"
|
root="$(urchin_root "${1}")"
|
||||||
if basename "$(fullpath "$root")" |
|
if basename "$(fullpath "${root}")" |
|
||||||
grep -i 'test' > /dev/null || $force; then
|
grep -i 'test' > /dev/null || "${force}"; then
|
||||||
|
|
||||||
start=$(date +%s)
|
start=$(date +%s)
|
||||||
|
|
||||||
@ -555,11 +555,12 @@ if basename "$(fullpath "$root")" |
|
|||||||
# 2 urchin root
|
# 2 urchin root
|
||||||
# 3 Should we cycle shells?
|
# 3 Should we cycle shells?
|
||||||
# 4 TEST_SHELL
|
# 4 TEST_SHELL
|
||||||
recurse "$(fullpath "$1")" "$root" "$cycle_shell" "$TEST_SHELL" || :
|
recurse "$(fullpath "${1}")" "${root}" "${cycle_shell}" "${TEST_SHELL}" || :
|
||||||
finish=$(date +%s)
|
finish=$(date +%s)
|
||||||
|
|
||||||
report_outcome "$root" $tap_format $urchin_tmp/log $start $finish
|
report_outcome "${root}" "${tap_format}" "${urchin_tmp}"/log "${start}" \
|
||||||
urchin_exit $?
|
"${finish}"
|
||||||
|
urchin_exit "${?}"
|
||||||
else
|
else
|
||||||
echo 'The root directory of the tests that you are running urchin on
|
echo 'The root directory of the tests that you are running urchin on
|
||||||
does not contain the word "test", so I am not running,
|
does not contain the word "test", so I am not running,
|
||||||
@ -567,4 +568,4 @@ in case that was an accident. Use the -f flag if you really
|
|||||||
want to run urchin on that directory.' >&2
|
want to run urchin on that directory.' >&2
|
||||||
exit_code=1
|
exit_code=1
|
||||||
fi
|
fi
|
||||||
urchin_exit $exit_code
|
urchin_exit "${exit_code}"
|
||||||
|
Loading…
Reference in New Issue
Block a user