1 # 2ooM: The Master of Orion II Reverse Engineering Project
2 # Common test suite initialization functions.
3 # Copyright © 2013 Nick Bowler
5 # This program is free software: you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation, either version 3 of the License, or
8 # (at your option) any later version.
10 # This file incorporates work covered by the following copyright and
13 # Copyright (C) 1996-2013 Free Software Foundation, Inc.
15 # This program is free software; you can redistribute it and/or modify
16 # it under the terms of the GNU General Public License as published by
17 # the Free Software Foundation; either version 2, or (at your option)
20 # This program is distributed in the hope that it will be useful,
21 # but WITHOUT ANY WARRANTY; without even the implied warranty of
22 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 # GNU General Public License for more details.
25 # You should have received a copy of the GNU General Public License
26 # along with this program. If not, see <http://www.gnu.org/licenses/>.
30 test ${test_lib_sourced-no} = yes && return 0
33 # CDPATH is evil if used in non-interactive scripts (and even more
34 # evil if exported in the environment).
37 # Be more Bourne compatible.
38 # (Snippet inspired to configure's initialization in Autoconf 2.64)
39 DUALCASE=1; export DUALCASE # for MKS sh
40 if test -n "${ZSH_VERSION+set}" && (emulate sh) >/dev/null 2>&1; then
44 # If Zsh is not started directly in POSIX-compatibility mode, it has
45 # some incompatibilities in the handling of $0 that conflict with our
46 # usage; i.e., $0 inside a file sourced with the '.' builtin is
47 # temporarily set to the name of the sourced file. Work around that.
48 # Note that a bug in some versions of Zsh prevents us from resetting $0
49 # in a sourced script, so the use of $argv0. For more info see:
50 # <http://www.zsh.org/mla/workers/2009/msg01140.html>
51 # The apparently useless 'eval' here is needed by at least dash 0.5.2,
52 # to prevent it from bailing out with an error like:
53 # "Syntax error: Bad substitution".
54 eval 'argv0=${functrace[-1]%:*}' && test -f "$argv0" || {
55 echo "Cannot determine the path of running test script." >&2
56 echo "Your Zsh (version $ZSH_VERSION) is probably too old." >&2
61 # Ignore command substitution failure, for it might cause problems
62 # with "set -e" on some shells.
63 am_shell_opts=$(set -o) || :
64 case $am_shell_opts in *posix*) set -o posix;; esac
68 # A single whitespace character.
70 # A tabulation character.
72 # A newline character.
76 # As autoconf-generated configure scripts do, ensure that IFS
77 # is defined initially, so that saving and restoring $IFS works.
80 . "$srcdir/tests/util/tap-functions.sh"
81 . "$srcdir/tests/util/test-defs.sh"
83 testdata=$srcdir/tests/testdata
85 # We need a scratch directory for most tests, so set that up now.
86 dx_testname=`expr x"$argv0" : x'.*/\(.*\)\.'`
87 dx_testdir=tests/$dx_testname.dir
94 if test "$exitstatus" -eq 0 &&
95 test $tap_pass_count_ -eq $tap_count_
103 $MKDIR_P "$dx_testdir"
104 trap 'dx_cleanup_testdir $?' 0
111 NR==1 { if (!/^P7$/) exit 1 }
112 /^P7$/,/^ENDHDR$/ { ret=0; if ($2) print $1"="$2 }
113 /^ENDHDR$/ { print $1"="NR+1; exit }
114 END { exit ret }' ${1+"$@"}
117 dx_check_pam_md5_() {
118 dx_pam_header "$1" > "$1.sh" || return
119 . "./$1.sh" || return
121 tail -n +"$ENDHDR" "$1" > "$1.px" || return
122 echo "$2 $1.px" > "$1.md5" || return
127 if $HAVE_MD5SUM; then
128 command_ok_ "$1" dx_check_pam_md5_ "$1" "$2"
134 # Variables to run the LBX tools. Default to the build tree, but can also be
135 # set explicitly to test installed tools.
136 : "${LBXTOOL=$builddir/lbxtool$EXEEXT}"
137 : "${LBXIMG=$builddir/lbximg$EXEEXT}"
139 # Set MALLOC_CHECK_ in the environment of the test programs which will enable
140 # malloc instrumentation on glibc-based systems to hopefully catch some forms
141 # of memory corruption.
142 dx_test_wrapper="$builddir/libtool --mode=execute env MALLOC_CHECK_=3"
143 LBXTOOL="$dx_test_wrapper $LBXTOOL"
144 LBXIMG="$dx_test_wrapper $LBXIMG"