]>
Commit | Line | Data |
---|---|---|
726f6388 JA |
1 | # @(#)precedence_test 1.0 91/07/24 Maarten Litmaath |
2 | # test of relative precedences for `&&' and `||' operators | |
3 | ||
4 | echo "\`Say' echos its argument. Its return value is of no interest." | |
5 | case `echo -n` in | |
6 | '') Say () { echo -n "$*" ; } ;; | |
7 | *) Say () { echo "$*\c" ; } ;; | |
8 | esac | |
9 | ||
10 | echo "\`Truth' echos its argument and returns a TRUE result." | |
11 | Truth () { | |
12 | Say $1; | |
13 | return 0; | |
14 | } | |
15 | ||
16 | echo "\`False' echos its argument and returns a FALSE result." | |
17 | False () { | |
18 | Say $1; | |
19 | return 1; | |
20 | } | |
21 | ||
22 | echo "" | |
23 | ||
24 | cmd1='$open $test1 && $test2 $close || $test3' | |
25 | cmd2='$test1 || $open $test2 && $test3 $close' | |
26 | ||
27 | grouping_sh= | |
28 | grouping_C='( )' | |
29 | ||
30 | test3='Say 3' | |
31 | ||
32 | for i in 1 2 | |
33 | do | |
34 | eval proto=\$cmd$i | |
35 | ||
36 | for test1 in 'Truth 1' 'False 1' | |
37 | do | |
38 | for test2 in 'Truth 2' 'False 2' | |
39 | do | |
40 | for precedence in sh C | |
41 | do | |
42 | eval set x \$grouping_$precedence | |
43 | shift | |
44 | open=${1-' '} | |
45 | close=${2-' '} | |
46 | eval cmd=\""$proto"\" | |
47 | Say "$cmd output=" | |
48 | output=`eval "$cmd"` | |
49 | Say "$output" | |
50 | read correct || { echo 'Input fubar. Abort.' >&2; exit 1; } | |
51 | test "X$output" = "X$correct" || echo " correct=$correct" | |
52 | echo '' | |
53 | done | |
54 | ||
55 | echo '' | |
56 | done | |
57 | done | |
58 | done << EOF | |
59 | 12 | |
60 | 12 | |
61 | 123 | |
62 | 123 | |
63 | 13 | |
64 | 13 | |
65 | 13 | |
66 | 13 | |
67 | 13 | |
68 | 1 | |
69 | 13 | |
70 | 1 | |
71 | 123 | |
72 | 123 | |
73 | 12 | |
74 | 12 | |
75 | EOF |