#! /bin/sh

TESTID=sherpa-smoke001
export TESTID

INFILE=''
OUTFILE=''
OUTLIST='${OUTFILE}'
TOLFILE=''
#
# Synopsis: Sherpa Self Test
TESTCMD='python -c "import sherpa; \
         sherpa.smoke(xspec=True, ds9=True, fits=\"pycrates\")"'

# Setup CIAO environment
#   (replace with variable via configure)
#
ASCDS_QUIET=1; export ASCDS_QUIET
ASCDS_OVERRIDE=1; export ASCDS_OVERRIDE
. $ASCDS_INSTALL/test/smoke/bin/setup.sh
  
#
# Setup test env
#
TESTDIR=$ASCDS_INSTALL/test/smoke/data; export TESTDIR
OUTDIR=$ASCDS_WORK_PATH/smoke.${LOGNAME}/$TESTID; export OUTDIR
SAVEDIR=$TESTDIR; export SAVEDIR

INDIR=$TESTDIR

#
# --!!  check $ASCDS_WORK_PATH exist, writeable, has enough space
#
# Setup local parameter location
PFILES="$OUTDIR/param;$ASCDS_INSTALL/param"; export PFILES

if test -d $OUTDIR
then
  \rm -rf $OUTDIR
fi

mkdir -p $OUTDIR/param

#
# Run command
#
printf "Running test $TESTID"
printf " ."

fail=1
(eval "$TESTCMD")  > $OUTDIR/diff.log 2>&1
fail=$?
printf "."

#
# Exit condition
#
if test $fail -eq 0
then
  printf ". "
  echo "PASS"
  \rm -rf $OUTDIR
  xx=`\ls $ASCDS_WORK_PATH/smoke.${LOGNAME}`
  if test "x$xx" = "x"
  then
    rmdir $ASCDS_WORK_PATH/smoke.${LOGNAME}
  fi
else
  printf ". "
  echo "FAIL"
fi

exit $fail

