]> ruderich.org/simon Gitweb - coloredstderr/coloredstderr.git/blobdiff - tests/lib.sh
tests: Handle `sed` which append a trailing newline.
[coloredstderr/coloredstderr.git] / tests / lib.sh
index 897d50e754ca38a4fe5bc6658b0a1217e8217818..33a3721f751f9268a6f653940c72a5a733d016e7 100644 (file)
@@ -40,7 +40,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 +81,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 +99,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<>STDERR>//g' < "$output" > "$output.tmp"
+    mv "$output.tmp" "$output"
+
     diff -u "$expected" "$output" \
         || die 'failed!'
     rm "$output"
@@ -105,7 +117,9 @@ run_test() {
 test_script() {
     testcase="$1"
     expected="$2"
-    shift; shift || true
+    # shift || true is not enough for dash.
+    test $# -ge 2 && shift
+    shift
 
     if test -z "$expected"; then
         expected="$testcase"
@@ -113,12 +127,13 @@ 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"
     expected="$2"
-    shift; shift || true
+    test $# -ge 2 && shift
+    shift
 
     if test -z "$expected"; then
         expected="$testcase"