#!/bin/bash

# regression test  (need to run regrtest -ocaml in ../elsa before)
#
# run ast_graph and dot on all ast files found
#
# takes a long time because doing graph layout with dot is time consuming
# to improve to timings you can patch dot to exit after parsing the dot file
# call this dot-parseonly, place it into the PATH and use the option -parse


trap "echo Interupted; exit 1" SIGINT

# load variable ast-files
. regtest-ast-files

function usage(){
    echo "usage: regtest-graph [-skip <n>]"
    exit 1
}

skip=0
typeset -i count=0

while [ $# -ge 1 ] ; do
    case $1 in
	-skip)	
	    if [ $# -lt 2 ] ; then
		usage
	    fi
	    skip=$2
	    shift;;
	*)  usage;;
    esac
    shift
done

for f in $ast_files ; do
    if [ $skip -gt $count ]; then
	echo "[$count] skip $f"
    else
	echo "[$count] test $f"
	./count-ast $f > output-count-ast 2>&1
	result=$?
	if [ ! $result -eq 0 ] ; then
	    echo count-ast exit $result on $f >&2
	    exit $result
	fi
	./count-ast-new $f > output-count-ast-new 2>&1
	result=$?
	if [ ! $result -eq 0 ] ; then
	    echo count-ast-new exit $result on $f >&2
	    exit $result
	fi
	diff output-count-ast output-count-ast-new
	result=$?
	if [ ! $result -eq 0 ] ; then
	    echo output differs on $f >&2
	    exit $result
	fi	
    fi
    count=$count+1
    rm -f output-count-ast output-count-ast-new 
done

