Improve test framework: better progress output

This commit is contained in:
Andrew Bettison 2013-01-31 13:52:57 +11:00
parent 7b984bbd92
commit ac18b895e3

View File

@ -211,7 +211,7 @@ runTests() {
$_tfw_stop_on_error && [ $_tfw_errorcount -ne 0 ] && break $_tfw_stop_on_error && [ $_tfw_errorcount -ne 0 ] && break
$_tfw_stop_on_failure && [ $_tfw_failcount -ne 0 ] && break $_tfw_stop_on_failure && [ $_tfw_failcount -ne 0 ] && break
# Start the next test in a child process. # Start the next test in a child process.
_tfw_echo_intro $testPosition $testNumber $testName _tfw_echo_progress $testPosition $testNumber $testName
if $_tfw_verbose || [ $_tfw_njobs -ne 1 ]; then if $_tfw_verbose || [ $_tfw_njobs -ne 1 ]; then
echo echo
fi fi
@ -313,12 +313,6 @@ _tfw_killtests() {
done done
} }
_tfw_echo_intro() {
local docvar="doc_$3"
echo -n "$2. ${!docvar:-$3}..."
[ $1 -gt $_tfw_test_number_watermark ] && _tfw_test_number_watermark=$1
}
_tfw_harvest_processes() { _tfw_harvest_processes() {
# <incantation> # <incantation>
# This is the only way known to get the effect of a 'wait' builtin that will # This is the only way known to get the effect of a 'wait' builtin that will
@ -364,22 +358,18 @@ _tfw_harvest_processes() {
esac esac
local lines local lines
if ! $_tfw_verbose && [ $_tfw_njobs -eq 1 ]; then if ! $_tfw_verbose && [ $_tfw_njobs -eq 1 ]; then
echo -n " " _tfw_echo_progress $testPosition $testNumber $testName $result
_tfw_echo_result "$result"
echo echo
elif ! $_tfw_verbose && lines=$($_tfw_tput lines); then elif ! $_tfw_verbose && lines=$($_tfw_tput lines); then
local travel=$(($_tfw_test_number_watermark - $testPosition + 1)) local travel=$(($_tfw_test_number_watermark - $testPosition + 1))
if [ $travel -gt 0 -a $travel -lt $lines ] && $_tfw_tput cuu $travel ; then if [ $travel -gt 0 -a $travel -lt $lines ] && $_tfw_tput cuu $travel ; then
_tfw_echo_intro $testPosition $testNumber $testName _tfw_echo_progress $testPosition $testNumber $testName $result
echo -n " "
_tfw_echo_result "$result"
echo echo
travel=$(($_tfw_test_number_watermark - $testPosition)) travel=$(($_tfw_test_number_watermark - $testPosition))
[ $travel -gt 0 ] && $_tfw_tput cud $travel [ $travel -gt 0 ] && $_tfw_tput cud $travel
fi fi
else else
echo -n "$testNumber. ... " _tfw_echo_progress $testPosition $testNumber $testName $result
_tfw_echo_result "$result"
echo echo
fi fi
else else
@ -390,6 +380,15 @@ _tfw_harvest_processes() {
_tfw_running_jobs=(${surviving_jobs[*]}) _tfw_running_jobs=(${surviving_jobs[*]})
} }
_tfw_echo_progress() {
local docvar="doc_$3"
echo -n -e '\r'
echo -n "$2 ["
_tfw_echo_result "$4"
echo -n "] ${!docvar:-$3}"
[ $1 -gt $_tfw_test_number_watermark ] && _tfw_test_number_watermark=$1
}
_tfw_echo_result() { _tfw_echo_result() {
local result="$1" local result="$1"
case "$result" in case "$result" in
@ -404,14 +403,17 @@ _tfw_echo_result() {
$_tfw_tput setaf 2 $_tfw_tput setaf 2
echo -n "$result" echo -n "$result"
$_tfw_tput op $_tfw_tput op
echo -n "."
;; ;;
FAIL) FAIL)
$_tfw_tput setaf 1 $_tfw_tput setaf 1
echo -n "$result" echo -n "$result"
$_tfw_tput op $_tfw_tput op
echo -n "."
;; ;;
*) *)
echo -n "$result" result="$result....."
echo -n "${result:0:5}"
;; ;;
esac esac
} }