]> git.saurik.com Git - bison.git/blob - examples/calc++/test
2aa917bc070f5ef3c3e7c6559232cb5df5dbf679
[bison.git] / examples / calc++ / test
1 #! /bin/sh
2
3 test -z "$VERBOSE" && {
4 exec > /dev/null 2>&1
5 set -x
6 }
7
8 me=`basename $0`
9
10 # Number of the current test.
11 number=1
12
13 # Exit status of this script.
14 exit=true
15
16 # run EXPECTED-EXIT-STATUS EXPECTED-OUTPUT [PARSER-OPTIONS]
17 # ---------------------------------------------------------
18 run ()
19 {
20 # Effective and expected exit status.
21 local sta_exp=$1
22 shift
23 local out_exp=$1
24 shift
25 ./calc++ "$@" input >out_eff
26 local sta_eff=$?
27 local out_eff=`cat out_eff`
28 if test $sta_eff -eq $sta_exp; then
29 if test "$out_eff" = "$out_exp"; then
30 printf "$me: PASS: %2d\n" $number
31 else
32 printf "$me: FAIL: %2d (expected output: %s, effective: %s\n" \
33 $number "$out_exp" "$out_eff"
34 exit=false
35 fi
36 else
37 printf "$me: FAIL: %2d (expected status: %d, effective: %d\n" \
38 $number $sta_exp $sta_eff
39 exit=false
40 fi
41 number=`expr $number + 1`
42 }
43
44 cat >input <<EOF
45 a := 1
46 b := 2
47 c := 3
48 d := a + b * c
49 d
50 EOF
51 run 0 7
52 run 0 7 -p
53
54
55 cat >input <<EOF
56 a := 1
57 b := 2
58 c := 3
59 d := (a + b) * c
60 d
61 EOF
62 run 0 9
63
64
65 cat >input <<EOF
66 a := 1
67 d := a + b * c
68 EOF
69 run 1 '' input
70
71
72 cat >input <<EOF
73 toto := 1
74 toto
75 EOF
76 run 0 1 -s
77
78 rm input out_eff
79 $exit