#!/bin/csh -f
#
# SCTEST - test SCORE
#
#1
#2

set System = `../manager/system-id`
set BinDir = ../dev/$System/bin
set ERROR  = "FALSE"
set FAIL   = "NO"
set status = 0

source ../manager/env-$System

if (-e ../dev/$System/include/scstd.h) then

   touch test.error

   rm -f sctest.debug
   echo `../manager/pwhich pact` >& sctest.debug
   echo `../manager/pwhich cc` >>& sctest.debug
   echo "BinDir = $BinDir" >>& sctest.debug

   echo ""
   echo "SCORE TEST..."

   echo ""
   echo -n "                    Building SCORE Tests ....."

   pact compre >& test.error

   if ($status != 0) then
      echo ""
      cat test.error
      echo "                         Can't build SCORE Test Programs"
      set ERROR = "TRUE"

   else

      echo " DONE"
      echo ""
      echo -n "                    SCORE Test #1 ....."

      $BinDir/tscctl > tscctl.res
      if ($status == 0) then
         echo " PASSED"
      else
         echo ""
         echo "                    SCORE Test #1 ..... FAILED"
         set ERROR = "TRUE"
      endif

      echo ""
      echo -n "                    SCORE Test #2 ....."

      $BinDir/tscctla > tscctla.res
      if ($status == 0) then
         echo " PASSED"
      else
         echo ""
         echo "                    SCORE Test #2 ..... FAILED"
         set ERROR = "TRUE"
      endif

      echo ""
      echo -n "                    SCORE Test #3 ....."

      $BinDir/tscstr > tscstr.res
      if ($status == 0) then
         echo " PASSED"
      else
         echo ""
         echo "                    SCORE Test #3 ..... FAILED"
         set ERROR = "TRUE"
      endif

      rm ts*.res

      echo ""
      echo "                    SCORE HASH Test ....."

      pact ha >& test.error

      if ($status != 0) then
         echo "                         ERROR Building HASH Test Program"
         cat test.error
         echo "                    SCORE HASH Test ............. FAILED"
         set ERROR = "TRUE"
      else
         $BinDir/scatst
         if ($status == 0) then
            echo "                    SCORE HASH Test ............. PASSED"
         else
            echo "                    SCORE HASH Test ............. FAILED"
            set ERROR = "TRUE"
         endif
      endif

      echo ""
      echo -n "                    SCORE Lexical Scan Test ....."

      pact scan >& test.error
      if ($status != 0) then
         echo ""
         cat test.error
         echo "                         ERROR Building Lexical Scan Tests"
         echo "                    SCORE Lexical Scan Test ..... FAILED"
         set ERROR = "TRUE"
      else
         $BinDir/sclsts sclsts.src > sclsts.res
         diff sclsts.res sclsts.res.ref > sclsts.res.diff
         set Files = `find . -name "sclsts.res.diff" -size 0 -print`
         if ($#Files == 0) then
            echo ""
            echo "                    SCORE Lexical Scan Test ..... FAILED"
            set ERROR = "TRUE"
         else
            echo " PASSED"
         endif
         rm -f sclsts.res.diff
      endif

   endif

   rm test.error

   echo ""
   if ($ERROR == "TRUE") then
      echo ""
      echo "Debug:"
      cat sctest.debug
      echo ""
      echo "SCORE TEST...FAILED"
   else
      echo "SCORE TEST...PASSED"
   endif

   echo ""
   echo " --------------------------------------------------------"

endif

set xstatus = 0
if ($ERROR == "TRUE") then
   set xstatus = 1
endif

exit($xstatus)

