]> git.pond.sub.org Git - empserver/commitdiff
tests/files tests/fairland: Check stderr and exit status
authorMarkus Armbruster <armbru@pond.sub.org>
Wed, 29 Jan 2014 19:12:18 +0000 (20:12 +0100)
committerMarkus Armbruster <armbru@pond.sub.org>
Sun, 1 Feb 2015 15:52:59 +0000 (16:52 +0100)
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 <armbru@pond.sub.org>
tests/fairland-test
tests/fairland/fairland.out
tests/files-test
tests/test-common.sh

index e3427168349b12ac8af052e9c59cfbd9808fee7b..58102ac7b36f1c7e191c097e1fe306e269acddbf 100755 (executable)
@@ -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
index d6455d5d5565f76007befd3f585e1ab05d7cfaef..a0d7a9fe3bb9efa8b63bee88b3d244c0c458453c 100644 (file)
@@ -1,4 +1,3 @@
-All praise to POGO!
 Creating a planet with:
 
 10 continents
index 3343ed7ed7aae7fc1fe1a49a77def5822e8397fe..3c8840d27706ebad5b13c832fb8aa305a500822d 100755 (executable)
@@ -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
index a61397523b23a308231980be0730c5f68beeb68b..7681cac03b117e2e6c14799fdbf2f67d79209112 100644 (file)
@@ -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"