#! /bin/echo this_file_should_be_sourced,_not_executed
#  -*- Mode: Shell-script -*-
# ----------------------------------------------------------------------
# defs --- define the environment for autogen tests.
#
# Author:         Bruce Korb <bkorb@gnu.org>
# Maintainer:     Bruce Korb <bkorb@gnu.org>
# Created:        Fri Mar 27 21:15:30 1998
# Last Modified:  $Date: 2003/12/06 22:04:13 $
#            by: bkorb
# ----------------------------------------------------------------------
# $Id: defs,v 1.11 2003/12/06 22:04:13 bkorb Exp $
# ----------------------------------------------------------------------

# Make sure srcdir is an absolute path.  Supply the variable
# if it does not exist.  We want to be able to run the tests
# stand-alone!!
#
srcdir=${srcdir-.}
top_srcdir=${top_srcdir-`cd $srcdir/../.. ; pwd`}
top_builddir=${top_builddir-`cd ../.. ; pwd`}

if test ! -d "$srcdir"       \
     -o ! -d "$top_srcdir"   \
     -o ! -d "$top_builddir"
then
    echo "defs: installation error" 1>&2
    exit 1
fi

homedir=`pwd`

#  IF the source directory is a Unix or a DOS root directory, ...
#
case "$srcdir" in
    /* | [A-Za-z]:\\*) ;;
    *) srcdir=`\cd $srcdir && pwd` ;;
esac

progname=`echo "$0" | sed 's,^.*/,,'`
testname=`echo "$progname" | sed 's,\..*$,,'`
testsubdir=${testsubdir-testdir}

export progname testname testsubdir homedir

# User can set VERBOSE to prevent output redirection
case x$VERBOSE in
  xNO* | xno* | x0 | x)
    exec > /dev/null 2>&1
    rm -rf $testsubdir
    VERBOSE=false
    ;;

  x* )
    VERBOSE=true
    ;;
esac

test -d $testsubdir || mkdir $testsubdir
cd $testsubdir
testsubdir=`pwd`

if test $? != 0 ; then
  echo "Cannot make or change into $testsubdir"
  exit 1
fi

echo "=== Running $progname"
chmod +w * > /dev/null 2>&1 || :

# A standard failure function
failure()
{
  set -x
  test -d ${homedir}/FAILURES || mkdir ${homedir}/FAILURES
  cd ${testsubdir}
  l=`echo *`
  ( \cd ../FAILURES ; rm -rf $l )
  mv -f * ../FAILURES
  echo "$*"
  exit 1
}

cleanup()
{
  if $VERBOSE
  then : ; else
    cd ${homedir}
    rm -rf $testsubdir
  fi
  echo $testname done
}
# defs ends here
