-# 2ooM: The Master of Orion II Reverse Engineering Project
-# Common test suite initialization functions.
-# 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
-# the Free Software Foundation, either version 3 of the License, or
-# (at your option) any later version.
-#
-# This file incorporates work covered by the following copyright and
-# permission notice:
-#
-# Copyright (C) 1996-2013 Free Software Foundation, Inc.
-#
-# 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
-# the Free Software Foundation; either version 2, or (at your option)
-# any later version.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program. If not, see <http://www.gnu.org/licenses/>.
-
-test ${test_lib_sourced-no} = yes && return 0
-test_lib_sourced=yes
-
-# CDPATH is evil if used in non-interactive scripts (and even more
-# evil if exported in the environment).
-CDPATH=; unset CDPATH
-
-# Be more Bourne compatible.
-# (Snippet inspired to configure's initialization in Autoconf 2.64)
-DUALCASE=1; export DUALCASE # for MKS sh
-if test -n "${ZSH_VERSION+set}" && (emulate sh) >/dev/null 2>&1; then
- emulate sh
- NULLCMD=:
- setopt NO_GLOB_SUBST
- # If Zsh is not started directly in POSIX-compatibility mode, it has
- # some incompatibilities in the handling of $0 that conflict with our
- # usage; i.e., $0 inside a file sourced with the '.' builtin is
- # temporarily set to the name of the sourced file. Work around that.
- # Note that a bug in some versions of Zsh prevents us from resetting $0
- # in a sourced script, so the use of $argv0. For more info see:
- # <http://www.zsh.org/mla/workers/2009/msg01140.html>
- # The apparently useless 'eval' here is needed by at least dash 0.5.2,
- # to prevent it from bailing out with an error like:
- # "Syntax error: Bad substitution".
- eval 'argv0=${functrace[-1]%:*}' && test -f "$argv0" || {
- echo "Cannot determine the path of running test script." >&2
- echo "Your Zsh (version $ZSH_VERSION) is probably too old." >&2
- exit 99
- }
-else
- argv0=$0
- # Ignore command substitution failure, for it might cause problems
- # with "set -e" on some shells.
- am_shell_opts=$(set -o) || :
- case $am_shell_opts in *posix*) set -o posix;; esac
- unset am_shell_opts
-fi
-
-# A single whitespace character.
-sp=' '
-# A tabulation character.
-tab=' '
-# A newline character.
-nl='
-'
-
-# As autoconf-generated configure scripts do, ensure that IFS
-# is defined initially, so that saving and restoring $IFS works.
-IFS=$sp$tab$nl
-
-. "$srcdir/tests/util/tap-functions.sh"
-. "$srcdir/tests/util/test-defs.sh"
-
-testdata=$srcdir/tests/testdata
-
-# We need a scratch directory for most tests, so set that up now.
-dx_testname=`expr x"$argv0" : x'.*/\(.*\)\.'`
-dx_testdir=tests/$dx_testname.dir
-
-dx_cleanup_testdir() {
- exitstatus=$1
-
- cd "$builddir" || return
- if test "$exitstatus" -eq 0 &&
- test $tap_pass_count_ -eq $tap_count_
- then
- rm -rf "$dx_testdir"
- fi
-}
-
-dx_create_testdir_() {
- $MKDIR_P "$dx_testdir" || return
- trap 'dx_cleanup_testdir $?' 0
- cd "$dx_testdir"
-}
-
-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 }
- /^ENDHDR$/ { print $1"="NR+1; exit }
- END { exit ret }' ${1+"$@"}
-}
-
-dx_check_pam_md5_() {
- dx_pam_header "$1" > "$1.sh" || return
- . "./$1.sh" || return
-
- tail -n +"$ENDHDR" "$1" > "$1.px" || return
- echo "$2 $1.px" > "$1.md5" || return
- $MD5SUM -c "$1.md5"
-}
-
-dx_check_pam_md5() {
- if $HAVE_MD5SUM; then
- command_ok_ "$1" dx_check_pam_md5_ "$1" "$2"
- else
- skip_ "$1"
- fi
-}
-
-# Variables to run the LBX tools. Default to the build tree, but can also be
-# set explicitly to test installed tools.
-: "${LBXTOOL=$builddir/lbxtool$EXEEXT}"
-: "${LBXIMG=$builddir/lbximg$EXEEXT}"
-
-# Set MALLOC_CHECK_ in the environment of the test programs which will enable
-# malloc instrumentation on glibc-based systems to hopefully catch some forms
-# of memory corruption.
-dx_test_wrapper="$builddir/libtool --mode=execute env MALLOC_CHECK_=3"
-LBXTOOL="$dx_test_wrapper $LBXTOOL"
-LBXIMG="$dx_test_wrapper $LBXIMG"