examples: fix the test suites.
[bison.git] / examples / mfcalc / test
CommitLineData
c1192f8a
AD
1#! /bin/sh
2
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`
c1192f8a
AD
20
21# Number of the current test.
22number=1
23
24# Exit status of this script.
25exit=true
26
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
c1192f8a
AD
44
45# run EXPECTED-EXIT-STATUS EXPECTED-OUTPUT [PARSER-OPTIONS]
46# ---------------------------------------------------------
47run ()
48{
c3a2e0e6 49 # Expected exit status.
c1192f8a
AD
50 local sta_exp=$1
51 shift
c3a2e0e6 52 # Expected output.
c1192f8a
AD
53 local out_exp=$1
54 shift
c3a2e0e6
AD
55 $prog "$@" - <input >out_eff
56 # Effective exit status.
c1192f8a 57 local sta_eff=$?
c3a2e0e6 58 # Effective output.
c1192f8a
AD
59 local out_eff=`cat out_eff`
60 if test $sta_eff -eq $sta_exp; then
61 if test "$out_eff" = "$out_exp"; then
c3a2e0e6 62 echo "$me: PASS: $number"
c1192f8a 63 else
c3a2e0e6 64 echo "$me: FAIL: $number (expected output: $out_exp, effective: $out_eff)"
c1192f8a
AD
65 exit=false
66 fi
67 else
c3a2e0e6 68 echo "$me: FAIL: $number (expected status: $sta_exp, effective: $sta_eff)"
c1192f8a
AD
69 exit=false
70 fi
71 number=`expr $number + 1`
72}
73
c3a2e0e6 74
c1192f8a
AD
75cat >input <<EOF
761+2*3
77EOF
78run 0 7
79run 0 7
80
81cat >input <<EOF
82(1+2) * 3
83EOF
84run 0 9
85
c1192f8a 86$exit