#!/bin/tcsh 

#unset D_USE_FREELISTS for best valgrind results
#setenv VALGRIND 'valgrind -q '
setenv VALGRIND ' '

cp D_BUILD_VERSION Makefile *.c *.h grammar.g tests
cd tests
$MAKE -s make_dparser
$MAKE gram
$MAKE -s make_dparser
set failed = 0
foreach g (*.test.g)
  rm -f sample_parser
  if (-e $g.flags) then
    set flags = `cat $g.flags`
  else
    set flags = 
  endif
  $VALGRIND ./make_dparser $flags $g
  $MAKE -s sample_parser SAMPLE_GRAMMAR=$g:t
  foreach t ( $g.[0-9] $g.[0-9][0-9] )
    if (-e $t.flags) then
      set flags = `cat $t.flags`
    else
      set flags = 
    endif
    $VALGRIND ./sample_parser $flags -v $t >&! $t.out
    diff $t.out $t.check
    if ($?) then
      echo $t "******** FAILED ********"
      set failed = `expr $failed + 1`
    else
      echo $t "PASSED"
    endif
  end
end
echo "---------------------------------------"
if (! $failed) then
  echo "ALL tests PASSED"
else
  echo "********" $failed "test(s) FAILED *********"
endif
rm -f sample_parser D_BUILD_VERSION Makefile *.c *.h *.o make_dparser libdparse.a grammar.g
cd ..
