catch exit codes better

This commit is contained in:
Thomas Levine 2016-04-10 22:07:15 +00:00
parent ba20619102
commit 85a6c37dfc

23
urchin
View File

@ -329,6 +329,15 @@ test_suite_root() {
fi fi
} }
# Print the return code of a command, and suppress printing.
catch() {
if eval "${*}" &> /dev/null; then
echo 0
else
echo "$?"
fi
}
# -------------------- Metafunctions -------------------- # -------------------- Metafunctions --------------------
meta_verbosity() { meta_verbosity() {
echo "if test \${${1}} -ge ${2}; then ${3}=true; fi" echo "if test \${${1}} -ge ${2}; then ${3}=true; fi"
@ -523,21 +532,21 @@ recurse() {
. ./setup . ./setup
fi fi
out_file="$(stdout_file "${tmp_dir}" "${rel_current}" "${sh}")"
# Run with a shell? # Run with a shell?
if has_shebang_line "${abs_current}"; then if has_shebang_line "${abs_current}"; then
set -- "${abs_current}" set -- "${abs_current}"
else else
set -- "${sh}" "${abs_current}" set -- "${sh}" "${abs_current}"
fi fi
out_file="$(stdout_file "${tmp_dir}" "${rel_current}" "${sh}")"
# Run the test # Run the test
cmd='TEST_SHELL="${sh}" $TIMEOUT "$@" > "${out_file}" 2>&1'
start=$("${epoch}") start=$("${epoch}")
set +e exit_code="$(catch "${cmd}")"
TEST_SHELL="${sh}" $TIMEOUT "$@" > "${out_file}" 2>&1
exit_code="${?}"
set -e
finish=$("${epoch}") finish=$("${epoch}")
elapsed=$(($finish - $start))
if test -f teardown; then if test -f teardown; then
. ./teardown . ./teardown
@ -549,9 +558,7 @@ recurse() {
*) result=not_ok ;; *) result=not_ok ;;
esac esac
elapsed=$(($finish - $start)) log "${remote}" "${rel_curent}" "${result}" "${elapsed}" \
rel="${rel_current##"${root}/"}"
printf "\t${sh}\t${rel}\t${result}\t${elapsed}\n" \
>> "${urchin_tmp}"/log >> "${urchin_tmp}"/log
exit "${exit_code}" exit "${exit_code}"
) & ) &