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
83 #### Replace generated Content-ID headers with static value
86 sed "/^Content-ID/s/:.*/: <TESTID>/" "$@"
90 #### Filter that squeezes blank lines, partially emulating GNU cat -s,
91 #### but sufficient for our purpose.
92 #### From http://www-rohan.sdsu.edu/doc/sed.html, compiled by Eric Pement.
98 #### Filter that converts non-breakable space U+00A0 to an ASCII space.
101 sed 's/'"`printf '\\302\\240'`"'/ /g'
105 # first argument: command line to run
106 # second argument: "normspace" to normalize the whitespace
107 # stdin: expected output
110 if [ "$2" = "normspace" ]; then
111 eval "$1" 2>&1 | prepare_space >"$tmpfile"
112 diff="`prepare_space | diff -ub - "$tmpfile" || :`"
114 eval "$1" >"$tmpfile" 2>&1
115 diff="`diff -u - "$tmpfile"`"
121 failed=`expr "${failed:-0}" + 1`