]> git.saurik.com Git - bison.git/blame - examples/calc++/test
examples: fix the test suites.
[bison.git] / examples / calc++ / test
CommitLineData
0ffd4fd1 1#! /bin/sh
828c373b 2
3272a725
AD
3# Copyright (C) 2005-2012 Free Software Foundation, Inc.
4#
5# This program is free software: you can redistribute it and/or modify
6# it under the terms of the GNU General Public License as published by
7# the Free Software Foundation, either version 3 of the License, or
8# (at your option) any later version.
9#
10# This program is distributed in the hope that it will be useful,
11# but WITHOUT ANY WARRANTY; without even the implied warranty of
12# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13# GNU General Public License for more details.
14#
15# You should have received a copy of the GNU General Public License
16# along with this program. If not, see <http://www.gnu.org/licenses/>.
17
c3a2e0e6
AD
18me=`dirname $0`
19me=`basename $me`
414c76a4
AD
20
21# Number of the current test.
22number=1
23
24# Exit status of this script.
25exit=true
26
2e4986a8 27# The exercised program.
c3a2e0e6
AD
28prog=../examples/$me/$me
29
30# cleanup
31# -------
32cleanup ()
33{
34 local status=$?
35 if test -z "$DEBUG"; then
36 cd ..
37 rm -rf $$.dir
38 fi
39 exit $status
40}
41trap cleanup 0 1 2 13 15
42mkdir $$.dir
43cd $$.dir
2e4986a8 44
1a7a65f9
AD
45# run EXPECTED-EXIT-STATUS EXPECTED-OUTPUT [PARSER-OPTIONS]
46# ---------------------------------------------------------
414c76a4
AD
47run ()
48{
c3a2e0e6 49 # Expected exit status.
414c76a4
AD
50 local sta_exp=$1
51 shift
c3a2e0e6 52 # Expected output.
1a7a65f9
AD
53 local out_exp=$1
54 shift
2e4986a8 55 $prog "$@" - <input >out_eff
c3a2e0e6 56 # Effective exit status.
414c76a4 57 local sta_eff=$?
c3a2e0e6 58 # Effective output.
1a7a65f9 59 local out_eff=`cat out_eff`
414c76a4 60 if test $sta_eff -eq $sta_exp; then
1a7a65f9 61 if test "$out_eff" = "$out_exp"; then
c3a2e0e6 62 echo "$me: PASS: $number"
1a7a65f9 63 else
c3a2e0e6 64 echo "$me: FAIL: $number (expected output: $out_exp, effective: $out_eff)"
1a7a65f9
AD
65 exit=false
66 fi
414c76a4 67 else
c3a2e0e6 68 echo "$me: FAIL: $number (expected status: $sta_exp, effective: $sta_eff)"
414c76a4
AD
69 exit=false
70 fi
71 number=`expr $number + 1`
72}
73
2e4986a8
AD
74
75cat >input <<EOF
76toto := 1
77toto
78EOF
79run 0 1 -s
80
81
0ffd4fd1
AD
82cat >input <<EOF
83a := 1
84b := 2
85c := 3
86d := a + b * c
87d
88EOF
1a7a65f9
AD
89run 0 7
90run 0 7 -p
91
92
93cat >input <<EOF
94a := 1
95b := 2
96c := 3
97d := (a + b) * c
98d
99EOF
100run 0 9
0ffd4fd1 101
0ffd4fd1
AD
102
103cat >input <<EOF
104a := 1
105d := a + b * c
106EOF
2e4986a8 107run 1 ''
828c373b 108
414c76a4 109$exit