#!/bin/sh

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

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

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

# This is conveniently changed to 'mv' when the tests change.
DIFF=diff


make clean
gct-init $GCTLIB
gct -B$GCTLIB test.c
a.out
mv gct-map gct-map.tmp

say base-effects
cp gct-map.tmp gct-map
uedit File test.c S
greport -all -edit GCTLOG > base.log
cp gct-map.tmp gct-map
uedit Internal-File test.h I
greport -all -edit -show-ignored GCTLOG >> base.log
cp gct-map.tmp gct-map
uedit Routine main I
greport -all -edit -show-ignored GCTLOG >> base.log
$DIFF base.log base.ref


say "internal>file"
cp gct-map.tmp gct-map
uedit Internal-File test.h S
uedit File test.c I
greport -all -edit GCTLOG > if.log; $DIFF if.log extS.ref

say "routine>file"
cp gct-map.tmp gct-map
uedit Routine main V
uedit File test.c I
greport -all -edit GCTLOG > rf.log; $DIFF rf.log plain.ref

say "routine>internal"
cp gct-map.tmp gct-map
uedit Routine main S
uedit Internal-File test.c I
greport -all -edit GCTLOG > ri.log; $DIFF ri.log extS.ref

say "line>file"
cp gct-map.tmp gct-map
uedit File test.c V
gedit edit.s
greport -all -edit GCTLOG > lf.log; $DIFF lf.log lineS.ref

say "line>internal"
cp gct-map.tmp gct-map
uedit Internal-File test.h S
gedit edit.v
greport -all -edit GCTLOG > li.log; $DIFF li.log lineV.ref

say "line>routine"
cp gct-map.tmp gct-map
uedit Routine main S
gedit edit.i
greport -show-ignored -all -edit GCTLOG > lr.log; $DIFF lr.log lineI.ref


# PART 2

say "E-ignored-vf"
cp gct-map.tmp gct-map
uedit File test.c V
uedit Internal-File test.h V
uedit Routine main V
gedit edit.v
greport -vf dummy -all -edit GCTLOG

say "E-ignored-vr"
greport -vr dummy -all -edit GCTLOG

say "E-ignored-vf-vr"
greport -vf dummy -visible-routine dummyrout -all -edit GCTLOG




# -vf without -vr 
say "E-visible-vf-file"
cp gct-map.tmp gct-map
uedit File test.c I
greport -vf test.c -all -edit GCTLOG > E.log; $DIFF E.log plain.ref

say "E-visible-vf-internal"
uedit Internal-File test.h S
greport -vf test.c -all -edit GCTLOG > E.log; $DIFF E.log extS.ref

say "E-visible-vf-routine"
uedit Internal-File test.h I
uedit Routine main S
greport -vf test.c -all -edit GCTLOG > E.log; $DIFF E.log extS.ref

say "E-visible-vf-line"
uedit Routine main I
gedit edit.s
greport -vf test.c -all -edit GCTLOG > E.log; $DIFF E.log lineS.ref



# -vf with -vr causing ignoration.
say "E-visible-vf-ignored-vr-file"
cp gct-map.tmp gct-map
uedit File test.c I
greport -vr nonexist -vf test.c -all -edit GCTLOG > E.log; $DIFF E.log plain.ref

say "E-visible-vf-ignored-vr-internal"
uedit Internal-File test.h S
greport -vf nonexist -vf test.c -all -edit GCTLOG > E.log; $DIFF E.log extS.ref

say "E-visible-vf-ignored-vr-routine"
uedit Internal-File test.h I
uedit Routine main S
greport -vr nonexist -vf test.c -all -edit GCTLOG > E.log; $DIFF E.log extS.ref

say "E-visible-vf-ignored-vr-line"
uedit Routine main I
gedit edit.s
greport -vr nonexist -vf test.c -all -edit GCTLOG > E.log; $DIFF E.log lineS.ref


# -vf and -vr both causing visibility (vr takes precedence)
say "E-visible-vf-visible-vr-file"
cp gct-map.tmp gct-map
uedit File test.c I
greport -vr main -vf test.c -all -edit GCTLOG > E.log; $DIFF E.log plain.ref

say "E-visible-vf-visible-vr-internal"
uedit Internal-File test.h S
greport -vr main -vf test.c -all -edit GCTLOG > E.log; $DIFF E.log extS.ref

say "E-visible-vf-visible-vr-routine"
uedit Routine main I
greport -vr main -vf test.c -all -edit GCTLOG > E.log; $DIFF E.log extS.ref
uedit Internal-File test.h -
greport -vr main -vf test.c -all -edit GCTLOG > E.log; $DIFF E.log plain.ref

say "E-visible-vf-visible-vr-line"
gedit edit.s
greport -vr main -vf test.c -all -edit GCTLOG > E.log; $DIFF E.log lineS.ref
gedit edit.i
greport -vr main -vf test.c -all -edit GCTLOG




# -vf ignored and -vr causing visibility (vr takes precedence)
say "E-ignored-vf-visible-vr-file"
cp gct-map.tmp gct-map
uedit File test.c I
greport -vr main -vf nofile.c -all -edit GCTLOG > E.log; $DIFF E.log plain.ref

say "E-ignored-vf-visible-vr-internal"
cp gct-map.tmp gct-map
uedit Internal-File test.h S
greport -vr main -vf nofile.c -all -edit GCTLOG > E.log; $DIFF E.log extS.ref

say "E-ignored-vf-visible-vr-routine"
uedit Routine main I
greport -vr main -vf nofile.c -all -edit GCTLOG > E.log; $DIFF E.log extS.ref
uedit Internal-File test.h -
greport -vr main -vf nofile.c -all -edit GCTLOG > E.log; $DIFF E.log plain.ref

say "E-ignored-vf-visible-vr-line"
cp gct-map.tmp gct-map
gedit edit.s
greport -vr main -vf nofile.c -all -edit GCTLOG > E.log; $DIFF E.log lineS.ref
gedit edit.i
greport -vr main -vf nofile.c -all -edit GCTLOG




# -vr causing visibility
say "E-visible-vr-file"
cp gct-map.tmp gct-map
uedit File test.c I
greport -vr main -all -edit GCTLOG > E.log; $DIFF E.log plain.ref

say "E-visible-vr-internal"
cp gct-map.tmp gct-map
uedit Internal-File test.h S
greport -vr main -all -edit GCTLOG > E.log; $DIFF E.log extS.ref

say "E-visible-vr-routine"
uedit Routine main I
greport -vr main -all -edit GCTLOG > E.log; $DIFF E.log extS.ref
uedit Internal-File test.h -
uedit File test.c I
greport -vr main -all -edit GCTLOG > E.log; $DIFF E.log plain.ref

say "E-visible-vr-line"
cp gct-map.tmp gct-map
gedit edit.s
greport -vr main -all -edit GCTLOG > E.log; $DIFF E.log lineS.ref
gedit edit.i
greport -vr main -all -edit GCTLOG
uedit Internal-File test.h S
greport -vr main -all -edit GCTLOG

exit 0
