#/bin/csh
# Motif
#
# Copyright (c) 1987-2012, The Open Group. All rights reserved.
#
# These libraries and programs are free software; you can
# redistribute them and/or modify them under the terms of the GNU
# Lesser General Public License as published by the Free Software
# Foundation; either version 2 of the License, or (at your option)
# any later version.
#
# These libraries and programs are distributed in the hope that
# they will be useful, but WITHOUT ANY WARRANTY; without even the
# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
# PURPOSE. See the GNU Lesser General Public License for more
# details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with these librararies and programs; if not, write
# to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
# Floor, Boston, MA 02110-1301 USA
#
# HISTORY


#run validator into a listing file
#assumes you are running in ./tests/uil/validator and that uil
#compiler is build and located at ../../../../clients/uil/uil

if !(-e ../../../../clients/uil/uil) then
   echo "***ERROR!***"
   echo "Your uil compiler is missing."
   echo "Please build it in ../../../../clients/uil."
   exit (1)
endif

if !(-x ../../../../clients/uil/uil) then
   echo "***ERROR!***"
   echo "Your uil compiler is not executable."
   echo "Please change its permissions."
   exit (1)
endif

echo "Uil compiler in place at ../../../../clients/uil/uil."

if !(-w .) then
   echo "***ERROR!***"
   echo "This directory is unwriteable."
   echo "Please change the permissions."
   exit (1)
endif

#cleanup if need be
if (-e validator.uid) then
   rm validator.uid
endif
if (-e run.log) then
   rm run.log
endif
if (-e run.out) then
   rm run.out
endif
if (-e run.diff) then
   rm run.diff
endif

echo "Beginning test..."

../../../../clients/uil/uil -o validator.uid validator.uil -v run.out

set postCompileStatus = $status

#remove the Page/date headers which show up in every diff
#and other stuff which makes maintenance tedious

sed -e '/Page/d' -e '/^Module/d' -e 's///g' -e '/^$/d' -e 's/^ *[0-9]* *//'  run.out | sed -e '/(0)[ 	]*$/d' > run.log
diff -c validator.log run.log > run.diff

set diffStatus = $status

#report results
clear
echo " "
echo "*************RESULTS*************"
echo "***PART I: Exit Status***********"
echo "   PostCompileStatus expected is 1, actual is" $postCompileStatus
if ($postCompileStatus == 1) then
echo "   Part I PASSES"
else
echo "   Part I FAILS"
endif
if ($postCompileStatus > 4) then
echo "The status indicates a severe failure."
endif
echo "  "
echo "***PART II: Log Comparison*******"
if ($diffStatus == 0) then
   echo "   The run and source files are the same."
   echo "   Part II PASSES."
   echo "  "
else
   echo "   The run and source files are different."
   echo "   To determine the extent of the failure, check the differences"
   echo "     between run.log and validator.log, as shown in run.diff."
   echo "   It is possible that spurious file differences may have caused"
   echo "     the failure."
   echo "   In evaluating the results, remember each valid entry in validator.uil"
   echo "     should be compiled without error, and each INVALID entry should"
   echo "     have an error generated."
   echo "   Part II FAILS"
   echo " "
endif
echo "*************END OF TEST*********"
echo "   "
