]> git.draconx.ca Git - liblbx.git/commitdiff
tests: Remove toplevel set -e usage.
authorNick Bowler <nbowler@draconx.ca>
Thu, 23 Jan 2014 01:06:27 +0000 (20:06 -0500)
committerNick Bowler <nbowler@draconx.ca>
Thu, 23 Jan 2014 03:12:17 +0000 (22:12 -0500)
Using set -e at the top level affects the entire script and makes it
difficult to work with commands that may legitimately return an error.
Regardless, set -e is still not so great for error checks because it
has some incredibly non-obvious semantics.

Better to just have correct error checks everywhere.  Fortunately, this
is the case for almost all the existing test code -- only the testdir
creation needs fixing.

tests/util/test-init.sh

index 52625c0d199f86f66f14957a42cb4ffdbfc68e3a..d59b8532177d210c749499384f046e466980f5d4 100644 (file)
@@ -1,6 +1,6 @@
 # 2ooM: The Master of Orion II Reverse Engineering Project
 # Common test suite initialization functions.
-# Copyright © 2013 Nick Bowler
+# Copyright © 2013-2014 Nick Bowler
 #
 # 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
@@ -25,8 +25,6 @@
 # You should have received a copy of the GNU General Public License
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
-set -e
-
 test ${test_lib_sourced-no} = yes && return 0
 test_lib_sourced=yes
 
@@ -86,11 +84,10 @@ testdata=$srcdir/tests/testdata
 dx_testname=`expr x"$argv0" : x'.*/\(.*\)\.'`
 dx_testdir=tests/$dx_testname.dir
 
-dx_cleanup_testdir()
-{
+dx_cleanup_testdir() {
        exitstatus=$1
 
-       cd "$builddir"
+       cd "$builddir" || return
        if test "$exitstatus" -eq 0 &&
           test $tap_pass_count_ -eq $tap_count_
        then
@@ -98,15 +95,17 @@ dx_cleanup_testdir()
        fi
 }
 
-dx_create_testdir()
-{
-       $MKDIR_P "$dx_testdir"
+dx_create_testdir_() {
+       $MKDIR_P "$dx_testdir" || return
        trap 'dx_cleanup_testdir $?' 0
        cd "$dx_testdir"
 }
 
-dx_pam_header()
-{
+dx_create_testdir() {
+       dx_create_testdir_ || bailout_ "failed to create test directory"
+}
+
+dx_pam_header() {
        awk 'BEGIN { ret=1 }
                NR==1 { if (!/^P7$/) exit 1 }
                /^P7$/,/^ENDHDR$/ { ret=0; if ($2) print $1"="$2 }