#!/bin/sh

PMCCABE=${PMCCABE:-../pmccabe}

testlist='
	test000
	test001
	test002
	test003
	test004
	test005
	test006/*.H
	test007
	test008
	test009
	test010
	test011
	test012
	test013
	test014
	test015
	test016
	test017
	test018
	test019
	test020
	test021
	test022
	test023
	test024
	test025
	test026
	test027'

testlist=`echo $testlist`

error=0

# record the command and output
# save stderr separately to prevent buffering/interlace ordering problems
run_pmccabe()
{
    echo "RUN: $PMCCABE $@"
    $PMCCABE "$@" 2>.tmp
    cat .tmp
    rm .tmp
}

TEST1()
{
    f=$1
    shift

    (
	run_pmccabe -X -vt $*
	run_pmccabe -X -vnt $*
	run_pmccabe -x -vt $*
    ) > $f.out

    if [ -f $f.ref -a -z "$REFERENCE" ]
    then
	if ! cmp $f.ref $f.out
        then
	    error=2
	    diff $f.ref $f.out
	fi
    else
	echo "Creating new REFERENCE file $f.ref"
	mv $f.out $f.ref
    fi
}

TEST1 testlist $testlist

for n in $testlist
do
    TEST1 $n $n
done

exit $error
