X-Git-Url: https://ruderich.org/simon/gitweb/?a=blobdiff_plain;f=tests%2Flib.sh;h=90a7db3996ec986c1b9a6cc6a4bbed0b438746db;hb=3676d3f21f0e1e2e59cd2fcafc64acccd3782ef9;hp=3427b5608fc36cdf7dca0824fbca4b4f97979f73;hpb=d5b84811d2f4bded83211984c839a096872608af;p=coloredstderr%2Fcoloredstderr.git diff --git a/tests/lib.sh b/tests/lib.sh index 3427b56..90a7db3 100644 --- a/tests/lib.sh +++ b/tests/lib.sh @@ -1,6 +1,6 @@ # Library for the test suite. -# Copyright (C) 2013 Simon Ruderich +# Copyright (C) 2013-2014 Simon Ruderich # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -20,6 +20,7 @@ set -e # 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 @@ -40,7 +41,10 @@ fi LC_ALL=C unset LANGUAGE -# Set default COLORED_STDERR_FDS value. +# Clear user defined variables. +unset COLORED_STDERR_FDS +unset COLORED_STDERR_FORCE_WRITE +# Set default COLORED_STDERR_PRIVATE_FDS value. fds=2, @@ -78,9 +82,9 @@ run_test() { ( # Standard setup. LD_PRELOAD="$library" - COLORED_STDERR_FDS="$fds" + 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>' @@ -96,6 +100,15 @@ run_test() { $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>//g' < "$output" > "$output.tmp" + mv "$output.tmp" "$output" + diff -u "$expected" "$output" \ || die 'failed!' rm "$output" @@ -115,7 +128,7 @@ test_script() { run_test "$srcdir/$testcase" "$srcdir/$expected.expected" "$@" } test_script_subshell() { - test_script "$1" "$2" bash -c 'bash $1' '' + test_script "$1" "$2" sh -c 'sh $1' '' } test_program() { testcase="$1"