X-Git-Url: https://ruderich.org/simon/gitweb/?a=blobdiff_plain;f=tests%2Flib.sh;fp=tests%2Flib.sh;h=94807699c8f305c2bd207031986257beeffa7c5d;hb=fb9548453fbc0dedc8f145e8468fc601de784c32;hp=0000000000000000000000000000000000000000;hpb=96710bc3fa919e221338ef96686e80ba590d3b77;p=coloredstderr%2Fcoloredstderr.git
diff --git a/tests/lib.sh b/tests/lib.sh
new file mode 100644
index 0000000..9480769
--- /dev/null
+++ b/tests/lib.sh
@@ -0,0 +1,91 @@
+# Library for the test suite.
+
+# Copyright (C) 2013 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
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see .
+
+
+# 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
+# Clean locale for reproducible tests.
+LC_ALL=C
+unset LANGUAGE
+
+
+die() {
+ echo "$@" >&2
+ exit 1
+}
+
+get_library_path() {
+ # Get name of the real library file from libtool's .la file.
+ dlname=`$EGREP "^dlname='" "$builddir/../src/libcoloredstderr.la"` \
+ || die 'dlname not found'
+ dlname=`echo "$dlname" | sed "s/^dlname='//; s/'$//"`
+
+ library="$builddir/../src/.libs/$dlname"
+ test -e "$library" || die "'$library' not found"
+
+ echo "`pwd`/$library"
+}
+
+library=`get_library_path`
+force_write=1
+
+
+run_test() {
+ printf '%s' "Running test '$*' .. "
+
+ testcase="$1"
+ expected="$2"
+ shift
+ shift
+
+ (
+ # Standard setup.
+ LD_PRELOAD="$library"
+ COLORED_STDERR_FDS=2,
+ export LD_PRELOAD
+ export COLORED_STDERR_FDS
+
+ # Change pre/post strings for simpler testing.
+ COLORED_STDERR_PRE='>stderr>'
+ COLORED_STDERR_POST=' output 2>&1
+ )
+
+ diff -u "$expected" output \
+ || die 'failed!'
+ rm output
+ echo 'passed.'
+}
+
+test_script() {
+ run_test "$srcdir/$1" "$srcdir/$1.expected"
+}
+test_program() {
+ run_test "$builddir/$1" "$srcdir/$1.expected"
+}