summaryrefslogtreecommitdiffstats
path: root/tests/run.sh
diff options
context:
space:
mode:
authorTavian Barnes <tavianator@tavianator.com>2024-05-22 16:12:37 -0400
committerTavian Barnes <tavianator@tavianator.com>2024-05-22 16:12:37 -0400
commit59b1c525c4c7c254dce702fca0fa472616a976d2 (patch)
tree6df8b88d03b541d2eea43184ec98fd4c625b70fa /tests/run.sh
parent98191107e1dd2d186604bdb58990e020fc04c24e (diff)
downloadbfs-59b1c525c4c7c254dce702fca0fa472616a976d2.tar.xz
tests: Print progress outside the scroll region
Diffstat (limited to 'tests/run.sh')
-rw-r--r--tests/run.sh66
1 files changed, 22 insertions, 44 deletions
diff --git a/tests/run.sh b/tests/run.sh
index 629f756..87f94b4 100644
--- a/tests/run.sh
+++ b/tests/run.sh
@@ -5,23 +5,6 @@
## Running test cases
-# Beginning/end of line escape sequences
-BOL=$'\n'
-EOL=$'\n'
-
-# Update $EOL for the terminal size
-update_eol() {
- # Bash gets $COLUMNS from stderr, so if it's redirected use tput instead
- local cols="${COLUMNS-}"
- if [ -z "$cols" ]; then
- cols=$(tput cols 2>/dev/tty)
- fi
-
- # Put the cursor at the last column, then write a space so the next
- # character will wrap
- EOL=$'\e['"${cols}G "
-}
-
# ERR trap for tests
debug_err() {
local ret=$? line func file
@@ -64,19 +47,19 @@ run_test() {
case $ret in
0)
if ((VERBOSE_TESTS)); then
- color printf "${BOL}${GRN}[PASS]${RST} ${BLD}%s${RST}\n" "$TEST"
+ color printf "${GRN}[PASS]${RST} ${BLD}%s${RST}\n" "$TEST"
fi
;;
$EX_SKIP)
if ((VERBOSE_SKIPPED || VERBOSE_TESTS)); then
- color printf "${BOL}${CYN}[SKIP]${RST} ${BLD}%s${RST}\n" "$TEST"
+ color printf "${CYN}[SKIP]${RST} ${BLD}%s${RST}\n" "$TEST"
fi
;;
*)
if ((!VERBOSE_ERRORS)); then
cat "$TMP/$TEST.err" >&2
fi
- color printf "${BOL}${RED}[FAIL]${RST} ${BLD}%s${RST}\n" "$TEST"
+ color printf "${RED}[FAIL]${RST} ${BLD}%s${RST}\n" "$TEST"
;;
esac
@@ -173,35 +156,24 @@ comake() {
exec {READY_PIPE}<&${COPROC[0]} {DONE_PIPE}>&${COPROC[1]}
}
-# Run all the tests
-run_tests() {
- if ((VERBOSE_TESTS)); then
- BOL=''
- elif ((COLOR_STDOUT)); then
- # Carriage return + clear line
- BOL=$'\r\e[K'
-
- # Workaround for bash 4: checkwinsize is off by default. We can turn it
- # on, but we also have to explicitly trigger a foreground job to finish
- # so that it will update the window size before we use $COLUMNS
- shopt -s checkwinsize
- (:)
-
- update_eol
- trap update_eol WINCH
+# Print the current test progess
+progress() {
+ if [ "${BAR:-}" ]; then
+ print_bar "$(printf "$@")"
+ elif ((VERBOSE_TESTS)); then
+ color printf "$@"
fi
+}
+# Run all the tests
+run_tests() {
passed=0
failed=0
skipped=0
ran=0
total=${#TEST_CASES[@]}
- if ((COLOR_STDOUT || VERBOSE_TESTS)); then
- TEST_FMT="${BOL}${YLW}[%3d%%]${RST} ${BLD}%s${RST}${EOL}"
- else
- TEST_FMT="."
- fi
+ TEST_FMT="${YLW}[%3d%%]${RST} ${BLD}%s${RST}\\n"
if ((${#MAKE[@]})); then
comake
@@ -210,6 +182,10 @@ run_tests() {
# Turn off set -e (but turn it back on in run_test)
set +e
+ if ((COLOR_STDOUT && !VERBOSE_TESTS)); then
+ show_bar
+ fi
+
for TEST in "${TEST_CASES[@]}"; do
wait_ready
if ((STOP && failed > 0)); then
@@ -217,7 +193,7 @@ run_tests() {
fi
percent=$((100 * ran / total))
- color printf "$TEST_FMT" $percent "$TEST"
+ progress "${YLW}[%3d%%]${RST} ${BLD}%s${RST}\\n" $percent "$TEST"
mkdir -p "$TMP/$TEST"
OUT="$TMP/$TEST.out"
@@ -230,7 +206,10 @@ run_tests() {
wait_test
done
- printf "${BOL}"
+ if [ "${BAR:-}" ]; then
+ progress "${YLW}[100%%]${RST} ${BLD}%3d${RST} / ${BLD}%d${RST}\n" $ran $total
+ hide_bar
+ fi
if ((passed > 0)); then
color printf "${GRN}[PASS]${RST} ${BLD}%3d${RST} / ${BLD}%d${RST}\n" $passed $total
@@ -262,7 +241,6 @@ skip() {
if ((VERBOSE_SKIPPED)); then
caller | {
read -r line file
- printf "${BOL}"
debug "$file" $line "" >&$DUPOUT
}
fi