Commit | Line | Data |
---|---|---|
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 |
18 | me=`dirname $0` |
19 | me=`basename $me` | |
c1192f8a AD |
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. | |
c3a2e0e6 AD |
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 | |
c1192f8a AD |
44 | |
45 | # run EXPECTED-EXIT-STATUS EXPECTED-OUTPUT [PARSER-OPTIONS] | |
46 | # --------------------------------------------------------- | |
47 | run () | |
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 |
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 | ||
c1192f8a | 86 | $exit |