]> git.draconx.ca Git - cdecl99.git/blobdiff - tests/crossparse-c-random.sh
Add better --help text to the test programs.
[cdecl99.git] / tests / crossparse-c-random.sh
index 8fb1b633039d96d2bc39e66fcb9ed2014b5cb5d8..a800f3f938b065c49029464cdf8277383d212227 100755 (executable)
@@ -14,19 +14,52 @@ randomdecl=test/randomdecl$EXEEXT
 crossparse=test/crossparse$EXEEXT
 test -x $randomdecl || exit 77
 
+# Slow case: run tests one at a time to determine exactly which one failed.
+first_failed() {
+       ff_count=0
+
+       while test $# -gt 0
+       do
+               $crossparse "$1" 2>/dev/null || break
+               ff_count=`expr $ff_count + 1`
+               shift
+       done
+
+       echo "$ff_count"
+}
+
 proc() {
        result=pass
        count=0
 
+       set x
        while read decl
        do
-               count=`expr $count + 1`
-               $crossparse "$decl" || { result=fail
-                       printf 'original input: %s\n' "$decl" 1>&2
-                       break
+               set "$@" "$decl"
+
+               # Accumulate tests in $@ and run them in batches to avoid
+               # significant startup costs.
+               if test $# -gt 25; then
+                       shift
+                       $crossparse "$@" || { result=fail
+                               tmp_count=`first_failed "$@"`
+                               count=`expr $count + $tmp_count`
+                               break
                        }
+                       count=`expr $count + $#`
+                       set x
+               fi
        done
 
+       shift
+       if test $# -gt 0 && test x"$result" = x"pass"; then
+               tmp_count=$#
+               $crossparse "$@" || { result=fail
+                       tmp_count=`first_failed "$@"`
+               }
+               count=`expr $count + $tmp_count`
+       fi
+
        echo "result=$result"
        echo "count=$count"
 }
@@ -39,6 +72,12 @@ eval_cmd=`exec 3>&1
        } | proc >&3`
 eval "$eval_cmd"
 
+if test x"$gen_status" != x"0"; then
+       printf '%s: %s failed with status=%d\n' \
+               "$0" "$randomdecl" "$gen_status" 1>&2
+       exit 1
+fi
+
 expected_count=`expr "$TESTITER" + 0`
 if test x"$count" != x"$expected_count"; then
        printf '%s: failed after %d successful tests (out of %d)\n' \
@@ -46,5 +85,5 @@ if test x"$count" != x"$expected_count"; then
        exit 1
 fi
 
-test x"$result" = x"pass" && test x"$gen_status" = x"0" && exit 0
+test x"$result" = x"pass" && exit 0
 exit 1