outline main

This commit is contained in:
Thomas Levine 2016-04-10 20:27:56 +00:00
parent cc2c60cac0
commit af0a80d1bd
1 changed files with 95 additions and 98 deletions

193
urchin
View File

@ -421,15 +421,6 @@ format_urchin() {
fi
}
# ---------- Temporary directory global variable ----------
urchin_tmp=$(mktemp_dir)
> "${urchin_tmp}/log"
urchin_exit() {
rm -Rf "${urchin_tmp}"
exit "$@"
}
# -------------------- Main stuff --------------------
recurse() {
requested_path="${1}"
@ -584,90 +575,91 @@ report_outcome() {
main() {
# Defaults
format=urchin
while [ "${#}" -gt 0 ]
do
case "${1}" in
-b|--run-in-series) run_in_series=true;;
-e|--exit-on-fail) exit_on_not_ok=true;;
-f|--force) force=true;;
-s|--shell)
shift
shell_for_sh_tests="${1}"
if ! command -v "${shell_for_sh_tests}" > /dev/null; then
echo "Cannot find specified shell: '${shell_for_sh_tests}'" >&2
urchin_help >&2
urchin_exit 13
fi
if contains "${potential_test}" "${HT}" "${LF}"; then
echo 'Shell paths may contain all characters other than' >&2
echo 'horizontal tab (\t) and line feed (\n).' >&2
urchin_exit 11
fi
if contains "${shell_for_sh_tests}" "[${IFS}]"; then
echo "Warning: It is best if field-separator characters
(usually spaces) are absent from shell paths so that
you don't need to quote the TEST_SHELL variable." >&2
fi
shell_list="${shell_for_sh_tests}${LF}${shell_list}"
;;
-F|--format) shift ; format="${1}";;
-T|--timeout)
shift
urchin_timeout="${1}"
if ! contains "${urchin_timeout}" \
'[0-9][0-9.]*\(s\|m\|h\|d\|\)' ; then
echo Bad timeout argument: "${urchin_timeout}" >&2
urchin_exit 11
fi ;;
-p|--pretty) print_in_color=true;;
-q|--quiet) verbosity=0 ;;
-v) verbosity=2 ;;
-vv) verbosity=3 ;;
-vvv|--verbose) verbosity=4 ;;
-vvvv|--debug) verbosity=5 ;;
-h|--help) urchin_help
urchin_exit 0;;
--version) echo "${VERSION}"
urchin_exit;;
-*) urchin_help >&2
urchin_exit 11;;
*) if contains "${1}" "${HT}" "${LF}"; then
echo 'Test file names may contain all characters other than' >&2
echo 'horizontal tab (\t) and line feed (\n).' >&2
urchin_exit 11
elif [ ! -e "${1}" ]; then
echo "No such file or directory: '${1}'" >&2
echo "${USAGE}" >&2
urchin_exit 11
elif ! {
# Molly guard
root="$(test_suite_root "${1}")"
basename "$(fullpath "${root}")" |
grep -i 'test' > /dev/null || "${force}"
}; then
echo 'The root directory of the tests that you are running urchin on
does not contain the word "test", so I am not running,
in case that was an accident. Use the -f flag if you really
want to run urchin on that directory.' >&2
urchin_exit 12
fi
test_seeds="${1}${LF}${test_seeds}" ;;
esac
shift
done
if "${RUN_IN_SERIES}" 2> /dev/null; then
run_in_series=true
fi
# Shift if possible; error otherwise.
flag_arg() {
flag="${1}"
if shift; then
echo "${1}"
else
echo Missing argument for "${flag}" >&2
exit 11
fi
}
# Receive input
while [ "${#}" -gt 0 ]; do
case "${1}" in
-b|--run-in-series) run_in_series=true;;
-e|--exit-on-fail) exit_on_not_ok=true;;
-f|--force) force=true;;
-F|--format) format="$(flag_arg)" ;;
-p|--pretty) print_in_color=true;;
-q|--quiet) verbosity=0 ;;
-v) verbosity=2 ;;
-vv) verbosity=3 ;;
-vvv|--verbose) verbosity=4 ;;
-vvvv|--debug) verbosity=5 ;;
--version) echo "${VERSION}" && exit;;
-h|--help) urchin_help && exit 0;;
-s|--shell) sh="$(flag_arg)"
if ! command -v "${sh}" > /dev/null; then
echo "Cannot find specified shell: '${sh}'" >&2
urchin_help >&2
exit 13
elif contains "${potential_test}" "${HT}" "${LF}"; then
echo 'Shell paths may contain all characters other than' >&2
echo 'horizontal tab (\t) and line feed (\n).' >&2
exit 11
elif contains "${sh}" "[${IFS}]"; then
echo "Warning: It is best if field-separator characters
(usually spaces) are absent from shell paths so that
you don't need to quote the TEST_SHELL variable." >&2
fi
shell_list="${sh}${LF}${shell_list}" ;;
-T|--timeout) urchin_timeout="$(flag_arg)"
if ! contains "${urchin_timeout}" \
'[0-9][0-9.]*\(s\|m\|h\|d\|\)' ; then
echo Bad timeout argument: "${urchin_timeout}" >&2
exit 11
fi ;;
-*) urchin_help >&2 && exit 11;;
*) if contains "${1}" "${HT}" "${LF}"; then
echo 'Test file names may contain all characters other than' >&2
echo 'horizontal tab (\t) and line feed (\n).' >&2
exit 11
elif [ ! -e "${1}" ]; then
echo "No such file or directory: '${1}'" >&2
echo "${USAGE}" >&2
exit 11
elif ! {
# Molly guard
root="$(test_suite_root "${1}")"
basename "$(fullpath "${root}")" |
grep -i 'test' > /dev/null || "${force}"
}; then
echo 'The root directory of the tests that you are running urchin on
doesnot contain the word "test", so I am not running,
in case that was an accident. Use the -f flag if you really
wantto run urchin on that directory.' >&2
exit 12
fi
test_seeds="${1}${LF}${test_seeds}" ;;
esac
shift
done
# If -s was not passed, use the available default shells.
if ! is_set "${shell_list}"; then
if $cycle_shell; then
@ -687,17 +679,20 @@ want to run urchin on that directory.' >&2
TIMEOUT="timeout ${urchin_timeout}"
else
echo I couldn\'t figure out how to use your version of timeout >&2
urchin_exit 10
exit 10
fi
fi
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
urchin_exit 11
exit 11
fi
# -------------------- REALLY RUN -------------------- #
# Temporary files
urchin_tmp=$(mktemp_dir)
# Write header information
echo Running tests at $(date +%Y-%m-%dT%H:%M:%S) >> "${urchin_tmp}"/head
printf 'Cycling with the following shells: ' >> "${urchin_tmp}"/head
@ -710,16 +705,18 @@ want to run urchin on that directory.' >&2
done
finish=$("${epoch}")
if test $(cat "${urchin_tmp}"/log | wc -l) -eq 0; then
if ! test -f "${urchin_tmp}"/log ; then
echo 'No tests found' >&2
urchin_exit 2
exit_code=2
else
cat "${urchin_tmp}"/head
report_outcome "${root}" "${format}" "${urchin_tmp}"/log "${start}" \
"${finish}"
# cat "${urchin_tmp}"/foot
fi
cat "${urchin_tmp}"/head
report_outcome "${root}" "${format}" "${urchin_tmp}"/log "${start}" \
"${finish}"
# cat "${urchin_tmp}"/foot
urchin_exit "${?}"
rm -Rf "${urchin_tmp}"
exit "${exit_code}"
}
is_set TESTING_URCHIN_INTERNALS || main "$@"