#! /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: 2000/09/16 16:22:58 $
#            by:  Bruce Korb <bkorb@gnu.org>
# ----------------------------------------------------------------------
# $Id: defs,v 1.6 2000/09/16 16:22:58 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-.}
if test ! -d $srcdir
then
    echo "defs: installation error" 1>&2
    exit 1
fi

if test -z "$top_srcdir"
then
   top_srcdir=`cd $srcdir/../.. ; pwd`
fi

if test -z "$top_builddir"
then
   top_builddir=`cd ../.. ; pwd`
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

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

#  All the tests will require the templates in the autoopts dir.
#
AGEN="$AGEN -L `cd ${srcdir}/..;pwd`"

#  In general, they will have a test main procedure, too.
#
test_main=yes

# 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
use_flags=true

test -d $testsubdir || mkdir $testsubdir
cd $testsubdir || {
  echo "Cannot make or change into $testsubdir"
  exit 1
}

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

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

cleanup()
{
  if ! $VERBOSE
  then
    cd ${homedir}
    rm -rf $testsubdir
  fi
}

compile()
{
  d=`echo TEST_TEST_${testname}_OPTS | tr a-z A-Z`
  ${CC} -g -D$d ${INC} -o $testname $testname.c ${LIB} || \
    failure cannot compile $testname.c
  ./$testname $@ > $testname.help 2>&1 || \
    failure cannot obtain help output for $testname
}

# defs ends here
