#!/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"
}

error_and_no_change()
{
  say $1
  make clean
  /bin/rm -f $1.c
  cp $1.cref $1.c
  gct-init $GCTLIB
  gct -B$GCTLIB $1.c > $1.log 2>&1 
  diff $1.log $1.ref
  diff $1.cref $1.c
}

# TEST 1:  conditions:
# 	File is unreadable - so can't check if instrumented.

say noread
make clean
/bin/rm -f ok.c
cp ok.cref ok.c
chmod a-r ok.c
gct-init $GCTLIB
gct -B$GCTLIB ok.c 2>&1 | grep -v '^grep' > noread.log 
chmod a+r ok.c
diff noread.log noread.ref
diff ok.c ok.cref


# TEST 2:  conditions:
# 	File is readable and already instrumented.
#	Create backup directory

say already
make clean
/bin/rm -rf gct_backup ok.c
cp ok.cref ok.c
gct-init $GCTLIB
gct -B$GCTLIB ok.c
gct -B$GCTLIB ok.c > already.log 2>&1
diff already.log already.ref
grestore
diff ok.cref ok.c

# TEST 3:  syntax error during instrumentation

error_and_no_change synerr
error_and_no_change synerr2	# Syntax at eof handled differently by GCC.

# TEST 4:  semantic error during instrumentation
error_and_no_change semerr

# (GCT error during instrumentation is tested elsewhere.)

exit 0



