t_expr.sh revision 1.3.2.2 1 1.3.2.2 yamt # $NetBSD: t_expr.sh,v 1.3.2.2 2012/04/17 00:09:02 yamt Exp $
2 1.3.2.2 yamt #
3 1.3.2.2 yamt # Copyright (c) 2007 The NetBSD Foundation, Inc.
4 1.3.2.2 yamt # All rights reserved.
5 1.3.2.2 yamt #
6 1.3.2.2 yamt # Redistribution and use in source and binary forms, with or without
7 1.3.2.2 yamt # modification, are permitted provided that the following conditions
8 1.3.2.2 yamt # are met:
9 1.3.2.2 yamt # 1. Redistributions of source code must retain the above copyright
10 1.3.2.2 yamt # notice, this list of conditions and the following disclaimer.
11 1.3.2.2 yamt # 2. Redistributions in binary form must reproduce the above copyright
12 1.3.2.2 yamt # notice, this list of conditions and the following disclaimer in the
13 1.3.2.2 yamt # documentation and/or other materials provided with the distribution.
14 1.3.2.2 yamt #
15 1.3.2.2 yamt # THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
16 1.3.2.2 yamt # ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
17 1.3.2.2 yamt # TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
18 1.3.2.2 yamt # PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
19 1.3.2.2 yamt # BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20 1.3.2.2 yamt # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
21 1.3.2.2 yamt # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22 1.3.2.2 yamt # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23 1.3.2.2 yamt # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
24 1.3.2.2 yamt # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25 1.3.2.2 yamt # POSSIBILITY OF SUCH DAMAGE.
26 1.3.2.2 yamt #
27 1.3.2.2 yamt
28 1.3.2.2 yamt # The first arg will get eval'd so escape any meta characters
29 1.3.2.2 yamt # The 2nd arg is an expected string/response from expr for that op.
30 1.3.2.2 yamt test_expr() {
31 1.3.2.2 yamt echo "Expression '${1}', expecting '${2}'"
32 1.3.2.2 yamt res=`eval expr $1 2>&1`
33 1.3.2.2 yamt if [ "$res" != "$2" ]; then
34 1.3.2.2 yamt atf_fail "Expected $2, got $res from expression: " \
35 1.3.2.2 yamt "`eval echo $1`"
36 1.3.2.2 yamt fi
37 1.3.2.2 yamt }
38 1.3.2.2 yamt
39 1.3.2.2 yamt atf_test_case lang
40 1.3.2.2 yamt lang_ops_head() {
41 1.3.2.2 yamt atf_set "descr" "Test that expr(1) works with non-C LANG (PR bin/2486)"
42 1.3.2.2 yamt }
43 1.3.2.2 yamt lang_body() {
44 1.3.2.2 yamt
45 1.3.2.2 yamt export LANG=nonexistent
46 1.3.2.2 yamt atf_check -s exit:0 -o inline:"21\n" -e empty -x "expr 10 + 11"
47 1.3.2.2 yamt
48 1.3.2.2 yamt export LANG=ru_RU.KOI8-R
49 1.3.2.2 yamt atf_check -s exit:0 -o inline:"21\n" -e empty -x "expr 10 + 11"
50 1.3.2.2 yamt }
51 1.3.2.2 yamt
52 1.3.2.2 yamt atf_test_case overflow
53 1.3.2.2 yamt overflow_head() {
54 1.3.2.2 yamt atf_set "descr" "Test overflow cases"
55 1.3.2.2 yamt }
56 1.3.2.2 yamt overflow_body() {
57 1.3.2.2 yamt test_expr '4611686018427387904 + 4611686018427387903' \
58 1.3.2.2 yamt '9223372036854775807'
59 1.3.2.2 yamt test_expr '4611686018427387904 + 4611686018427387904' \
60 1.3.2.2 yamt "expr: integer overflow or underflow occurred for operation '4611686018427387904 + 4611686018427387904'"
61 1.3.2.2 yamt test_expr '4611686018427387904 - -4611686018427387904' \
62 1.3.2.2 yamt "expr: integer overflow or underflow occurred for operation '4611686018427387904 - -4611686018427387904'"
63 1.3.2.2 yamt test_expr '-4611686018427387904 - 4611686018427387903' \
64 1.3.2.2 yamt '-9223372036854775807'
65 1.3.2.2 yamt test_expr '-4611686018427387904 - 4611686018427387905' \
66 1.3.2.2 yamt "expr: integer overflow or underflow occurred for operation '-4611686018427387904 - 4611686018427387905'"
67 1.3.2.2 yamt test_expr '-4611686018427387904 \* 1' '-4611686018427387904'
68 1.3.2.2 yamt test_expr '-4611686018427387904 \* -1' '4611686018427387904'
69 1.3.2.2 yamt test_expr '-4611686018427387904 \* 2' '-9223372036854775808'
70 1.3.2.2 yamt test_expr '-4611686018427387904 \* 3' \
71 1.3.2.2 yamt "expr: integer overflow or underflow occurred for operation '-4611686018427387904 * 3'"
72 1.3.2.2 yamt test_expr '-4611686018427387904 \* -2' \
73 1.3.2.2 yamt "expr: integer overflow or underflow occurred for operation '-4611686018427387904 * -2'"
74 1.3.2.2 yamt test_expr '4611686018427387904 \* 1' '4611686018427387904'
75 1.3.2.2 yamt test_expr '4611686018427387904 \* 2' \
76 1.3.2.2 yamt "expr: integer overflow or underflow occurred for operation '4611686018427387904 * 2'"
77 1.3.2.2 yamt test_expr '4611686018427387904 \* 3' \
78 1.3.2.2 yamt "expr: integer overflow or underflow occurred for operation '4611686018427387904 * 3'"
79 1.3.2.2 yamt }
80 1.3.2.2 yamt
81 1.3.2.2 yamt atf_test_case gtkmm
82 1.3.2.2 yamt gtkmm_head() {
83 1.3.2.2 yamt atf_set "descr" "Test from gtk-- configure that cause problems on old expr"
84 1.3.2.2 yamt }
85 1.3.2.2 yamt gtkmm_body() {
86 1.3.2.2 yamt test_expr '3 \> 3 \| 3 = 3 \& 4 \> 4 \| 3 = 3 \& 4 = 4 \& 5 \>= 5' '1'
87 1.3.2.2 yamt test_expr '3 \> 3 \| 3 = 3 \& 4 \> 4 \| 3 = 3 \& 4 = 4 \& 5 \>= 6' '0'
88 1.3.2.2 yamt test_expr '3 \> 3 \| 3 = 3 \& 4 \> 4 \| 3 = 3 \& 4 = 3 \& 5 \>= 5' '0'
89 1.3.2.2 yamt test_expr '3 \> 3 \| 3 = 3 \& 4 \> 4 \| 3 = 2 \& 4 = 4 \& 5 \>= 5' '0'
90 1.3.2.2 yamt test_expr '3 \> 2 \| 3 = 3 \& 4 \> 4 \| 3 = 3 \& 4 = 4 \& 5 \>= 6' '1'
91 1.3.2.2 yamt test_expr '3 \> 3 \| 3 = 3 \& 4 \> 3 \| 3 = 3 \& 4 = 4 \& 5 \>= 5' '1'
92 1.3.2.2 yamt }
93 1.3.2.2 yamt
94 1.3.2.2 yamt atf_test_case colon_vs_math
95 1.3.2.2 yamt colon_vs_math_head() {
96 1.3.2.2 yamt atf_set "descr" "Basic precendence test with the : operator vs. math"
97 1.3.2.2 yamt }
98 1.3.2.2 yamt colon_vs_math_body() {
99 1.3.2.2 yamt test_expr '2 : 4 / 2' '0'
100 1.3.2.2 yamt test_expr '4 : 4 % 3' '1'
101 1.3.2.2 yamt }
102 1.3.2.2 yamt
103 1.3.2.2 yamt atf_test_case arithmetic_ops
104 1.3.2.2 yamt arithmetic_ops_head() {
105 1.3.2.2 yamt atf_set "descr" "Dangling arithemtic operator"
106 1.3.2.2 yamt }
107 1.3.2.2 yamt arithmetic_ops_body() {
108 1.3.2.2 yamt test_expr '.java_wrapper : /' '0'
109 1.3.2.2 yamt test_expr '4 : \*' '0'
110 1.3.2.2 yamt test_expr '4 : +' '0'
111 1.3.2.2 yamt test_expr '4 : -' '0'
112 1.3.2.2 yamt test_expr '4 : /' '0'
113 1.3.2.2 yamt test_expr '4 : %' '0'
114 1.3.2.2 yamt }
115 1.3.2.2 yamt
116 1.3.2.2 yamt atf_test_case basic_math
117 1.3.2.2 yamt basic_math_head() {
118 1.3.2.2 yamt atf_set "descr" "Basic math test"
119 1.3.2.2 yamt }
120 1.3.2.2 yamt basic_math_body() {
121 1.3.2.2 yamt test_expr '2 + 4 \* 5' '22'
122 1.3.2.2 yamt }
123 1.3.2.2 yamt
124 1.3.2.2 yamt atf_test_case basic_functional
125 1.3.2.2 yamt basic_functional_head() {
126 1.3.2.2 yamt atf_set "descr" "Basic functional tests"
127 1.3.2.2 yamt }
128 1.3.2.2 yamt basic_functional_body() {
129 1.3.2.2 yamt test_expr '2' '2'
130 1.3.2.2 yamt test_expr '-4' '-4'
131 1.3.2.2 yamt test_expr 'hello' 'hello'
132 1.3.2.2 yamt }
133 1.3.2.2 yamt
134 1.3.2.2 yamt atf_test_case compare_ops_precedence
135 1.3.2.2 yamt compare_ops_precedence_head() {
136 1.3.2.2 yamt atf_set "descr" "Compare operator precendence test"
137 1.3.2.2 yamt }
138 1.3.2.2 yamt compare_ops_precedence_body() {
139 1.3.2.2 yamt test_expr '2 \> 1 \* 17' '0'
140 1.3.2.2 yamt }
141 1.3.2.2 yamt
142 1.3.2.2 yamt atf_test_case compare_ops
143 1.3.2.2 yamt compare_ops_head() {
144 1.3.2.2 yamt atf_set "descr" "Compare operator tests"
145 1.3.2.2 yamt }
146 1.3.2.2 yamt compare_ops_body() {
147 1.3.2.2 yamt test_expr '2 \!= 5' '1'
148 1.3.2.2 yamt test_expr '2 \!= 2' '0'
149 1.3.2.2 yamt test_expr '2 \<= 3' '1'
150 1.3.2.2 yamt test_expr '2 \<= 2' '1'
151 1.3.2.2 yamt test_expr '2 \<= 1' '0'
152 1.3.2.2 yamt test_expr '2 \< 3' '1'
153 1.3.2.2 yamt test_expr '2 \< 2' '0'
154 1.3.2.2 yamt test_expr '2 = 2' '1'
155 1.3.2.2 yamt test_expr '2 = 4' '0'
156 1.3.2.2 yamt test_expr '2 \>= 1' '1'
157 1.3.2.2 yamt test_expr '2 \>= 2' '1'
158 1.3.2.2 yamt test_expr '2 \>= 3' '0'
159 1.3.2.2 yamt test_expr '2 \> 1' '1'
160 1.3.2.2 yamt test_expr '2 \> 2' '0'
161 1.3.2.2 yamt }
162 1.3.2.2 yamt
163 1.3.2.2 yamt atf_test_case multiply
164 1.3.2.2 yamt multiply_head() {
165 1.3.2.2 yamt atf_set "descr" "Test the multiply operator (PR bin/12838)"
166 1.3.2.2 yamt }
167 1.3.2.2 yamt multiply_body() {
168 1.3.2.2 yamt test_expr '1 \* -1' '-1'
169 1.3.2.2 yamt test_expr '2 \> 1 \* 17' '0'
170 1.3.2.2 yamt }
171 1.3.2.2 yamt
172 1.3.2.2 yamt atf_test_case negative
173 1.3.2.2 yamt negative_head() {
174 1.3.2.2 yamt atf_set "descr" "Test the additive inverse"
175 1.3.2.2 yamt }
176 1.3.2.2 yamt negative_body() {
177 1.3.2.2 yamt test_expr '-1 + 5' '4'
178 1.3.2.2 yamt test_expr '- 1 + 5' 'expr: syntax error'
179 1.3.2.2 yamt
180 1.3.2.2 yamt test_expr '5 + -1' '4'
181 1.3.2.2 yamt test_expr '5 + - 1' 'expr: syntax error'
182 1.3.2.2 yamt
183 1.3.2.2 yamt test_expr '1 - -5' '6'
184 1.3.2.2 yamt }
185 1.3.2.2 yamt
186 1.3.2.2 yamt atf_test_case math_precedence
187 1.3.2.2 yamt math_precedence_head() {
188 1.3.2.2 yamt atf_set "descr" "More complex math test for precedence"
189 1.3.2.2 yamt }
190 1.3.2.2 yamt math_precedence_body() {
191 1.3.2.2 yamt test_expr '-3 + -1 \* 4 + 3 / -6' '-7'
192 1.3.2.2 yamt }
193 1.3.2.2 yamt
194 1.3.2.2 yamt atf_test_case precedence
195 1.3.2.2 yamt precedence_head() {
196 1.3.2.2 yamt atf_set "descr" "Test precedence"
197 1.3.2.2 yamt }
198 1.3.2.2 yamt precedence_body() {
199 1.3.2.2 yamt # This is messy but the shell escapes cause that
200 1.3.2.2 yamt test_expr 'X1/2/3 : X\\\(.\*[^/]\\\)//\*[^/][^/]\*/\*$ \| . : \\\(.\\\)' '1/2'
201 1.3.2.2 yamt }
202 1.3.2.2 yamt
203 1.3.2.2 yamt atf_test_case regex
204 1.3.2.2 yamt regex_head() {
205 1.3.2.2 yamt atf_set "descr" "Test proper () returning \1 from a regex"
206 1.3.2.2 yamt }
207 1.3.2.2 yamt regex_body() {
208 1.3.2.2 yamt # This is messy but the shell escapes cause that
209 1.3.2.2 yamt test_expr '1/2 : .\*/\\\(.\*\\\)' '2'
210 1.3.2.2 yamt }
211 1.3.2.2 yamt
212 1.3.2.2 yamt atf_init_test_cases()
213 1.3.2.2 yamt {
214 1.3.2.2 yamt atf_add_test_case lang
215 1.3.2.2 yamt atf_add_test_case overflow
216 1.3.2.2 yamt atf_add_test_case gtkmm
217 1.3.2.2 yamt atf_add_test_case colon_vs_math
218 1.3.2.2 yamt atf_add_test_case arithmetic_ops
219 1.3.2.2 yamt atf_add_test_case basic_math
220 1.3.2.2 yamt atf_add_test_case basic_functional
221 1.3.2.2 yamt atf_add_test_case compare_ops_precedence
222 1.3.2.2 yamt atf_add_test_case compare_ops
223 1.3.2.2 yamt atf_add_test_case multiply
224 1.3.2.2 yamt atf_add_test_case negative
225 1.3.2.2 yamt atf_add_test_case math_precedence
226 1.3.2.2 yamt atf_add_test_case precedence
227 1.3.2.2 yamt atf_add_test_case regex
228 1.3.2.2 yamt }
229