fix molly guard

This commit is contained in:
Thomas Levine 2016-03-02 21:18:40 +00:00
parent 9fecb802cb
commit 918bf31ec5

206
urchin
View File

@ -445,109 +445,120 @@ validate_strings() {
} }
} }
cycle_shell=true main() {
shell_list="${urchin_tmp}"/shell_list cycle_shell=true
run_in_series=false shell_list="${urchin_tmp}"/shell_list
force=false run_in_series=false
exit_on_not_ok=false force=false
tap_format=false exit_on_not_ok=false
verbose=false tap_format=false
while [ "${#}" -gt 0 ] verbose=false
do while [ "${#}" -gt 0 ]
case "${1}" in do
-b|--run-in-series) run_in_series=true;; case "${1}" in
-e|--exit-on-fail) exit_on_not_ok=true;; -b|--run-in-series) run_in_series=true;;
-f|--force) force=true;; -e|--exit-on-fail) exit_on_not_ok=true;;
-s|--shell) -f|--force) force=true;;
shift -s|--shell)
shell_for_sh_tests="${1}" shift
shell_for_sh_tests="${1}"
which "${shell_for_sh_tests}" > /dev/null || {
echo "Cannot find specified shell: '${shell_for_sh_tests}'" >&2 which "${shell_for_sh_tests}" > /dev/null || {
urchin_help >&2 echo "Cannot find specified shell: '${shell_for_sh_tests}'" >&2
urchin_exit 11 urchin_help >&2
} 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;;
*) break;; *) break;;
esac esac
shift shift
done done
if ! "${cycle_shell}" && test -f "${shell_list}"; then # -------------------- VALIDATE INPUT -------------------- #
echo "The -n/--disable-cycling and -s/--shell options clash with each other." >&2 if ! "${cycle_shell}" && test -f "${shell_list}"; then
urchin_exit 11 echo "The -n/--disable-cycling and -s/--shell options clash with each other." >&2
fi urchin_exit 11
# If -s was not passed, use the available default shells.
if ! test -f "${shell_list}"; then
if $cycle_shell; then
for shell in $DEFAULT_SHELLS; do
if which $shell > /dev/null; then
echo $shell >> "$shell_list"
fi
done
else
echo > "$shell_list"
fi fi
fi
# Verify argument for main stuff # If -s was not passed, use the available default shells.
if [ "${#}" != '1' ] || [ ! -e "${1}" ]; then if ! test -f "${shell_list}"; then
if [ -n "${1}" ] && [ ! -e "${1}" ]; then if $cycle_shell; then
echo "No such file or directory: '${1}'" >&2 for shell in $DEFAULT_SHELLS; do
if which $shell > /dev/null; then
echo $shell >> "$shell_list"
fi
done
else
echo > "$shell_list"
fi
fi fi
echo "${USAGE}" >&2
urchin_exit 11
fi
# Warn about strange sort commands # Verify argument for main stuff
weird_string='\n- c\n-- b\n--- c\n---- a\n' if [ "${#}" != '1' ] || [ ! -e "${1}" ]; then
if test $(printf "${weird_string}" | sort | tr -d '[ \n-]') != cbca; then if [ -n "${1}" ] && [ ! -e "${1}" ]; then
echo 'Your version of sort sorts in dictionary order (-d) by default. echo "No such file or directory: '${1}'" >&2
Depending on how you name your tests, your Urchin output may look strange. fi
If this is a problem, install BusyBox or BSD coreutils.' >&2 echo "${USAGE}" >&2
fi urchin_exit 11
fi
if test -n "${urchin_timeout}"; then # Warn about strange sort commands
# Choose the timeout command weird_string='\n- c\n-- b\n--- c\n---- a\n'
if timeout -t 0 true; then if test $(printf "${weird_string}" | sort | tr -d '[ \n-]') != cbca; then
TIMEOUT="timeout -t ${urchin_timeout}" echo 'Your version of sort sorts in dictionary order (-d) by default.
elif timeout 0 true; then Depending on how you name your tests, your Urchin output may look strange.
TIMEOUT="timeout ${urchin_timeout}" If this is a problem, install BusyBox or BSD coreutils.' >&2
else fi
echo I couldn\'t figure out to use your version of timeout >&2
if test -n "${urchin_timeout}"; then
# Choose the timeout command
if timeout -t 0 true; then
TIMEOUT="timeout -t ${urchin_timeout}"
elif timeout 0 true; then
TIMEOUT="timeout ${urchin_timeout}"
else
echo I couldn\'t figure out to use your version of timeout >&2
urchin_exit 1
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
fi
# Molly guard.
root="$(urchin_root "${1}")"
if ! {
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 1 urchin_exit 1
fi 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
fi
# Run or present the Molly guard.
root="$(urchin_root "${1}")"
if basename "$(fullpath "${root}")" |
grep -i 'test' > /dev/null || "${force}"; then
# -------------------- REALLY RUN -------------------- #
start=$(date +%s) start=$(date +%s)
# 1 test file or folder to run # 1 test file or folder to run
@ -560,11 +571,6 @@ if basename "$(fullpath "${root}")" |
report_outcome "${root}" "${tap_format}" "${urchin_tmp}"/log "${start}" \ report_outcome "${root}" "${tap_format}" "${urchin_tmp}"/log "${start}" \
"${finish}" "${finish}"
urchin_exit "${?}" urchin_exit "${?}"
else }
echo 'The root directory of the tests that you are running urchin on
does not contain the word "test", so I am not running, main "$@"
in case that was an accident. Use the -f flag if you really
want to run urchin on that directory.' >&2
exit_code=1
fi
urchin_exit "${exit_code}"