]> granicus.if.org Git - re2c/commitdiff
run_tests.sh: added '--skeleton' option.
authorUlya Trofimovich <skvadrik@gmail.com>
Tue, 13 Oct 2015 13:26:33 +0000 (14:26 +0100)
committerUlya Trofimovich <skvadrik@gmail.com>
Tue, 13 Oct 2015 13:26:33 +0000 (14:26 +0100)
With this option script runs re2c with '--skeleton' and
'-Werror-undefined-control-flow' and instead of comparing results with
reference test results, it compiles the generated skeleton programs and
runs them. If C compiler or binary return nonzero error status, script
reports an error. Note that cases when re2c failed to generate code are
not considered errors (re2c has lots of test cases for its errors).

re2c/run_tests.sh.in

index 091f5e29db76094bcccb81eaa1480d33cb358ed4..ac5bf4346eab26d78875d5a59b14fe9d5bd43962 100644 (file)
@@ -21,6 +21,7 @@ detect_cpu_count () {
 }
 
 valgrind=""
+skeleton=""
 wine=""
 re2c="./re2c"
 threads=`detect_cpu_count; echo $CPUS`
@@ -29,6 +30,7 @@ for arg in $*
 do
        case $arg in
                "--valgrind" ) valgrind=`which valgrind` ;;
+               "--skeleton" ) skeleton="--skeleton" ;;
                "--wine" )
                        wine=`which wine`
                        re2c="${re2c}.exe"
@@ -121,65 +123,89 @@ run_pack() {
                local switches="$switches -W"
 
                local cmd="${valgrind} ${wine} ${re2c} $switches $x"
-               local outname_stdout="${outname}.stdout"
-               local outname_stderr="${outname}.stderr"
-               $cmd 2>$outname_stderr 1>$outname_stdout
-               cat $outname_stderr $outname_stdout > $outname
-               rm $outname_stderr $outname_stdout
-               LC_ALL=C sed -i $outname \
-                       -e "s,$x,`basename $x`,g" \
-                       -e 's,/\* Generated by re2c .*\*/,/\* Generated by re2c \*/,g'
-               if test -n "$genname"
-               then
-                       cat $genname | sed \
-                               -e 's,'"$test_srcdir"'/,,g' \
-                               -e 's,'"$test_blddir"'/,,g' \
-                               -e 's,/\* Generated by re2c .*\*/,/\* Generated by re2c \*/,g' \
-                               >> $outname
-                       rm $genname
-               fi
 
-               if test ! -f ${x%.re}.c
+               if [ x$skeleton == x"--skeleton" ]
                then
-                       echo "FAIL missing ${x%.re}.c"
-                       local errcnt=$(($errcnt + 1))
-                       cp -f $x $outx
-               else
-                       local r=`$diff_prog ${x%.re}.c $outname > $outdiff; echo $?`
-                       if [[ $r == 0 ]]
+                       local outc="${outx%.re}.c"
+                       cmd="${cmd} --skeleton -Werror-undefined-control-flow -o $outc"
+                       mkdir -p `dirname "$outc"`
+
+                       local status=""
+                       [ -z $status ] && status=`$cmd 2>"$outc".stderr || echo "FAIL_RE2C"`
+                       [ -z $status ] && status=`gcc -Wall -Wextra -o "$outc".out "$outc" 2>>"$outc".stderr || echo "FAIL_CC"`
+                       [ -z $status ] && status=`./"$outc".out 2>>"$outc".stderr || echo "FAIL_RUN"`
+                       [ -z $status ] && status="OK"
+                       if [ $status = "OK" -o $status = "FAIL_RE2C" ]
                        then
-                               echo "OK $x: $switches"
-                               rm $outname
+                               rm -f "$outc"{,.line*.{input,keys},.stderr,.out}
                        else
-                               echo "FAIL $x: $switches"
-                               local errcnt=$(($errcnt + 1))
                                cp -f $x $outx
-                               cp -f ${x%.re}.c ${outx%.re}.c
+                               local errcnt=$(($errcnt + 1))
                        fi
-               fi
 
-               if test -n "$headers"
-               then
-                       cat $headers | sed -e 's,'"$test_blddir"'/,,g' -e 's,/\* Generated by re2c .*\*/,/\* Generated by re2c \*/,g' > $typname
-                       rm $headers
-                       if test ! -f ${x%.re}.h
+                       echo "$status $x"
+               else
+                       local outname_stdout="${outname}.stdout"
+                       local outname_stderr="${outname}.stderr"
+                       $cmd 2>$outname_stderr 1>$outname_stdout
+                       cat $outname_stderr $outname_stdout > $outname
+                       rm $outname_stderr $outname_stdout
+                       LC_ALL=C sed -i $outname \
+                               -e "s,$x,`basename $x`,g" \
+                               -e 's,/\* Generated by re2c .*\*/,/\* Generated by re2c \*/,g'
+                       if test -n "$genname"
                        then
-                               echo "FAIL missing ${x%.re}.h"
-                               local errcnt=$(($errcnt + 1))
-                               cp -f $x $outx
-                       elif $diff_prog ${x%.re}.h $typname > $typdiff
+                               cat $genname | sed \
+                                       -e 's,'"$test_srcdir"'/,,g' \
+                                       -e 's,'"$test_blddir"'/,,g' \
+                                       -e 's,/\* Generated by re2c .*\*/,/\* Generated by re2c \*/,g' \
+                                       >> $outname
+                               rm $genname
+                       fi
+
+                       if test ! -f ${x%.re}.c
                        then
-                               echo "OK $x: $switches"
-                               rm $typname
-                       else
-                               echo "FAIL $x: $switches"
+                               echo "FAIL missing ${x%.re}.c"
                                local errcnt=$(($errcnt + 1))
                                cp -f $x $outx
-                               cp -f ${x%.re}.h ${outx%.re}.h
+                       else
+                               local r=`$diff_prog ${x%.re}.c $outname > $outdiff; echo $?`
+                               if [[ $r == 0 ]]
+                               then
+                                       echo "OK $x: $switches"
+                                       rm $outname
+                               else
+                                       echo "FAIL $x: $switches"
+                                       local errcnt=$(($errcnt + 1))
+                                       cp -f $x $outx
+                                       cp -f ${x%.re}.c ${outx%.re}.c
+                               fi
                        fi
+
+                       if test -n "$headers"
+                       then
+                               cat $headers | sed -e 's,'"$test_blddir"'/,,g' -e 's,/\* Generated by re2c .*\*/,/\* Generated by re2c \*/,g' > $typname
+                               rm $headers
+                               if test ! -f ${x%.re}.h
+                               then
+                                       echo "FAIL missing ${x%.re}.h"
+                                       local errcnt=$(($errcnt + 1))
+                                       cp -f $x $outx
+                               elif $diff_prog ${x%.re}.h $typname > $typdiff
+                               then
+                                       echo "OK $x: $switches"
+                                       rm $typname
+                               else
+                                       echo "FAIL $x: $switches"
+                                       local errcnt=$(($errcnt + 1))
+                                       cp -f $x $outx
+                                       cp -f ${x%.re}.h ${outx%.re}.h
+                               fi
+                       fi
+                       test -f $outdiff -a ! -s $outdiff && rm -f $outdiff
+                       test -f $typdiff -a ! -s $typdiff && rm -f $typdiff
+
                fi
-               test -f $outdiff -a ! -s $outdiff && rm -f $outdiff
-               test -f $typdiff -a ! -s $typdiff && rm -f $typdiff
        done
        echo $errcnt > $log
 }