#!/bin/bash 
# automated test script for testing AST and parser structure

TEST_PROG="./ast_test"
PARSER_RESULT_FILE="tmp_result.txt"
TEST_CASE_DIR="../test_case"
NUM_OF_CASES=16

case_number=0 
test_case_file=
test_result_file=
diff_str=
retval=

echo "start running test cases now ..."

while [ $case_number -lt $NUM_OF_CASES ]; do
    test_case_file="$TEST_CASE_DIR/test_case_$case_number.txt"
    test_result_file="$TEST_CASE_DIR/test_result_$case_number.txt"
    $TEST_PROG < $test_case_file > $PARSER_RESULT_FILE
    diff_str=$(diff $PARSER_RESULT_FILE $test_result_file)
    if [ $? -eq 0 ]; then
	echo "test case $case_number passed"
    else
	echo "test case $case_number failed, diff = $diff_str"
    fi
    case_number=$((case_number + 1))
done