]> git.saurik.com Git - bison.git/blob - examples/mfcalc/test
examples: fix the test suites.
[bison.git] / examples / mfcalc / test
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
18 me=`dirname $0`
19 me=`basename $me`
20
21 # Number of the current test.
22 number=1
23
24 # Exit status of this script.
25 exit=true
26
27 # The exercised program.
28 prog=../examples/$me/$me
29
30 # cleanup
31 # -------
32 cleanup ()
33 {
34 local status=$?
35 if test -z "$DEBUG"; then
36 cd ..
37 rm -rf $$.dir
38 fi
39 exit $status
40 }
41 trap cleanup 0 1 2 13 15
42 mkdir $$.dir
43 cd $$.dir
44
45 # run EXPECTED-EXIT-STATUS EXPECTED-OUTPUT [PARSER-OPTIONS]
46 # ---------------------------------------------------------
47 run ()
48 {
49 # Expected exit status.
50 local sta_exp=$1
51 shift
52 # Expected output.
53 local out_exp=$1
54 shift
55 $prog "$@" - <input >out_eff
56 # Effective exit status.
57 local sta_eff=$?
58 # Effective output.
59 local out_eff=`cat out_eff`
60 if test $sta_eff -eq $sta_exp; then
61 if test "$out_eff" = "$out_exp"; then
62 echo "$me: PASS: $number"
63 else
64 echo "$me: FAIL: $number (expected output: $out_exp, effective: $out_eff)"
65 exit=false
66 fi
67 else
68 echo "$me: FAIL: $number (expected status: $sta_exp, effective: $sta_eff)"
69 exit=false
70 fi
71 number=`expr $number + 1`
72 }
73
74
75 cat >input <<EOF
76 1+2*3
77 EOF
78 run 0 7
79 run 0 7
80
81 cat >input <<EOF
82 (1+2) * 3
83 EOF
84 run 0 9
85
86 $exit