#! /bin/bash
#
# (C) Copyright IBM Corp. 2001, 2003
#
# $Id: NightSanityDriver,v 1.7 2003/07/29 19:32:22 augart-oss Exp $
#
# @author Julian Dolby

# driver config file must be given
DRIVER=

# options given by the user
ADDED=

## -succeed-immediately flag.
succeed_immediately=

croak () {
    exec >&2
    echo "${0##*/}: $*";
    exit 1
}

while [ $# != 0 ]; do

    case $1 in
	-succeed-immediately  )
	    succeed_immediately="exit 0";
	    ;;
	    

	-common)
	    : ${2?"The -common flag requires an argument"}
	    ADDED="$2"
	    shift
	    ;;

	-config)
	    : ${2?"The -driver flag requires an argument"}
	    case "$2" in
		/*)
		    DRIVER="$2"
		    ;;
		
		*?)
		    DRIVER="$RVM_ROOT/rvm/regression/config/$2"
		    ;;
	    esac
	    shift
	    ;;

	*)  
	    croak "Invalid option \"$1\"
Valid options are
-common \"options\"         options to RunSanityTests
-config <file>            run tests given in file
-die-immediately	  exit successfully, once the arguments are verified
"
	    ;;
    esac
    shift
done


[[ -f $DRIVER ]] || croak "I cannot find a driver file named \"$DRIVER\""


# The config file specifies a configuration to test, and any extra
# arguments that RunSanityTests will need.

$succeed_immediately

awk "{ 
print \"echo 'About to launch RunSanityTests -configurations \" \$0 \" $ADDED'\" ;
print \"$RVM_ROOT/rvm/regression/RunSanityTests -configurations \" \$0 \" $ADDED || { \n\
     code=\$? ; \n\
     echo >&2 'Running the test \" \$0 \" died with error code \$code.' ; \n\
     echo >&2 'Test run as:   RunSanityTests -configurations \" \$0 \" $ADDED' ;  } \"
}" "${DRIVER}" | sh -s
