#!/bin/bash
#
# Test suite for Logiweb
#
# To execute: cd to the directory containing this file, then write ./test
#
# The test suite creates a temporary directory named 
# /tmp/logiweb.test.XXXXXXXXXX (with the X's replaced by random characters)
#
# After successful completion, the temporary directory is deleted.
# In case of errors, the temporary directory must be deleted manually
#
# When developing new tests it may be useful to work in a specific rather
# than a random directory. To do so, create a directory named
# /tmp/logiweb.test. Then the test suite uses that directory and does
# not delete it on successful completion.
#
# The test is divided in a number of classes:
#
# msg: test of output to stdout (including fatal error messages)
# fail: test runs which test that lgc catches various kinds of errors
# testsuite: test that lgc evaluates expressions correctly
# source: test of preprocessing and alphabets beyond ascii
# proof: test of various proof constructs
#
# Many error messages occur during execution of the test suite.
# That is normal since, among other, it is the ability of lgc to catch
# errors which is tested.
#
# The test suite is successful if it ends writing
# "Testsuite succeeded"
#
DIV=--------------------------------------------------------------
echo
echo Test of Logiweb
echo
echo $DIV
DIR=/tmp/logiweb.test
if [ -d $DIR ]
then
  echo "$DIR exists. Using that directory."
  rm -r -f $DIR/*
else
  DIR=`mktemp -d /tmp/logiweb.test.XXXXXXXXXX` || exit 1
  echo Temporary directory: $DIR
fi
WWW="$DIR/www"
LGC="$DIR/LGC -m 100M"
DIAG=undated/diagnose/diag.lgs
SRC=undated/vector/page.lgs
LGW_PATH=$DIR/cache/:/page.lgr
ARGS=roots=+file:$DIR/www/+$DIR/www/
ARGS="$ARGS url=file:$DIR/www/"
ARGS="$ARGS cache=$DIR/cache"
ARGS="$ARGS udphost="`lgc optionstr=udphost`
ARGS="$ARGS udpport="`lgc optionstr=udpport`
ARGS="$ARGS httphost="`lgc optionstr=httphost`
ARGS="$ARGS localrelay="`lgc optionstr=localrelay`
ARGS="$ARGS localhome="`lgc optionstr=localhome`
ARGS="$ARGS varhome="`lgc optionstr=varhome`
ARGS="$ARGS conf=/dev/null"
ARGS="$ARGS dest=\$LGS\$/undated"
ARGS="$ARGS link="

mkdir -p $DIR/stdout

# Wrap the following around things to be skipped
if (( 0 ))
then
echo This is skipped
fi

echo $DIV
TST=base
echo $TST
lgc -m 100M lgs=../lgc/$TST level=submit machine=$DIR/eecho bin=$DIR/bin $ARGS | tee $DIR/stdout/$TST
echo Checking          $WWW/$TST/$DIAG
diff -q /dev/null      $WWW/$TST/$DIAG || exit 1
grep 'Frontend: reading "../lgc/base.lgs"' \
                       $DIR/stdout/$TST || exit 1
grep 'Frontend: parsing associativity sections' \
                       $DIR/stdout/$TST || exit 1
grep 'Frontend: parsing body' \
                       $DIR/stdout/$TST || exit 1
grep 'Frontend: invoking priority rules' \
                       $DIR/stdout/$TST || exit 1
grep 'Frontend: vectorizing' \
                       $DIR/stdout/$TST || exit 1
grep 'ITERATION ENDED' \
                       $DIR/stdout/$TST || exit 1
grep 'Load: verifying page' \
                       $DIR/stdout/$TST || exit 1
grep "Claim of page 'base' succeeded" \
                       $DIR/stdout/$TST || exit 1
grep 'Load: dumping to cache' \
                       $DIR/stdout/$TST || exit 1
grep 'Load: dump ended' \
                       $DIR/stdout/$TST || exit 1
grep 'Rendering page at file:'$DIR'/www/base/undated/' \
                       $DIR/stdout/$TST || exit 1
grep 'Backend: writing diagnose' \
                       $DIR/stdout/$TST || exit 1
grep 'Backend: writing vector' \
                       $DIR/stdout/$TST || exit 1
grep 'Backend: finishing' \
                       $DIR/stdout/$TST || exit 1
grep 'Dumping executables' \
                       $DIR/stdout/$TST || exit 1
grep 'Claim succeeded' \
                       $DIR/stdout/$TST || exit 1

echo $DIV
echo "Hello World"
$DIR/bin/hello > $DIR/stdout/hello1
echo "Hello World" > $DIR/stdout/hello2
diff -q $DIR/stdout/hello1 $DIR/stdout/hello2 || exit 1

echo $DIV
echo "echo"
echo "abcq" | $DIR/bin/echo > $DIR/stdout/echo1
echo "abc" > $DIR/stdout/echo2
diff -q $DIR/stdout/echo1 $DIR/stdout/echo2 || exit 1

echo $DIV
echo "eecho"
echo "abcq" | $DIR/bin/eecho > $DIR/stdout/eecho1
echo "aabbcc" > $DIR/stdout/eecho2
diff -q $DIR/stdout/eecho1 $DIR/stdout/eecho2 || exit 1

echo $DIV
TST=check
echo $TST
lgc -m 100M lgs=../lgc/$TST level=submit $ARGS
echo Checking          $WWW/$TST/$DIAG
diff -q /dev/null      $WWW/$TST/$DIAG || exit 1

echo $DIV
echo dump
lgc -m 100M lgs=fail/fail01 dump=$DIR/LGC $ARGS

echo $DIV
TST=msg01
echo $TST
(cd msg ; $LGC lgs=$TST level=diagnose $ARGS | tee $DIR/stdout/$TST )
echo Checking          $DIR/stdout/$TST
fgrep 'Frontend: reading "msg01.lgs"' \
                       $DIR/stdout/$TST || exit 1
fgrep 'Frontend: reading "msg01-1.lgs"' \
                       $DIR/stdout/$TST || exit 1

echo $DIV
TST=msg02
echo $TST
(cd msg ; $LGC lgs=$TST level=diagnose $ARGS | tee $DIR/stdout/$TST )
echo Checking          $DIR/stdout/$TST
fgrep 'Frontend: parsing body' \
                       $DIR/stdout/$TST || exit 1
fgrep '\begin{statements}' \
                       $DIR/stdout/$TST || exit 1
fgrep '\item "[[ value define ab|' \
                       $DIR/stdout/$TST || exit 1
fgrep 'd as true end define ]]"' \
                       $DIR/stdout/$TST || exit 1
fgrep '\item "[[ ftst abc end test ]]"' \
                       $DIR/stdout/$TST || exit 1
fgrep 'File msg02.lgs around line 96 char 26:' \
                       $DIR/stdout/$TST || exit 1
fgrep 'No interpretations' \
                       $DIR/stdout/$TST || exit 1
fgrep 'Goodbye' \
                       $DIR/stdout/$TST || exit 1

echo $DIV
TST=msg03
echo $TST
(cd msg ; $LGC lgs=$TST level=diagnose $ARGS | tee $DIR/stdout/$TST )
echo Checking          $DIR/stdout/$TST
fgrep 'Frontend: parsing body' \
                       $DIR/stdout/$TST || exit 1
fgrep '\begin{statements}' \
                       $DIR/stdout/$TST || exit 1
fgrep '\item "[[ value define a|' \
                       $DIR/stdout/$TST || exit 1
fgrep 'dc as true end define ]]"' \
                       $DIR/stdout/$TST || exit 1
fgrep '\item "[[ ftst abc end test ]]"' \
                       $DIR/stdout/$TST || exit 1
fgrep 'File msg03.lgs around line 97 char 25:' \
                       $DIR/stdout/$TST || exit 1
fgrep 'No interpretations' \
                       $DIR/stdout/$TST || exit 1
fgrep 'Goodbye' \
                       $DIR/stdout/$TST || exit 1

echo $DIV
TST=msg04
echo $TST
(cd msg ; $LGC lgs=$TST level=diagnose $ARGS | tee $DIR/stdout/$TST )
echo Checking          $DIR/stdout/$TST
fgrep '"" abc' \
                       $DIR/stdout/$TST || exit 1
fgrep 'PREASCOCIATIVE' \
                       $DIR/stdout/$TST || exit 1
fgrep '"base" " factorial' \
                       $DIR/stdout/$TST || exit 1
fgrep '"check" " plist ( " )' \
                       $DIR/stdout/$TST || exit 1
fgrep 'File msg04-1.lgs around line 3 char 1:' \
                       $DIR/stdout/$TST || exit 1
fgrep 'Page name (string) expected' \
                       $DIR/stdout/$TST || exit 1
fgrep 'Goodbye' \
                       $DIR/stdout/$TST || exit 1

echo $DIV
TST=unpacker
echo $TST
(cd msg ; $LGC lgs=$TST level=submit verbose=1 $ARGS | tee $DIR/stdout/$TST )
echo Checking          $DIR/stdout/$TST
fgrep "Load: Default unpacking" \
                       $DIR/stdout/$TST || exit 1
fgrep "Backend: Default rendering" \
                       $DIR/stdout/$TST || exit 1
fgrep "Claim of page 'unpacker' succeeded." \
                       $DIR/stdout/$TST || exit 1
fgrep "Backend: finishing" \
                       $DIR/stdout/$TST || exit 1

echo $DIV
TST=unpacked
echo $TST
(cd msg ; $LGC lgs=$TST level=diagnose verbose=1 $ARGS | tee $DIR/stdout/$TST )
echo Checking          $DIR/stdout/$TST
fgrep "Load: Custom unpacking" \
                       $DIR/stdout/$TST || exit 1
fgrep "Backend: Default rendering" \
                       $DIR/stdout/$TST || exit 1
fgrep "Claim of page 'unpacked' succeeded." \
                       $DIR/stdout/$TST || exit 1

echo $DIV
TST=renderer
echo $TST
(cd msg ; $LGC lgs=$TST level=submit verbose=1 $ARGS | tee $DIR/stdout/$TST )
echo Checking          $DIR/stdout/$TST
fgrep "Load: Default unpacking" \
                       $DIR/stdout/$TST || exit 1
fgrep "Backend: Custom rendering" \
                       $DIR/stdout/$TST || exit 1
fgrep "Claim of page 'renderer' succeeded." \
                       $DIR/stdout/$TST || exit 1
fgrep "Backend: finishing" \
                       $DIR/stdout/$TST || exit 1

echo $DIV
TST=rendered
echo $TST
(cd msg ; $LGC lgs=$TST level=diagnose verbose=1 $ARGS | tee $DIR/stdout/$TST )
echo Checking          $DIR/stdout/$TST
fgrep "Load: Default unpacking" \
                       $DIR/stdout/$TST || exit 1
fgrep "Backend: Custom rendering" \
                       $DIR/stdout/$TST || exit 1
fgrep "Claim of page 'rendered' succeeded." \
                       $DIR/stdout/$TST || exit 1

echo $DIV
TST=fail01
echo $TST
$LGC lgs=fail/$TST level=diagnose $ARGS
echo Checking          $WWW/$TST/$DIAG
diff -q -              $WWW/$TST/$DIAG <<diag || exit 1
math ttst false end test end math
diag

echo $DIV
TST=fail02
echo $TST
$LGC lgs=fail/$TST level=diagnose $ARGS
echo Checking          $WWW/$TST/$DIAG
diff -q -              $WWW/$TST/$DIAG <<diag || exit 1
math ttst exception end test end math
diag

echo $DIV
TST=fail03
echo $TST
$LGC lgs=fail/$TST level=diagnose $ARGS
echo Checking          $WWW/$TST/$DIAG
diff -q -              $WWW/$TST/$DIAG <<diag || exit 1
math ftst true end test end math
diag

echo $DIV
TST=fail04
echo $TST
$LGC lgs=fail/$TST level=diagnose $ARGS
echo Checking          $WWW/$TST/$DIAG
diff -q -              $WWW/$TST/$DIAG <<diag || exit 1
math ftst exception end test end math
diag

echo $DIV
TST=fail05
echo $TST
$LGC lgs=fail/$TST level=diagnose $ARGS
echo Checking          $WWW/$TST/$DIAG
diff -q -              $WWW/$TST/$DIAG <<diag || exit 1
math etst exception ; true end test end math
diag

echo $DIV
TST=fail06
echo $TST
$LGC lgs=fail/$TST level=diagnose $ARGS
echo Checking          $WWW/$TST/$DIAG
diff -q -              $WWW/$TST/$DIAG <<diag || exit 1
math etst exception ; false end test end math
diag

echo $DIV
TST=fail07
echo $TST
$LGC lgs=fail/$TST level=diagnose $ARGS
echo Checking          $WWW/$TST/$DIAG
diff -q -              $WWW/$TST/$DIAG <<diag || exit 1
math etst exception ; 2 raise end test end math
diag

echo $DIV
TST=latin1
echo $TST
$LGC lgs=source/$TST level=submit $ARGS filter=,latin1,newline,10
echo Checking          $WWW/$TST/$DIAG
cmp -s source/$TST.dia $WWW/$TST/$DIAG || exit 1

echo $DIV
TST=latin2
echo $TST
$LGC lgs=source/$TST level=submit $ARGS filter=,latin2,newline,10
echo Checking          $WWW/$TST/$DIAG
cmp -s source/$TST.dia $WWW/$TST/$DIAG || exit 1

echo $DIV
TST=latin3
echo $TST
$LGC lgs=source/$TST level=submit $ARGS filter=,latin3,newline,10
echo Checking          $WWW/$TST/$DIAG
cmp -s source/$TST.dia $WWW/$TST/$DIAG || exit 1

echo $DIV
TST=latin4
echo $TST
$LGC lgs=source/$TST level=submit $ARGS filter=,latin4,newline,10
echo Checking          $WWW/$TST/$DIAG
cmp -s source/$TST.dia $WWW/$TST/$DIAG || exit 1

echo $DIV
TST=cyrillic
echo $TST
$LGC lgs=source/$TST level=submit $ARGS filter=,cyrillic,newline,10
echo Checking          $WWW/$TST/$DIAG
cmp -s source/$TST.dia $WWW/$TST/$DIAG || exit 1

echo $DIV
TST=arabic
echo $TST
$LGC lgs=source/$TST level=submit $ARGS filter=,arabic,newline,10
echo Checking          $WWW/$TST/$DIAG
cmp -s source/$TST.dia $WWW/$TST/$DIAG || exit 1

echo $DIV
TST=greek
echo $TST
$LGC lgs=source/$TST level=submit $ARGS filter=,greek,newline,10
echo Checking          $WWW/$TST/$DIAG
cmp -s source/$TST.dia $WWW/$TST/$DIAG || exit 1

echo $DIV
TST=hebrew
echo $TST
$LGC lgs=source/$TST level=submit $ARGS filter=,hebrew,newline,10
echo Checking          $WWW/$TST/$DIAG
cmp -s source/$TST.dia $WWW/$TST/$DIAG || exit 1

echo $DIV
TST=latin5
echo $TST
$LGC lgs=source/$TST level=submit $ARGS filter=,latin5,newline,10
echo Checking          $WWW/$TST/$DIAG
cmp -s source/$TST.dia $WWW/$TST/$DIAG || exit 1

echo $DIV
TST=latin6
echo $TST
$LGC lgs=source/$TST level=submit $ARGS filter=,latin6,newline,10
echo Checking          $WWW/$TST/$DIAG
cmp -s source/$TST.dia $WWW/$TST/$DIAG || exit 1

echo $DIV
TST=thai
echo $TST
$LGC lgs=source/$TST level=submit $ARGS filter=,thai,newline,10
echo Checking          $WWW/$TST/$DIAG
cmp -s source/$TST.dia $WWW/$TST/$DIAG || exit 1

echo $DIV
TST=latin7
echo $TST
$LGC lgs=source/$TST level=submit $ARGS filter=,latin7,newline,10
echo Checking          $WWW/$TST/$DIAG
cmp -s source/$TST.dia $WWW/$TST/$DIAG || exit 1

echo $DIV
TST=latin8
echo $TST
$LGC lgs=source/$TST level=submit $ARGS filter=,latin8,newline,10
echo Checking          $WWW/$TST/$DIAG
cmp -s source/$TST.dia $WWW/$TST/$DIAG || exit 1

echo $DIV
TST=latin9
echo $TST
$LGC lgs=source/$TST level=submit $ARGS filter=,latin9,newline,10
echo Checking          $WWW/$TST/$DIAG
cmp -s source/$TST.dia $WWW/$TST/$DIAG || exit 1

echo $DIV
TST=latin10
echo $TST
$LGC lgs=source/$TST level=submit $ARGS filter=,latin10,newline,10
echo Checking          $WWW/$TST/$DIAG
cmp -s source/$TST.dia $WWW/$TST/$DIAG || exit 1

echo $DIV
TST=japanese
echo $TST
$LGC lgs=source/$TST level=submit $ARGS filter=,ISO-2022-JP,newline,10
echo Checking          $WWW/$TST/$DIAG
cmp -s source/$TST.dia $WWW/$TST/$DIAG || exit 1

echo $DIV
TST=inc01
echo $TST
( cd source ; $LGC lgs=$TST level=diagnose $ARGS )
echo Checking          $WWW/$TST/$DIAG
cmp -s source/$TST.dia $WWW/$TST/$DIAG || exit 1

echo $DIV
TST=inc02
echo $TST
( cd source ; $LGC lgs=$TST level=diagnose $ARGS )
echo Checking          $WWW/$TST/$DIAG
grep "BJ0Q"            $WWW/$TST/$SRC  || exit 1
diff -q /dev/null      $WWW/$TST/$DIAG || exit 1

echo $DIV
TST=inc02a
echo $TST
( cd source ; $LGC lgs=$TST level=diagnose $ARGS )
echo Checking          $WWW/$TST/$DIAG
grep "BJ0Q"            $WWW/$TST/$SRC  || exit 1
diff -q /dev/null      $WWW/$TST/$DIAG || exit 1

echo $DIV
TST=inc03
echo $TST
( cd source ; $LGC lgs=$TST level=diagnose $ARGS )
echo Checking          $WWW/$TST/$DIAG
cmp -s source/$TST.dia $WWW/$TST/$DIAG || exit 1

echo $DIV
TST=unify
echo $TST
$LGC lgs=proof/$TST level=diagnose $ARGS
echo Checking          $WWW/$TST/$DIAG
grep "Line"            $WWW/$TST/$DIAG || exit 1
grep "L02"             $WWW/$TST/$DIAG || exit 1
grep "in proof of"     $WWW/$TST/$DIAG || exit 1
grep "testlemma"       $WWW/$TST/$DIAG || exit 1
grep "Unable to unify" $WWW/$TST/$DIAG || exit 1
grep "#x"              $WWW/$TST/$DIAG || exit 1
grep "with"            $WWW/$TST/$DIAG || exit 1
grep "#y"              $WWW/$TST/$DIAG || exit 1

echo $DIV
TST=Init
echo $TST
$LGC lgs=proof/$TST level=diagnose $ARGS
echo Checking          $WWW/$TST/$DIAG
grep "Line"            $WWW/$TST/$DIAG || exit 1
grep "L01"             $WWW/$TST/$DIAG || exit 1
grep "in proof of"     $WWW/$TST/$DIAG || exit 1
grep "testlemma"       $WWW/$TST/$DIAG || exit 1
grep "Init-seqop used on non-meta term" \
                       $WWW/$TST/$DIAG || exit 1

echo $DIV
TST=Ponens
echo $TST
$LGC lgs=proof/$TST level=diagnose $ARGS
echo Checking          $WWW/$TST/$DIAG
grep "In proof of"     $WWW/$TST/$DIAG || exit 1
grep "testlemma"       $WWW/$TST/$DIAG || exit 1
grep "Ponens-seqop used on non-inference" \
                       $WWW/$TST/$DIAG || exit 1
grep "#x"              $WWW/$TST/$DIAG || exit 1

echo $DIV
TST=Probans
echo $TST
$LGC lgs=proof/$TST level=diagnose $ARGS
echo Checking          $WWW/$TST/$DIAG
grep "In proof of"     $WWW/$TST/$DIAG || exit 1
grep "testlemma"       $WWW/$TST/$DIAG || exit 1
grep "Probans-seqop used on non-endorsement" \
                       $WWW/$TST/$DIAG || exit 1
grep "#x"              $WWW/$TST/$DIAG || exit 1

echo $DIV
TST=Verify
echo $TST
$LGC lgs=proof/$TST level=diagnose $ARGS
echo Checking          $WWW/$TST/$DIAG
grep "In proof of"     $WWW/$TST/$DIAG || exit 1
grep "testlemma"       $WWW/$TST/$DIAG || exit 1
grep "Verify-seqop used on non-endorsement" \
                       $WWW/$TST/$DIAG || exit 1
grep "#x"              $WWW/$TST/$DIAG || exit 1

echo $DIV
TST=sidecond
echo $TST
$LGC lgs=proof/$TST level=diagnose $ARGS
echo Checking          $WWW/$TST/$DIAG
grep "Line"            $WWW/$TST/$DIAG || exit 1
grep "L08"             $WWW/$TST/$DIAG || exit 1
grep "in proof of"     $WWW/$TST/$DIAG || exit 1
grep "testlemma"       $WWW/$TST/$DIAG || exit 1
grep "Verify-seqop used on false condition" \
                       $WWW/$TST/$DIAG || exit 1
grep "\ c . false"     $WWW/$TST/$DIAG || exit 1

echo $DIV
TST=Curry
echo $TST
$LGC lgs=proof/$TST level=diagnose $ARGS
echo Checking          $WWW/$TST/$DIAG
grep "In proof of"     $WWW/$TST/$DIAG || exit 1
grep "testlemma"       $WWW/$TST/$DIAG || exit 1
grep "Curry-seqop used on unfit argument:" \
                       $WWW/$TST/$DIAG || exit 1
grep "#x"              $WWW/$TST/$DIAG || exit 1

echo $DIV
TST=Uncurry
echo $TST
$LGC lgs=proof/$TST level=diagnose $ARGS
echo Checking          $WWW/$TST/$DIAG
grep "In proof of"     $WWW/$TST/$DIAG || exit 1
grep "testlemma"       $WWW/$TST/$DIAG || exit 1
grep "Uncurry-seqop used on unfit argument:" \
                       $WWW/$TST/$DIAG || exit 1
grep "#x"              $WWW/$TST/$DIAG || exit 1

echo $DIV
TST=Deref
echo $TST
$LGC lgs=proof/$TST level=diagnose $ARGS
echo Checking          $WWW/$TST/$DIAG
grep "In proof of"     $WWW/$TST/$DIAG || exit 1
grep "testlemma"       $WWW/$TST/$DIAG || exit 1
grep "Deref-seqop used on undefined statement:" \
                       $WWW/$TST/$DIAG || exit 1
grep "#x"              $WWW/$TST/$DIAG || exit 1

echo $DIV
TST=Deref2
echo $TST
$LGC lgs=proof/$TST level=diagnose $ARGS
echo Checking          $WWW/$TST/$DIAG
grep "In proof of"     $WWW/$TST/$DIAG || exit 1
grep "testlemma"       $WWW/$TST/$DIAG || exit 1
grep "Deref-seqop applied to" \
                       $WWW/$TST/$DIAG || exit 1
grep "teststatement"   $WWW/$TST/$DIAG || exit 1
grep "produced non-meta term:" \
                       $WWW/$TST/$DIAG || exit 1
grep "#x = All #x : #x" \
                       $WWW/$TST/$DIAG || exit 1

echo $DIV
TST=at
echo $TST
$LGC lgs=proof/$TST level=diagnose $ARGS
echo Checking          $WWW/$TST/$DIAG
grep "In proof of"     $WWW/$TST/$DIAG || exit 1
grep "testlemma"       $WWW/$TST/$DIAG || exit 1
grep "At-seqop used on non-quantifier:" \
                       $WWW/$TST/$DIAG || exit 1
grep "#x"              $WWW/$TST/$DIAG || exit 1

echo $DIV
TST=at2
echo $TST
$LGC lgs=proof/$TST level=diagnose $ARGS
echo Checking          $WWW/$TST/$DIAG
grep "In proof of"     $WWW/$TST/$DIAG || exit 1
grep "testlemma"       $WWW/$TST/$DIAG || exit 1
grep "At-seqop used for non-free substitution. Attempt to instantiate" \
                       $WWW/$TST/$DIAG || exit 1
grep "#x" \
                       $WWW/$TST/$DIAG || exit 1
grep "with"            $WWW/$TST/$DIAG || exit 1
grep "#y"              $WWW/$TST/$DIAG || exit 1

echo $DIV
TST=infer
echo $TST
$LGC lgs=proof/$TST level=diagnose $ARGS
echo Checking          $WWW/$TST/$DIAG
grep "In proof of"     $WWW/$TST/$DIAG || exit 1
grep "testlemma"       $WWW/$TST/$DIAG || exit 1
grep "Infer-seqop used on non-meta term:" \
                       $WWW/$TST/$DIAG || exit 1
grep "#x = All #x : #x" \
                       $WWW/$TST/$DIAG || exit 1

echo $DIV
TST=endorse
echo $TST
$LGC lgs=proof/$TST level=diagnose $ARGS
echo Checking          $WWW/$TST/$DIAG
grep "In proof of"     $WWW/$TST/$DIAG || exit 1
grep "testlemma"       $WWW/$TST/$DIAG || exit 1
grep "Endorse-seqop used on non-meta term:" \
                       $WWW/$TST/$DIAG || exit 1
grep "#x = All #x : #x" \
                       $WWW/$TST/$DIAG || exit 1

echo $DIV
TST=IdEst
echo $TST
$LGC lgs=proof/$TST level=diagnose $ARGS
echo Checking          $WWW/$TST/$DIAG
grep "In proof of"     $WWW/$TST/$DIAG || exit 1
grep "testlemma"       $WWW/$TST/$DIAG || exit 1
grep "IdEst-seqop used on non-matching result. Attempt to match" \
                       $WWW/$TST/$DIAG || exit 1
grep "teststatement"   $WWW/$TST/$DIAG || exit 1
grep "with"            $WWW/$TST/$DIAG || exit 1
grep "All #x :  { #x = #y }" \
                       $WWW/$TST/$DIAG || exit 1

echo $DIV
TST=All1
echo $TST
$LGC lgs=proof/$TST level=diagnose $ARGS
echo Checking          $WWW/$TST/$DIAG
grep "In proof of"     $WWW/$TST/$DIAG || exit 1
grep "testlemma"       $WWW/$TST/$DIAG || exit 1
grep "All-seqop catches variable" \
                       $WWW/$TST/$DIAG || exit 1
grep "#x"              $WWW/$TST/$DIAG || exit 1
grep "which is free in the following premise" \
                       $WWW/$TST/$DIAG || exit 1

echo $DIV
TST=All2
echo $TST
$LGC lgs=proof/$TST level=diagnose $ARGS
echo Checking          $WWW/$TST/$DIAG
grep "In proof of"     $WWW/$TST/$DIAG || exit 1
grep "testlemma"       $WWW/$TST/$DIAG || exit 1
grep "All-seqop catches variable" \
                       $WWW/$TST/$DIAG || exit 1
grep "#x"              $WWW/$TST/$DIAG || exit 1
grep "which is free in the following condition:" \
                       $WWW/$TST/$DIAG || exit 1

echo $DIV
TST=unknown
echo $TST
$LGC lgs=proof/$TST level=diagnose $ARGS
echo Checking          $WWW/$TST/$DIAG
grep "In proof of"     $WWW/$TST/$DIAG || exit 1
grep "testlemma"       $WWW/$TST/$DIAG || exit 1
grep "Unknown seqop in root of" \
                       $WWW/$TST/$DIAG || exit 1
grep "2 + 3"           $WWW/$TST/$DIAG || exit 1

echo $DIV
TST=malform
echo $TST
$LGC lgs=proof/$TST level=diagnose $ARGS
echo Checking          $WWW/$TST/$DIAG
grep "Malformed proof of" \
                       $WWW/$TST/$DIAG || exit 1
grep "testlemma"       $WWW/$TST/$DIAG || exit 1

echo $DIV
TST=sidecond2
echo $TST
$LGC lgs=proof/$TST level=diagnose $ARGS
echo Checking          $WWW/$TST/$DIAG
grep "In proof of"     $WWW/$TST/$DIAG || exit 1
grep "testlemma"       $WWW/$TST/$DIAG || exit 1
grep "Unchecked sidecondition:" \
                       $WWW/$TST/$DIAG || exit 1
grep "#x"              $WWW/$TST/$DIAG || exit 1

echo $DIV
TST=nolemma
echo $TST
$LGC lgs=proof/$TST level=diagnose $ARGS
echo Checking          $WWW/$TST/$DIAG
grep "Proof of non-existent lemma:" \
                       $WWW/$TST/$DIAG || exit 1
grep "testlemma"       $WWW/$TST/$DIAG || exit 1

echo $DIV
TST=wronglemma
echo $TST
$LGC lgs=proof/$TST level=diagnose $ARGS
echo Checking          $WWW/$TST/$DIAG
grep "The proof of"    $WWW/$TST/$DIAG || exit 1
grep "testlemma"       $WWW/$TST/$DIAG || exit 1
grep "does not prove what the lemma says." \
                       $WWW/$TST/$DIAG || exit 1
grep "After macro expansion, the lemma says:" \
                       $WWW/$TST/$DIAG || exit 1
grep "System S infer All #x :  { #x = #x }" \
                       $WWW/$TST/$DIAG || exit 1
grep "After macro, tactic, and sequent expansion, the proof concludes:" \
                       $WWW/$TST/$DIAG || exit 1
grep "#x infer #x" \
                       $WWW/$TST/$DIAG || exit 1

echo $DIV
TST=aux1
echo $TST
$LGC lgs=proof/$TST level=submit $ARGS
echo Checking          $WWW/$TST/$DIAG
diff -q /dev/null      $WWW/$TST/$DIAG || exit 1

echo $DIV
TST=ref1
echo $TST
$LGC lgs=proof/$TST level=diagnose $ARGS
echo Checking          $WWW/$TST/$DIAG
diff -q /dev/null      $WWW/$TST/$DIAG || exit 1

echo $DIV
TST=aux2
echo $TST
$LGC lgs=proof/$TST level=submit $ARGS
echo Checking          $WWW/$TST/$DIAG
diff -q -              $WWW/$TST/$DIAG <<diag || exit 1
math ttst false end test end math
diag

echo $DIV
TST=ref2
echo $TST
$LGC lgs=proof/$TST level=diagnose $ARGS
echo Checking          $WWW/$TST/$DIAG
grep "Lemma"           $WWW/$TST/$DIAG || exit 1
grep "testlemma1"      $WWW/$TST/$DIAG || exit 1
grep "occurs on a page with a non-empty diagnose." \
                       $WWW/$TST/$DIAG || exit 1
grep "Avoid referencing that lemma." \
                       $WWW/$TST/$DIAG || exit 1

echo $DIV
TST=aux3
echo $TST
$LGC lgs=proof/$TST level=submit $ARGS
echo Checking          $WWW/$TST/$DIAG
diff -q /dev/null      $WWW/$TST/$DIAG || exit 1

echo $DIV
TST=ref3
echo $TST
$LGC lgs=proof/$TST level=diagnose $ARGS
echo Checking          $WWW/$TST/$DIAG
grep "Lemma"           $WWW/$TST/$DIAG || exit 1
grep "testlemma1"      $WWW/$TST/$DIAG || exit 1
grep "occurs on a page which has not been checked" \
                       $WWW/$TST/$DIAG || exit 1
grep "by the present proof checker." \
                       $WWW/$TST/$DIAG || exit 1
grep "Avoid referencing that lemma." \
                       $WWW/$TST/$DIAG || exit 1

echo $DIV
TST=noproof
echo $TST
$LGC lgs=proof/$TST level=diagnose $ARGS
echo Checking          $WWW/$TST/$DIAG
grep "Lemma"           $WWW/$TST/$DIAG || exit 1
grep "testlemma1"      $WWW/$TST/$DIAG || exit 1
grep "has no proof. Avoid referencing that lemma." \
                       $WWW/$TST/$DIAG || exit 1

echo $DIV
TST=nocirc
echo $TST
$LGC lgs=proof/$TST level=diagnose $ARGS
echo Checking          $WWW/$TST/$DIAG
diff -q /dev/null      $WWW/$TST/$DIAG || exit 1

echo $DIV
TST=circular
echo $TST
$LGC lgs=proof/$TST level=diagnose $ARGS
echo Checking          $WWW/$TST/$DIAG
grep "Circular proof. The vicious circle includes lemma" \
                       $WWW/$TST/$DIAG || exit 1
grep "testlemma"       $WWW/$TST/$DIAG || exit 1

echo $DIV
TST=unify1
echo $TST
$LGC lgs=proof/$TST level=diagnose $ARGS
echo Checking          $WWW/$TST/$DIAG
grep "Line"            $WWW/$TST/$DIAG || exit 1
grep "L03"             $WWW/$TST/$DIAG || exit 1
grep "in proof of"     $WWW/$TST/$DIAG || exit 1
grep "testlemma"       $WWW/$TST/$DIAG || exit 1
grep "Incomplete unification. Uninstantiated variable:" \
                       $WWW/$TST/$DIAG || exit 1
grep "#x"              $WWW/$TST/$DIAG || exit 1

echo $DIV
TST=rule1
echo $TST
$LGC lgs=proof/$TST level=diagnose $ARGS
echo Checking          $WWW/$TST/$DIAG
grep "Line"            $WWW/$TST/$DIAG || exit 1
grep "L02"             $WWW/$TST/$DIAG || exit 1
grep "in proof of"     $WWW/$TST/$DIAG || exit 1
grep "testlemma"       $WWW/$TST/$DIAG || exit 1
grep "No locally assumed theory includes the following rule:" \
                       $WWW/$TST/$DIAG || exit 1

echo $DIV
TST=rule2
echo $TST
$LGC lgs=proof/$TST level=diagnose $ARGS
echo Checking          $WWW/$TST/$DIAG
grep "Line"            $WWW/$TST/$DIAG || exit 1
grep "L03"             $WWW/$TST/$DIAG || exit 1
grep "in proof of"     $WWW/$TST/$DIAG || exit 1
grep "testlemma"       $WWW/$TST/$DIAG || exit 1
grep "No locally assumed theory includes the following rule:" \
                       $WWW/$TST/$DIAG || exit 1

echo $DIV
TST=plus1
echo $TST
$LGC lgs=proof/$TST level=diagnose $ARGS
echo Checking          $WWW/$TST/$DIAG
diff -q /dev/null      $WWW/$TST/$DIAG || exit 1

echo $DIV
TST=noop
echo $TST
$LGC lgs=proof/$TST level=diagnose $ARGS
echo Checking          $WWW/$TST/$DIAG
grep "Line"            $WWW/$TST/$DIAG || exit 1
grep "L03"             $WWW/$TST/$DIAG || exit 1
grep "in proof of"     $WWW/$TST/$DIAG || exit 1
grep "testlemma"       $WWW/$TST/$DIAG || exit 1
grep "Unknown unitac operator in root of argumentation:" \
                       $WWW/$TST/$DIAG || exit 1
grep "2 + 3"           $WWW/$TST/$DIAG || exit 1

echo $DIV
TST=testsuite
echo $TST
$LGC lgs=$TST level=diagnose $ARGS
diff -q /dev/null      $WWW/$TST/$DIAG || exit 1

echo $DIV
if [ -d /tmp/logiweb.test ]
then
  echo "Remove /tmp/logiweb.test manually"
else
  echo Removing $DIR
  rm -r $DIR
fi

echo $DIV
echo
echo Testsuite succeeded
echo

















