1 # Common helper routines for test shell scripts
2 # -- intended to be sourced by them
19 # portable implementation of 'which' utility
30 if [ -f "$D/$PROG" ] && [ -x "$D/$PROG" ]; then
31 printf '%s\n' "$D/$PROG"
40 if [ -z "$(findprog $1)" ]; then
41 test_skip "missing $1"
47 for locale in "$@"; do
48 if locale -a | grep -i "$locale" >/dev/null; then
52 test_skip "no suitable locale available"
55 # Some stuff for doing silly progress indicators
58 test -t 1 || return 0 # supress progress meter if non-interactive
62 range="$(expr $last - $first ||:)"
63 prog="$(expr $this - $first ||:)"
64 # this automatically rounds to nearest integer
65 perc="$(expr 100 \* $prog / $range ||:)"
66 # note \r so next update will overwrite
67 printf "%3d%%\r" $perc
72 test -t 1 || return 0 # supress progress meter if non-interactive
78 #### Filter that squeezes blank lines, partially emulating GNU cat -s,
79 #### but sufficient for our purpose.
80 #### From http://www-rohan.sdsu.edu/doc/sed.html, compiled by Eric Pement.
86 #### Filter that converts non-breakable space U+00A0 to an ASCII space.
89 sed 's/'"`printf '\\302\\240'`"'/ /g'
93 # first argument: command line to run
94 # second argument: "normspace" to normalize the whitespace
95 # stdin: expected output
98 if [ "$2" = "normspace" ]; then
99 eval "$1" 2>&1 | prepare_space >"$tmpfile"
100 diff="`prepare_space | diff -ub - "$tmpfile" || :`"
102 eval "$1" >"$tmpfile" 2>&1
103 diff="`diff -u - "$tmpfile"`"
109 failed=`expr "${failed:-0}" + 1`