1 # Library for the test suite.
3 # Copyright (C) 2013-2014 Simon Ruderich
5 # This program is free software: you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation, either version 3 of the License, or
8 # (at your option) any later version.
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with this program. If not, see <http://www.gnu.org/licenses/>.
21 # Allow running the script directly without running `make check`.
22 test "x$builddir" = x && builddir=.
23 test "x$abs_builddir" = x && abs_builddir="`pwd`"
24 test "x$EGREP" = x && EGREP='grep -E'
26 # The tests fail if running under coloredstderr because the tests redirect
27 # stderr to stdout which is detected by coloredstderr :D (and not colored as a
28 # result). Therefore remove LD_PRELOAD and re-exec the test.
29 if test -n "$LD_PRELOAD"; then
34 # Use valgrind to run the tests if it's available.
36 if type valgrind >/dev/null 2>&1; then
37 valgrind_cmd='valgrind --quiet --error-exitcode=1'
40 # Clean locale for reproducible tests.
44 # Clear user defined variables.
45 unset COLORED_STDERR_FDS
46 unset COLORED_STDERR_FORCE_WRITE
47 # Set default COLORED_STDERR_PRIVATE_FDS value.
57 # Get name of the real library file from libtool's .la file.
58 dlname=`$EGREP "^dlname='" "$builddir/../src/libcoloredstderr.la"` \
59 || die 'dlname not found'
60 dlname=`echo "$dlname" | sed "s/^dlname='//; s/'$//"`
62 library="$builddir/../src/.libs/$dlname"
63 test -e "$library" || die "'$library' not found"
68 library=`get_library_path`
73 printf '%s' "Running test '$*' .. "
85 COLORED_STDERR_PRIVATE_FDS="$fds"
87 export COLORED_STDERR_PRIVATE_FDS
89 # Change pre/post strings for simpler testing.
90 COLORED_STDERR_PRE='>STDERR>'
91 COLORED_STDERR_POST='<STDERR<'
92 export COLORED_STDERR_PRE
93 export COLORED_STDERR_POST
94 # And force writes to a file (unless we are testing the force).
95 if test -n "$force_write"; then
96 COLORED_STDERR_FORCE_WRITE=1
97 export COLORED_STDERR_FORCE_WRITE
100 $valgrind_cmd "$@" "$testcase" > "$output" 2>&1
103 # Some sed implementations (e.g. on FreeBSD 9.1) always append a trailing
104 # newline. Add "EOF" to detect if the real output had one.
105 echo EOF >> "$output"
107 # Merge continuous regions of colored output. The exact calls don't matter
108 # as long as the output is colored.
109 sed 's/<STDERR<>STDERR>//g' < "$output" > "$output.tmp"
110 mv "$output.tmp" "$output"
112 diff -u "$expected" "$output" \
121 # shift || true is not enough for dash.
122 test $# -ge 2 && shift
125 if test -z "$expected"; then
128 run_test "$srcdir/$testcase" "$srcdir/$expected.expected" "$@"
130 test_script_subshell() {
131 test_script "$1" "$2" sh -c 'sh $1' ''
136 test $# -ge 2 && shift
139 if test -z "$expected"; then
142 run_test "$builddir/$testcase" "$srcdir/$expected.expected" "$@"
144 test_program_subshell() {
145 test_program "$1" "$2" sh -c '$1' ''