outline main

This commit is contained in:
Thomas Levine 2016-04-10 20:27:56 +00:00
parent cc2c60cac0
commit af0a80d1bd

127
urchin
View File

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