1# @(#)precedence_test 1.0 91/07/24 Maarten Litmaath
2# test of relative precedences for `&&' and `||' operators
3
4echo "\`Say' echos its argument. Its return value is of no interest."
5case `echo -n` in
6  '') Say () { echo -n "$*" ; } ;;
7   *) Say () { echo "$*\c" ; } ;;
8esac
9
10echo "\`Truth' echos its argument and returns a TRUE result."
11Truth () {
12  Say $1;
13  return 0;
14}
15
16echo "\`False' echos its argument and returns a FALSE result."
17False () {
18  Say $1;
19  return 1;
20}
21
22echo ""
23
24cmd1='$open $test1 && $test2 $close || $test3'
25cmd2='$test1 || $open $test2 && $test3 $close'
26
27grouping_sh=
28grouping_C='( )'
29
30test3='Say 3'
31
32for i in 1 2
33do
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
58done << EOF
5912
6012
61123
62123
6313
6413
6513
6613
6713
681
6913
701
71123
72123
7312
7412
75EOF
76