#! /bin/bash

criteria="*.xc"
tot_passed=0
tot_failed=0

function xlang_test ()
{
  rm -Rf $1.tmp
  touch $1.tmp

  ../xlang $1.$2 > $1.tmp 2> $1.err
  tr -d '\r' < $1.tmp > $1.out
  rm $1.tmp

  diff $1.out $1.tst > $1.diff 2> /dev/null
  ret=$?

  if [ $ret -eq 0 ]; then
    let tot_passed=tot_passed+1
    msg="Passed";
  else
    let tot_failed=tot_failed+1
    msg="Failed"
  fi

  echo "  " $3 : $msg
}

function xlang_test_main ()
{
  echo "Main tests"
  echo "----------"
  echo ""

  xlang_test "test-01" "xc" "Comparators test"
  xlang_test "test-02" "xc" "While test"
  xlang_test "test-03" "xc" "Empty test"
  xlang_test "test-04" "xc" "Invalid class test"
  xlang_test "test-05" "xc" "Invalid file name"
  xlang_test "test-06" "xx" "Invalid file name extension"
  xlang_test "test-07" "xc" "Undefined variable"
  xlang_test "test-08" "xc" "Array"
  xlang_test "test-09" "xc" "Class test"
  xlang_test "test-10" "xc" "Callback"

  echo ""
}

function xlang_test_ffxz ()
{
  echo "Xiong PuXiang tests"
  echo "-------------------"
  echo ""

  xlang_test "ffxz-01" "xc" "Test #01"
  xlang_test "ffxz-02" "xc" "Test #02"

  echo ""
}

function xlang_test_gcc ()
{
  echo "GCC tests (adapted)"
  echo "-------------------"
  echo ""

  xlang_test "gcc-20000224-1" "xc" "Test #01"
}

echo ""
echo "---------------------"
echo "X Language bench test"
echo "---------------------"
echo ""

cd ./test
xlang_test_main
xlang_test_ffxz
xlang_test_gcc

echo ""
echo "Summary"
echo "-------"
echo ""
echo "Total passed :      " $tot_passed
echo "Total failed :      " $tot_failed
echo ""     

