# Allow running the script directly without running `make check`.
test "x$builddir" = x && builddir=.
+test "x$abs_builddir" = x && abs_builddir="`pwd`"
test "x$EGREP" = x && EGREP='grep -E'
# The tests fail if running under coloredstderr because the tests redirect
LC_ALL=C
unset LANGUAGE
+# Clear user defined variables.
+unset COLORED_STDERR_FDS
+unset COLORED_STDERR_FORCE_WRITE
+# Set default COLORED_STDERR_PRIVATE_FDS value.
+fds=2,
+
die() {
echo "$@" >&2
(
# Standard setup.
LD_PRELOAD="$library"
- COLORED_STDERR_FDS=2,
+ COLORED_STDERR_PRIVATE_FDS="$fds"
export LD_PRELOAD
- export COLORED_STDERR_FDS
+ export COLORED_STDERR_PRIVATE_FDS
# Change pre/post strings for simpler testing.
COLORED_STDERR_PRE='>STDERR>'
export COLORED_STDERR_PRE
export COLORED_STDERR_POST
# And force writes to a file (unless we are testing the force).
- if test "x$force_write" != x; then
+ if test -n "$force_write"; then
COLORED_STDERR_FORCE_WRITE=1
export COLORED_STDERR_FORCE_WRITE
fi
$valgrind_cmd "$@" "$testcase" > "$output" 2>&1
)
+ # Some sed implementations (e.g. on FreeBSD 9.1) always append a trailing
+ # newline. Add "EOF" to detect if the real output had one.
+ echo EOF >> "$output"
+
+ # Merge continuous regions of colored output. The exact calls don't matter
+ # as long as the output is colored.
+ sed 's/<STDERR<>STDERR>//g' < "$output" > "$output.tmp"
+ mv "$output.tmp" "$output"
+
diff -u "$expected" "$output" \
|| die 'failed!'
rm "$output"
test_script() {
testcase="$1"
+ expected="$2"
+ # shift || true is not enough for dash.
+ test $# -ge 2 && shift
shift
- run_test "$srcdir/$testcase" "$srcdir/$testcase.expected" "$@"
+
+ if test -z "$expected"; then
+ expected="$testcase"
+ fi
+ run_test "$srcdir/$testcase" "$srcdir/$expected.expected" "$@"
}
test_script_subshell() {
- test_script "$1" bash -c 'bash $1' ''
+ test_script "$1" "$2" sh -c 'sh $1' ''
}
test_program() {
testcase="$1"
+ expected="$2"
+ test $# -ge 2 && shift
shift
- run_test "$builddir/$testcase" "$srcdir/$testcase.expected" "$@"
+
+ if test -z "$expected"; then
+ expected="$testcase"
+ fi
+ run_test "$builddir/$testcase" "$srcdir/$expected.expected" "$@"
}
test_program_subshell() {
- test_program "$1" sh -c '$1' ''
+ test_program "$1" "$2" sh -c '$1' ''
}