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 # Do a best guess at FQDN
58 hostname -f 2>/dev/null || uname -n
61 # Some stuff for doing silly progress indicators
64 test -t 1 || return 0 # suppress progress meter if non-interactive
68 range="$(expr $last - $first ||:)"
69 prog="$(expr $this - $first ||:)"
70 # this automatically rounds to nearest integer
71 perc="$(expr 100 \* $prog / $range ||:)"
72 # note \r so next update will overwrite
73 printf "%3d%%\r" $perc
78 test -t 1 || return 0 # suppress progress meter if non-interactive
84 #### Filter that squeezes blank lines, partially emulating GNU cat -s,
85 #### but sufficient for our purpose.
86 #### From http://www-rohan.sdsu.edu/doc/sed.html, compiled by Eric Pement.
92 #### Filter that converts non-breakable space U+00A0 to an ASCII space.
95 sed 's/'"`printf '\\302\\240'`"'/ /g'
99 # first argument: command line to run
100 # second argument: "normspace" to normalize the whitespace
101 # stdin: expected output
104 if [ "$2" = "normspace" ]; then
105 eval "$1" 2>&1 | prepare_space >"$tmpfile"
106 diff="`prepare_space | diff -ub - "$tmpfile" || :`"
108 eval "$1" >"$tmpfile" 2>&1
109 diff="`diff -u - "$tmpfile"`"
115 failed=`expr "${failed:-0}" + 1`