]> git.pond.sub.org Git - empserver/commitdiff
tests: Simplify running cmp_out more than once
authorMarkus Armbruster <armbru@pond.sub.org>
Wed, 29 Jan 2014 18:56:38 +0000 (19:56 +0100)
committerMarkus Armbruster <armbru@pond.sub.org>
Sun, 1 Feb 2015 15:52:59 +0000 (16:52 +0100)
When cmp_out detects a test failure, it returns non-zero status, which
terminates the test script unless caught.

Accumulate failures in a global variable checked at exit instead, so
running it multiple times in a test script just works.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
tests/test-common.sh

index 5fc117c128ac0a4a140f75267e2d708add8361c0..bb37b7730d9992ab41230f804d94cda05e137a5d 100644 (file)
@@ -8,6 +8,9 @@ fi
 test=${0##*/}
 test=${test%-test}
 
+failed=
+trap 'if [ "$pid" ]; then kill -9 "$pid" 2>/dev/null || true; fi; [ "$failed" ] && exit 1' EXIT
+
 # Abbreviations
 testdir="$srcdir/tests/$test"
 econfig=sandbox/etc/empire/econfig
@@ -72,7 +75,6 @@ start_server()
     check_empthread
 
     pid=
-    trap 'if [ "$pid" ]; then kill -9 "$pid" 2>/dev/null || true; fi' EXIT
     src/server/emp_server -e $econfig -R 1 -s -E crash-dump
     timeout=$((`now`+5))
     until pid=`cat $pidfile 2>/dev/null` && [ -n "$pid" ]
@@ -177,7 +179,7 @@ cmp_logs_xdump()
 
 cmp_out()
 {
-    local exp act nrm ret=0
+    local exp act nrm
     for i
     do
        exp="$testdir/${i##*/}"
@@ -201,9 +203,8 @@ cmp_out()
            echo "$i CHANGED"
            cp "$nrm" "$exp"
        else
-           ret=$?
+           failed=y
            echo "$i FAIL"
        fi
     done
-    return $ret
 }