]> git.draconx.ca Git - cdecl99.git/blob - tests/crossparse-c-random.sh
8fb1b633039d96d2bc39e66fcb9ed2014b5cb5d8
[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=500}"
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
25                         printf 'original input: %s\n' "$decl" 1>&2
26                         break
27                         }
28         done
29
30         echo "result=$result"
31         echo "count=$count"
32 }
33
34 printf '%s: randomized test using RANDOMSEED=%d\n' "$0" "$RANDOMSEED"
35
36 eval_cmd=`exec 3>&1
37         { $randomdecl -s "$RANDOMSEED" -n "$TESTITER" 3>&-
38                 echo gen_status=$? >&3
39         } | proc >&3`
40 eval "$eval_cmd"
41
42 expected_count=`expr "$TESTITER" + 0`
43 if test x"$count" != x"$expected_count"; then
44         printf '%s: failed after %d successful tests (out of %d)\n' \
45                 "$0" "$count" "$expected_count" 1>&2
46         exit 1
47 fi
48
49 test x"$result" = x"pass" && test x"$gen_status" = x"0" && exit 0
50 exit 1