X-Git-Url: https://ruderich.org/simon/gitweb/?a=blobdiff_plain;ds=sidebyside;f=tests%2Flib.sh;h=b1c8bc0276e22ac23215726fdb086e307ea990bb;hb=1e02760898c1ac458f0079f353855ce7064bc4fe;hp=94807699c8f305c2bd207031986257beeffa7c5d;hpb=fb9548453fbc0dedc8f145e8468fc601de784c32;p=coloredstderr%2Fcoloredstderr.git
diff --git a/tests/lib.sh b/tests/lib.sh
index 9480769..b1c8bc0 100644
--- a/tests/lib.sh
+++ b/tests/lib.sh
@@ -15,13 +15,27 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see .
+set -e
+
# Allow running the script directly without running `make check`.
test "x$builddir" = x && builddir=.
test "x$EGREP" = x && EGREP='grep -E'
-# In case we are called with LD_PRELOAD already set.
-unset LD_PRELOAD
+# The tests fail if running under coloredstderr because the tests redirect
+# stderr to stdout which is detected by coloredstderr :D (and not colored as a
+# result). Therefore remove LD_PRELOAD and re-exec the test.
+if test -n "$LD_PRELOAD"; then
+ unset LD_PRELOAD
+ exec "$0"
+fi
+
+# Use valgrind to run the tests if it's available.
+valgrind_cmd=
+if type valgrind >/dev/null 2>&1; then
+ valgrind_cmd='valgrind --quiet --error-exitcode=1'
+fi
+
# Clean locale for reproducible tests.
LC_ALL=C
unset LANGUAGE
@@ -56,6 +70,8 @@ run_test() {
shift
shift
+ output="output-$$"
+
(
# Standard setup.
LD_PRELOAD="$library"
@@ -64,8 +80,8 @@ run_test() {
export COLORED_STDERR_FDS
# Change pre/post strings for simpler testing.
- COLORED_STDERR_PRE='>stderr>'
- COLORED_STDERR_POST=' output 2>&1
+ $valgrind_cmd "$@" "$testcase" > "$output" 2>&1
)
- diff -u "$expected" output \
+ diff -u "$expected" "$output" \
|| die 'failed!'
- rm output
+ rm "$output"
echo 'passed.'
}
test_script() {
- run_test "$srcdir/$1" "$srcdir/$1.expected"
+ testcase="$1"
+ shift
+ run_test "$srcdir/$testcase" "$srcdir/$testcase.expected" "$@"
+}
+test_script_subshell() {
+ test_script "$1" bash -c 'bash $1' ''
}
test_program() {
- run_test "$builddir/$1" "$srcdir/$1.expected"
+ testcase="$1"
+ shift
+ run_test "$builddir/$testcase" "$srcdir/$testcase.expected" "$@"
+}
+test_program_subshell() {
+ test_program "$1" sh -c '$1' ''
}