1 # $NetBSD: t_expr.sh,v 1.1 2007/11/12 15:14:00 jmmv Exp $
3 # Copyright (c) 2007 The NetBSD Foundation, Inc.
6 # Redistribution and use in source and binary forms, with or without
7 # modification, are permitted provided that the following conditions
9 # 1. Redistributions of source code must retain the above copyright
10 # notice, this list of conditions and the following disclaimer.
11 # 2. Redistributions in binary form must reproduce the above copyright
12 # notice, this list of conditions and the following disclaimer in the
13 # documentation and/or other materials provided with the distribution.
15 # THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
16 # ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
17 # TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
18 # PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
19 # BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20 # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
21 # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22 # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23 # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
24 # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25 # POSSIBILITY OF SUCH DAMAGE.
28 # The first arg will get eval'd so escape any meta characters
29 # The 2nd arg is an expected string/response from expr for that op.
31 echo "Expression '${1}', expecting '${2}'"
32 res
=`eval expr $1 2>&1`
33 if [ "$res" != "$2" ]; then
34 atf_fail
"Expected $2, got $res from expression: " \
39 atf_test_case overflow
41 atf_set
"descr" "Test overflow cases"
44 test_expr
'4611686018427387904 + 4611686018427387903' \
46 test_expr
'4611686018427387904 + 4611686018427387904' \
47 "expr: integer overflow or underflow occurred for operation '4611686018427387904 + 4611686018427387904'"
48 test_expr
'4611686018427387904 - -4611686018427387904' \
49 "expr: integer overflow or underflow occurred for operation '4611686018427387904 - -4611686018427387904'"
50 test_expr
'-4611686018427387904 - 4611686018427387903' \
51 '-9223372036854775807'
52 test_expr
'-4611686018427387904 - 4611686018427387905' \
53 "expr: integer overflow or underflow occurred for operation '-4611686018427387904 - 4611686018427387905'"
54 test_expr
'-4611686018427387904 \* 1' '-4611686018427387904'
55 test_expr
'-4611686018427387904 \* -1' '4611686018427387904'
56 test_expr
'-4611686018427387904 \* 2' '-9223372036854775808'
57 test_expr
'-4611686018427387904 \* 3' \
58 "expr: integer overflow or underflow occurred for operation '-4611686018427387904 * 3'"
59 test_expr
'-4611686018427387904 \* -2' \
60 "expr: integer overflow or underflow occurred for operation '-4611686018427387904 * -2'"
61 test_expr
'4611686018427387904 \* 1' '4611686018427387904'
62 test_expr
'4611686018427387904 \* 2' \
63 "expr: integer overflow or underflow occurred for operation '4611686018427387904 * 2'"
64 test_expr
'4611686018427387904 \* 3' \
65 "expr: integer overflow or underflow occurred for operation '4611686018427387904 * 3'"
70 atf_set
"descr" "Test from gtk-- configure that cause problems on old expr"
73 test_expr
'3 \> 3 \| 3 = 3 \& 4 \> 4 \| 3 = 3 \& 4 = 4 \& 5 \>= 5' '1'
74 test_expr
'3 \> 3 \| 3 = 3 \& 4 \> 4 \| 3 = 3 \& 4 = 4 \& 5 \>= 6' '0'
75 test_expr
'3 \> 3 \| 3 = 3 \& 4 \> 4 \| 3 = 3 \& 4 = 3 \& 5 \>= 5' '0'
76 test_expr
'3 \> 3 \| 3 = 3 \& 4 \> 4 \| 3 = 2 \& 4 = 4 \& 5 \>= 5' '0'
77 test_expr
'3 \> 2 \| 3 = 3 \& 4 \> 4 \| 3 = 3 \& 4 = 4 \& 5 \>= 6' '1'
78 test_expr
'3 \> 3 \| 3 = 3 \& 4 \> 3 \| 3 = 3 \& 4 = 4 \& 5 \>= 5' '1'
81 atf_test_case colon_vs_math
82 colon_vs_math_head
() {
83 atf_set
"descr" "Basic precendence test with the : operator vs. math"
85 colon_vs_math_body
() {
86 test_expr
'2 : 4 / 2' '0'
87 test_expr
'4 : 4 % 3' '1'
90 atf_test_case arithmetic_ops
91 arithmetic_ops_head
() {
92 atf_set
"descr" "Dangling arithemtic operator"
94 arithmetic_ops_body
() {
95 test_expr
'.java_wrapper : /' '0'
96 test_expr
'4 : \*' '0'
100 test_expr
'4 : %' '0'
103 atf_test_case basic_math
105 atf_set
"descr" "Basic math test"
108 test_expr
'2 + 4 \* 5' '22'
111 atf_test_case basic_functional
112 basic_functional_head
() {
113 atf_set
"descr" "Basic functional tests"
115 basic_functional_body
() {
118 test_expr
'hello' 'hello'
121 atf_test_case compare_ops_precedence
122 compare_ops_precedence_head
() {
123 atf_set
"descr" "Compare operator precendence test"
125 compare_ops_precedence_body
() {
126 test_expr
'2 \> 1 \* 17' '0'
129 atf_test_case compare_ops
131 atf_set
"descr" "Compare operator tests"
134 test_expr
'2 \!= 5' '1'
135 test_expr
'2 \!= 2' '0'
136 test_expr
'2 \<= 3' '1'
137 test_expr
'2 \<= 2' '1'
138 test_expr
'2 \<= 1' '0'
139 test_expr
'2 \< 3' '1'
140 test_expr
'2 \< 2' '0'
141 test_expr
'2 = 2' '1'
142 test_expr
'2 = 4' '0'
143 test_expr
'2 \>= 1' '1'
144 test_expr
'2 \>= 2' '1'
145 test_expr
'2 \>= 3' '0'
146 test_expr
'2 \> 1' '1'
147 test_expr
'2 \> 2' '0'
150 atf_test_case multiply
152 atf_set
"descr" "Test the multiply operator"
155 test_expr
'1 \* -1' '-1'
158 atf_test_case negative
160 atf_set
"descr" "Test the additive inverse"
163 test_expr
'-1 + 5' '4'
164 test_expr
'- 1 + 5' 'expr: syntax error'
166 test_expr
'5 + -1' '4'
167 test_expr
'5 + - 1' 'expr: syntax error'
169 test_expr
'1 - -5' '6'
172 atf_test_case math_precedence
173 math_precedence_head
() {
174 atf_set
"descr" "More complex math test for precedence"
176 math_precedence_body
() {
177 test_expr
'-3 + -1 \* 4 + 3 / -6' '-7'
180 atf_test_case precedence
182 atf_set
"descr" "Test precedence"
185 # This is messy but the shell escapes cause that
186 test_expr
'X1/2/3 : X\\\(.\*[^/]\\\)//\*[^/][^/]\*/\*$ \| . : \\\(.\\\)' '1/2'
191 atf_set
"descr" "Test proper () returning \1 from a regex"
194 # This is messy but the shell escapes cause that
195 test_expr
'1/2 : .\*/\\\(.\*\\\)' '2'
198 atf_init_test_cases
()
200 atf_add_test_case overflow
201 atf_add_test_case gtkmm
202 atf_add_test_case colon_vs_math
203 atf_add_test_case arithmetic_ops
204 atf_add_test_case basic_math
205 atf_add_test_case basic_functional
206 atf_add_test_case compare_ops_precedence
207 atf_add_test_case compare_ops
208 atf_add_test_case multiply
209 atf_add_test_case negative
210 atf_add_test_case math_precedence
211 atf_add_test_case precedence
212 atf_add_test_case regex