]> git.draconx.ca Git - cdecl99.git/blob - tests/crossparse-c-random.sh
Add a test case to check if libcdecl can parse its own output.
[cdecl99.git] / tests / crossparse-c-random.sh
1 #!/bin/sh
2 #
3 # Copyright © 2012 Nick Bowler
4 #
5 # Randomized tests that libcdecl can parse its own output.
6 #
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.
10
11 : "${RANDOMSEED=$RANDOM}" "${TESTITER=100}"
12
13 randomdecl=test/randomdecl$EXEEXT
14 crossparse=test/crossparse$EXEEXT
15 test -x $randomdecl || exit 77
16
17 proc() {
18         result=pass
19         count=0
20
21         while read decl
22         do
23                 count=`expr $count + 1`
24                 $crossparse "$decl" || { result=fail; break; }
25         done
26
27         echo "result=$result"
28         echo "count=$count"
29 }
30
31 printf '%s: randomized test using RANDOMSEED=%d\n' "$0" "$RANDOMSEED"
32
33 eval_cmd=`exec 3>&1
34         { $randomdecl -s "$RANDOMSEED" -n "$TESTITER" 3>&-
35                 echo gen_status=$? >&3
36         } | proc >&3`
37 eval "$eval_cmd"
38
39 expected_count=`expr "$TESTITER" + 0`
40 if test x"$count" != x"$expected_count"; then
41         printf '%s: failed after %d successful tests (out of %d)\n' \
42                 "$0" "$count" "$expected_count" 1>&2
43         exit 1
44 fi
45
46 test x"$result" = x"pass" && test x"$gen_status" = x"0" && exit 0
47 exit 1