3 # Copyright © 2012 Nick Bowler
5 # Randomized tests that libcdecl can parse its own output.
7 # License WTFPL2: Do What The Fuck You Want To Public License, version 2.
8 # This is free software: you are free to do what the fuck you want to.
9 # There is NO WARRANTY, to the extent permitted by law.
11 : "${RANDOMSEED=$RANDOM}" "${TESTITER=500}"
13 randomdecl=test/randomdecl$EXEEXT
14 crossparse=test/crossparse$EXEEXT
15 test -x $randomdecl || exit 77
17 # Slow case: run tests one at a time to determine exactly which one failed.
23 $crossparse "$1" 2>/dev/null || break
24 ff_count=`expr $ff_count + 1`
40 # Accumulate tests in $@ and run them in batches to avoid
41 # significant startup costs.
42 if test $# -gt 25; then
44 $crossparse "$@" || { result=fail
45 tmp_count=`first_failed "$@"`
46 count=`expr $count + $tmp_count`
49 count=`expr $count + $#`
55 if test $# -gt 0 && test x"$result" = x"pass"; then
57 $crossparse "$@" || { result=fail
58 tmp_count=`first_failed "$@"`
60 count=`expr $count + $tmp_count`
67 printf '%s: randomized test using RANDOMSEED=%d\n' "$0" "$RANDOMSEED"
70 { $randomdecl -s "$RANDOMSEED" -n "$TESTITER" 3>&-
71 echo gen_status=$? >&3
75 if test x"$gen_status" != x"0"; then
76 printf '%s: %s failed with status=%d\n' \
77 "$0" "$randomdecl" "$gen_status" 1>&2
81 expected_count=`expr "$TESTITER" + 0`
82 if test x"$count" != x"$expected_count"; then
83 printf '%s: failed after %d successful tests (out of %d)\n' \
84 "$0" "$count" "$expected_count" 1>&2
88 test x"$result" = x"pass" && exit 0