]> matita.cs.unibo.it Git - helm.git/blob - helm/matita/scripts/do_tests.sh
New framework for regression of bad tests.
[helm.git] / helm / matita / scripts / do_tests.sh
1 #!/bin/bash
2
3 OK="\e[32mOK\e[0m"
4 FAIL="\e[31mFAIL\e[0m"
5
6 if [ "$1" = "-no-color" ]; then
7   shift
8   OK="OK"
9   FAIL="FAIL"
10 fi
11 if [ "$1" = "-twice" ]; then
12   shift
13   TWICE=1
14 fi
15
16 COMPILER=$1
17 shift
18 CLEANER=$1
19 shift
20 LOGFILE=$1
21 shift
22 EXPECTED=$1
23 shift
24 TODO="$@"
25
26 if [ -z "$COMPILER" -o -z "$CLEANER" -o -z "$LOGFILE" -o -z "$EXPECTED" -o -z "$TODO" ]; then
27   echo
28   echo "usage: "
29   echo "  do_tests.sh [-no-color] [-twice] ./compiler ./cleaner logfile expected_result test.ma ..."
30   echo
31   echo "options:  "
32   echo "  -no-color Do not use vt100 colors"
33   echo "  -twice    Run each test twice but show only the second run times"
34   echo
35   echo "If expected_result is OK the result will be OK if the test compiles."
36   echo "Otherwise if expected_result is FAIL the result will be OK if the test"
37   echo "does not compile and the generated output is equal to test.log."
38   echo "The value of the DO_TESTS_EXTRA evironment variable"
39   echo "will be appended to each line."
40   exit 1
41 fi
42
43 LOG=.__log
44 DIFF=.__diff
45
46 export TIMEFORMAT="%2lR %2lU %2lS"
47 for T in $TODO; do
48   printf "$COMPILER\t%-30s   " $T
49   if [ "$TWICE" = "1" ]; then
50     $CLEANER $T 1>/dev/null 2>/dev/null
51     $COMPILER $T 1>/dev/null 2>/dev/null
52   fi
53   $CLEANER $T 1>/dev/null 2>/dev/null
54   TIMES=`(time $COMPILER $T > $LOG 2>&1) 2>&1`
55   RC=$?;
56   cat $LOG >> $LOGFILE
57   touch $DIFF
58   if [ $EXPECTED = "FAIL" ]; then
59    if [ $RC = 0 ]; then
60      echo "The test was successful but it should have failed!" > $DIFF
61      RC=1;
62    else
63      diff $LOG `basename $T .ma`.log > $DIFF
64      RC=$?
65      rm -f $LOG
66    fi
67   fi
68   if [ $RC = 0 ]; then
69     printf "$OK\t$TIMES\t$DO_TESTS_EXTRA\n"
70   else
71     printf "$FAIL\t$TIMES\t$DO_TESTS_EXTRA\n";
72     cat $DIFF
73   fi
74   rm -f $DIFF
75   exit $RC
76 done