This commit is contained in:
Thomas Levine 2016-04-10 18:42:58 +00:00
parent 3ceba43410
commit 4db468ef2e

110
urchin
View File

@ -300,12 +300,24 @@ urchin_root() {
fi
}
# -------------------- Metafunctions --------------------
meta_verbosity() {
echo "if test \${${1}} -gt ${2}; then ${3}=true; fi"
}
# -------------------- Printing output --------------------
# Format functions may read a log file from stdin.
format_tap() {
result="${1}"
remote="${2}" # may be ''
the_shell="${3}"
path="${4}"
v="${1}"
tmp_dir="${2}"
$(verbosity v 2 print_not_ok_stdout)
$(verbosity v 3 print_ok_stdout)
while IFS="${HT}" read remote the_shell path result file_elapsed; do
# Number of files that have run, including this one
n=$(( ${n:-0} + 1))
if test -z "${the_shell}"; then
the_shell='File is not executable.'
@ -323,26 +335,33 @@ format_tap() {
echo '# ------------ End output ------------'
fi
echo "# Previous test took ${file_elapsed} seconds."
}
# -------------------- Metafunctions --------------------
meta_verbosity() {
echo "if test \${verbosity} -gt ${1}; then ${2}=true; fi"
}
# Number of files that have been ok, not ok, and skipped
eval "old_count=${result}s"
eval "${result}s=$(($old_count+1))"
$(verbosity 1 print_margins)
$(verbosity 1 print_not_ok)
$(verbosity 2 print_not_ok_stdout)
$(verbosity 2 print_ok)
$(verbosity 3 print_ok_stdout)
done
}
format_urchin() {
result="${1}"
remote="${2}" # may be ''
the_shell="${3}"
path="${4}"
verbosity="${5}"
v="${1}"
tmp_dir="${2}"
verbosity="${3}"
print_in_color="${4}"
$(verbosity v 1 print_margins)
$(verbosity v 1 print_not_ok)
$(verbosity v 2 print_not_ok_stdout)
$(verbosity v 2 print_ok)
$(verbosity v 3 print_ok_stdout)
if $print_in_color; then
success_mark=$(printf "\033[32m✓ \033[0m")
fail_mark=$(printf "\033[31m✗ \033[0m")
else
success_mark=.\
fail_mark=F\
fi
header() {
if test "${prevdir}" != "${currentdir}"; then
@ -353,26 +372,24 @@ format_urchin() {
fi
}
while IFS="${HT}" read remote the_shell path result file_elapsed; do
abspath=${urchin_tmp}/${path}
currentdir="$(dirname -- "${path}")"
prevdir="${currentdir}"
case "${result}" in
ok)
if "${print_ok}"; then
header
if "${print_in_color}"; then
printf "\033[32m${success_mark} \033[0m"
else
printf "${success_mark} "
fi
echo "${the_shell} ("${file_elapsed}" $(plural second $file_elapsed))"
fi
;;
not_ok)
if "${print_not_ok}"; then
header
if "${print_in_color}"; then
printf "\033[31m${fail_mark} \033[0m"
else
printf "${fail_mark} "
fi
echo "${the_shell} ("${file_elapsed}" $(plural second $file_elapsed))"
fi
;;
@ -391,6 +408,8 @@ format_urchin() {
{ test "${result}" = ok && "${print_ok_stdout}"; }; then
sed 's/^/ | /' "$(stdout_file "${path}" "${the_shell}")"
fi
prevpath="${path}"
done
}
# -------------------- Main stuff --------------------
@ -557,21 +576,6 @@ report_outcome() {
sorted_log_file=$(mktemp_file)
cat "${log_file}" | LC_COLLATE=C sort > "${sorted_log_file}"
while IFS="${HT}" read path the_shell result file_elapsed; do
abspath=${urchin_tmp}/${path}
prevdir="${currentdir}"
currentdir="$(dirname -- "${path}")"
# Number of files that have run, including this one
n=$(($n + 1))
# Number of files that have been ok, not ok, and skipped
eval "old_count=${result}s"
eval "${result}s=$(($old_count+1))"
prevpath="${path}"
done < "${sorted_log_file}"
rm "${sorted_log_file}"
if test "${format}" = tap; then
@ -581,17 +585,9 @@ report_outcome() {
if "${print_margins}"; then
echo
echo "Done, took ${elapsed} $(plural second ${elapsed})."
printf '%s\n' "${oks} $(plural test "${oks}") passed."
printf '%s\n' "${skips} $(plural test "${skips}") skipped."
# If any tests are not ok, print the message in red.
if [ "${not_oks}" -gt 0 ] && "${print_in_color}"; then
printf '\033[31m'
fi
printf '%s\n' "${not_oks} $(plural test "${not_oks}") failed."
if "${print_in_color}"; then
printf '\033[m\n'
fi
echo "${oks} $(plural test "${oks}") passed."
echo "${skips} $(plural test "${skips}") skipped."
echo "${not_oks} $(plural test "${not_oks}") failed."
fi
fi
test "${not_oks}" -eq '0'
@ -700,14 +696,6 @@ want to run urchin on that directory.' >&2
run_in_series=true
fi
if $print_in_color; then
success_mark=✓
fail_mark=✗
else
success_mark=.
fail_mark=F
fi
# -------------------- VALIDATE INPUT -------------------- #
if ! "${cycle_shell}" && ! is_set shell_list; then
echo "The -n/--disable-cycling and -s/--shell options clash with each other." >&2