From fed6620a0b6c684741535a223d227e861bde2794 Mon Sep 17 00:00:00 2001 From: Markus Armbruster Date: Wed, 29 Jan 2014 20:12:18 +0100 Subject: [PATCH] tests/files tests/fairland: Check stderr and exit status New helper run_and_cmp to automate the job: run a program capturing its standard output, standard error and exit status, then compare the actual with the expected results. Signed-off-by: Markus Armbruster --- tests/fairland-test | 11 +++------- tests/fairland/fairland.out | 1 - tests/files-test | 9 ++------- tests/test-common.sh | 40 +++++++++++++++++++++++++++++++++++++ 4 files changed, 45 insertions(+), 16 deletions(-) diff --git a/tests/fairland-test b/tests/fairland-test index e3427168..58102ac7 100755 --- a/tests/fairland-test +++ b/tests/fairland-test @@ -11,13 +11,8 @@ srcdir="$1" create_sandbox -exec 3>sandbox/fairland.out - -$files -f >&3 -$fairland -s sandbox/newcap_script -R 1 10 30 >&3 - -exec 3>&- +$files -f >/dev/null +run_and_cmp fairland $fairland -s sandbox/newcap_script -R 1 10 30 $empdump -x >sandbox/final.xdump - -cmp_out fairland.out final.xdump newcap_script +cmp_out final.xdump newcap_script diff --git a/tests/fairland/fairland.out b/tests/fairland/fairland.out index d6455d5d..a0d7a9fe 100644 --- a/tests/fairland/fairland.out +++ b/tests/fairland/fairland.out @@ -1,4 +1,3 @@ -All praise to POGO! Creating a planet with: 10 continents diff --git a/tests/files-test b/tests/files-test index 3343ed7e..3c8840d2 100755 --- a/tests/files-test +++ b/tests/files-test @@ -11,12 +11,7 @@ srcdir="$1" create_sandbox -exec 3>sandbox/files.out - -$files -f >&3 - -exec 3>&- +run_and_cmp files $files -f $empdump -x >sandbox/final.xdump - -cmp_out files.out final.xdump +cmp_out final.xdump diff --git a/tests/test-common.sh b/tests/test-common.sh index a6139752..7681cac0 100644 --- a/tests/test-common.sh +++ b/tests/test-common.sh @@ -49,6 +49,23 @@ EOF cp `git ls-files "$srcdir"/src/lib/global | uniq | grep '\.config$'` sandbox/share/empire/builtin } +run_and_cmp() +{ + run "$@" + cmp_run "$1" +} + +run() +{ + local name=$1 ret + shift + set +e + "$@" >>sandbox/$name.out 2>>sandbox/$name.err + ret=$? + set -e + echo $ret >>sandbox/$name.status +} + now() { # date +%s isn't portable... @@ -174,6 +191,18 @@ end_test () $empdump -x >sandbox/final.xdump } +cmp_run() +{ + local i j exp + + for i + do + for j in status out err + do cmp_out "$i.$j" + done + done +} + cmp_logs_xdump() { cmp_out var/empire/server.log var/empire/journal.log final.xdump @@ -188,6 +217,15 @@ cmp_out() exp="$testdir/${i##*/}" act="sandbox/$i" nrm="sandbox/normalized-${i##*/}" + + if [ ! -e "$exp" ] + then + case "$i" in + *.status) exp=sandbox/ok.status; echo 0 >sandbox/ok.status ;; + *) exp=/dev/null ;; + esac + fi + case "$i" in */journal.log) perl "$srcdir"/tests/normalize.pl -j "$act" ;; @@ -195,6 +233,8 @@ cmp_out() perl "$srcdir"/tests/normalize.pl -s "$act" ;; *.xdump) perl "$srcdir"/tests/normalize.pl "$act" ;; + *.err) + perl -pe 's/\s+$/\n/;' -e "s,\Q$srcdir/tests\E,tests," "$act" ;; *) perl -pe 's/\s+$/\n/;' "$act" ;; esac >"$nrm"