#!/bin/sh

# Note:  use sed to strip blanks because not all systems have same version
# of diff.

say()
{
  echo "$INDENT" " $1"
}

if [ "x$GCTLIB" = "x" ]
then
  GCTLIB=`pwd`/../../../
  PATH=.:`pwd`/../../..:$PATH
  export PATH
fi

# The curious construction is because it's possible on some systems
# to get the wrong shell in the makefile, and different shells have
# different ideas about pwd in the presence of symlinks.
ROOT=`echo pwd | sh`

say basic

/bin/rm -f config/gct-ctrl includer/includer.c
sed s=ABSOLUTE=$ROOT= < gct-ctrl.src > config/gct-ctrl
sed s=ABSOLUTE=$ROOT= < includer.src > includer/includer.c
(cd config; make clean; make GCTLIB=$GCTLIB gct ) > /dev/null
cd config
system | sed s=$ROOT=ABSOLUTE= > system.out; diff system.out system.ref
greport MLOG | sed s=$ROOT=ABSOLUTE= > report.out; diff report.out report.ref

say summary-f

cd ..
gsummary -test-dir config -files config/MLOG | sed s=$ROOT=ABSOLUTE= > summaryf.out
diff summaryf.out summaryf.ref
# -f and -files are synonyms.
gsummary -test-dir config -f config/MLOG | sed s=$ROOT=ABSOLUTE= > summaryf.out
diff summaryf.out summaryf.ref

say summary-r

gsummary -test-dir config -routines config/MLOG | sed s=$ROOT=ABSOLUTE=g > summaryr.out
diff summaryr.out summaryr.ref
# -r and -routines are synonyms.
gsummary -test-dir config -r config/MLOG | sed s=$ROOT=ABSOLUTE=g > summaryr.out
diff summaryr.out summaryr.ref

say summary-vf

gsummary -test-dir config -files -vf "$ROOT/includer/includer.c" config/MLOG | sed s=$ROOT=ABSOLUTE= > summaryfvf.out
diff summaryfvf.out summaryfvf.ref

gsummary -test-dir config -files -visible-file ".*program..c" config/MLOG | sed s=$ROOT=ABSOLUTE= > summaryfvf2.out
diff summaryfvf2.out summaryfvf2.ref

# -visible-file does not apply to included files.
gsummary -test-dir config -files -vf ".*include.*.c" config/MLOG | sed s=$ROOT=ABSOLUTE= > summaryfvf3.out
diff summaryfvf3.out summaryfvf3.ref


say summary-vr-r

# Effect of -visible-routine on -r output.
# Note also checking that a partial match (tail of routine name) does
# not cause output
gsummary -test-dir config -r \
	-vr ncluded2 \
	-vr included3 \
	-visible-routine "function.*" \
    config/MLOG | sed s=$ROOT=ABSOLUTE=g > summaryrvr.out
diff summaryrvr.out summaryrvr.ref

say summary-vr-f

# Effect of -visible-routine on -f output.
gsummary -test-dir config -files \
	-vr ncluded3 \
	-vr included \
	-visible-routine "function[123]" \
    config/MLOG | sed s=$ROOT=ABSOLUTE=g > summaryfvr.out
diff summaryfvr.out summaryfvr.ref

say report-var
# Checking basic use of -vf -vr (including interactions)
greport -test-dir config -vf program -vf ".*ter.c" -vr "function[14].*" -n config/MLOG |\
	sed s=$ROOT=ABSOLUTE= > report-var.out; diff report-var.out report-var.ref


exit 0
