#! /usr/local/bin/tcsh -f

goto startScript

usage:
echo
echo  usage:  runTests.sh \[ids\*\]
echo  ""
echo  examples:                                                          
echo  runTests.sh
echo  runTests.sh ian clements greiner
echo  ""
echo  A script to run the indicated user\'s connect5 program
echo  on the test cases in Connect5/Tests/.
echo  If no users given, the default is all studnets listed in the file Connect5/roll
echo  ""
exit



#################
startScript:
################
if ($#argv >= 1) then
  if ("$argv[1]" == "help" || "$argv[1]" == "-help")    goto usage
  endif






set debug = 0

set mainDir  = /home/comp210/Web/01fall/Assignments/Connect5
if ($USER == comp210) then
  set testDir  = $mainDir/Tests-labbie
else
  set testDir  = $mainDir/Tests
  endif

# Possible improvement: Make test files end in "*.in" or so,
# to make it easier for students to have tests in their own dir?
set testFiles = $testDir/[a-z]*
set rollFile = $mainDir/roll
set roll     = `cat $rollFile`
# Directory of a student's program, relative to their home:
set studentPathToProg = "comp210/connect5"
# The name of a student's program:
set progName = "connect5.ss"

#set mzschemeStart =  "mzscheme -l macro.ss -l functioc.ss -q -m -r"
set mzschemeStart =  "mzscheme -l core.ss -q"

if ($#argv == 0) then
  set names = "$roll"
else
  set names = "$argv"
  endif

foreach s ($names)
  echo ""
  echo \*\*\* $s \*\*\*
  set sDir  = /home/$s/$studentPathToProg
  if (-r $s) then
    set sProg = $s
  else
    set sProg = $sDir/$progName
  endif
#  if (-x $sProg) then
#     if ($debug) echo "$progName found in $sDir"
#     set execute = $sProg
#  else
    if (-r $sProg) then
     if ($debug) echo "$progName found in $sDir"
     set execute = "$mzschemeStart -r $sProg"
    else
      echo "No $sProg or $s found."
      goto nextname
    endif
#  endif
  if ($debug) echo Execute line is $execute
  
  foreach tf ($testFiles)
    if ($tf:e == out) continue
    echo -n $tf:t
    set output = `$execute < $tf`
    set desiredOutput = `cat $tf.out`
    if ("$output" != "$desiredOutput") echo -n "  "\#Output $output, but correct answer is $desiredOutput.
    echo ""
    end

nextname:
  end
