]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/bc/tests/all.sh
MFV 364468:
[FreeBSD/FreeBSD.git] / contrib / bc / tests / all.sh
1 #! /bin/sh
2 #
3 # SPDX-License-Identifier: BSD-2-Clause
4 #
5 # Copyright (c) 2018-2020 Gavin D. Howard and contributors.
6 #
7 # Redistribution and use in source and binary forms, with or without
8 # modification, are permitted provided that the following conditions are met:
9 #
10 # * Redistributions of source code must retain the above copyright notice, this
11 #   list of conditions and the following disclaimer.
12 #
13 # * Redistributions in binary form must reproduce the above copyright notice,
14 #   this list of conditions and the following disclaimer in the documentation
15 #   and/or other materials provided with the distribution.
16 #
17 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18 # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
21 # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22 # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23 # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24 # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25 # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26 # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27 # POSSIBILITY OF SUCH DAMAGE.
28 #
29
30 set -e
31
32 script="$0"
33 testdir=$(dirname "$script")
34
35 . "$testdir/../functions.sh"
36
37 if [ "$#" -ge 1 ]; then
38         d="$1"
39         shift
40 else
41         err_exit "usage: $script dir [run_extra_tests] [run_stack_tests] [gen_tests] [time_tests] [exec args...]" 1
42 fi
43
44 if [ "$#" -lt 1 ]; then
45         extra=1
46 else
47         extra="$1"
48         shift
49 fi
50
51 if [ "$#" -lt 1 ]; then
52         run_stack_tests=1
53 else
54         run_stack_tests="$1"
55         shift
56 fi
57
58 if [ "$#" -lt 1 ]; then
59         generate_tests=1
60 else
61         generate_tests="$1"
62         shift
63 fi
64
65 if [ "$#" -lt 1 ]; then
66         time_tests=0
67 else
68         time_tests="$1"
69         shift
70 fi
71
72 if [ "$#" -lt 1 ]; then
73         exe="$testdir/../bin/$d"
74 else
75         exe="$1"
76         shift
77 fi
78
79 stars="***********************************************************************"
80 printf '%s\n' "$stars"
81
82 if [ "$d" = "bc" ]; then
83         halt="quit"
84 else
85         halt="q"
86 fi
87
88 unset BC_ENV_ARGS
89 unset BC_LINE_LENGTH
90 unset DC_ENV_ARGS
91 unset DC_LINE_LENGTH
92
93 printf '\nRunning %s tests...\n\n' "$d"
94
95 while read t; do
96
97         if [ "$extra" -eq 0  ]; then
98                 if [ "$t" = "trunc" ] || [ "$t" = "places" ] || [ "$t" = "shift" ] || \
99                    [ "$t" = "lib2" ] || [ "$t" = "scientific" ] || [ "$t" = "rand" ] || \
100                    [ "$t" = "engineering" ]
101                 then
102                         printf 'Skipping %s %s\n' "$d" "$t"
103                         continue
104                 fi
105         fi
106
107         sh "$testdir/test.sh" "$d" "$t" "$generate_tests" "$time_tests" "$exe" "$@"
108
109 done < "$testdir/$d/all.txt"
110
111 sh "$testdir/stdin.sh" "$d" "$exe" "$@"
112
113 sh "$testdir/scripts.sh" "$d" "$extra" "$run_stack_tests" "$generate_tests" "$time_tests" "$exe" "$@"
114 sh "$testdir/read.sh" "$d" "$exe" "$@"
115 sh "$testdir/errors.sh" "$d" "$exe" "$@"
116
117 num=100000000000000000000000000000000000000000000000000000000000000000000000000000
118 numres="$num"
119 num70="10000000000000000000000000000000000000000000000000000000000000000000\\
120 0000000000"
121
122 if [ "$d" = "bc" ]; then
123         halt="halt"
124         opt="x"
125         lopt="extended-register"
126         line_var="BC_LINE_LENGTH"
127 else
128         halt="q"
129         opt="l"
130         lopt="mathlib"
131         line_var="DC_LINE_LENGTH"
132         num="$num pR"
133 fi
134
135 printf '\nRunning %s quit test...' "$d"
136
137 printf '%s\n' "$halt" | "$exe" "$@" > /dev/null 2>&1
138
139 if [ "$d" = bc ]; then
140         printf '%s\n' "quit" | "$exe" "$@" > /dev/null 2>&1
141         two=$("$exe" "$@" -e 1+1 -e quit)
142         if [ "$two" != "2" ]; then
143                 err_exit "$d failed a quit test" 1
144         fi
145 fi
146
147 printf 'pass\n'
148
149 base=$(basename "$exe")
150
151 if [ "$base" != "bc" -a "$base" != "dc" ]; then
152         exit 0
153 fi
154
155 printf 'Running %s environment var tests...' "$d"
156
157 if [ "$d" = "bc" ]; then
158         export BC_ENV_ARGS=" '-l' '' -q"
159         export BC_EXPR_EXIT="1"
160         printf 's(.02893)\n' | "$exe" "$@" > /dev/null
161         "$exe" -e 4 "$@" > /dev/null
162 else
163         export DC_ENV_ARGS="'-x'"
164         export DC_EXPR_EXIT="1"
165         printf '4s stuff\n' | "$exe" "$@" > /dev/null
166         "$exe" -e 4pR "$@" > /dev/null
167 fi
168
169 printf 'pass\n'
170
171 out1="$testdir/../.log_$d.txt"
172 out2="$testdir/../.log_${d}_test.txt"
173
174 printf 'Running %s line length tests...' "$d"
175
176 printf '%s\n' "$numres" > "$out1"
177
178 export "$line_var"=80
179 printf '%s\n' "$num" | "$exe" "$@" > "$out2"
180
181 diff "$out1" "$out2"
182
183 printf '%s\n' "$num70" > "$out1"
184
185 export "$line_var"=2147483647
186 printf '%s\n' "$num" | "$exe" "$@" > "$out2"
187
188 diff "$out1" "$out2"
189
190 printf 'pass\n'
191
192 printf 'Running %s arg tests...' "$d"
193
194 f="$testdir/$d/add.txt"
195 exprs=$(cat "$f")
196 results=$(cat "$testdir/$d/add_results.txt")
197
198 printf '%s\n%s\n%s\n%s\n' "$results" "$results" "$results" "$results" > "$out1"
199
200 "$exe" "$@" -e "$exprs" -f "$f" --expression "$exprs" --file "$f" -e "$halt" > "$out2"
201
202 diff "$out1" "$out2"
203
204 printf '%s\n' "$halt" | "$exe" "$@" -- "$f" "$f" "$f" "$f" > "$out2"
205
206 diff "$out1" "$out2"
207
208 if [ "$d" = "bc" ]; then
209         printf '%s\n' "$halt" | "$exe" "$@" -i > /dev/null 2>&1
210 fi
211
212 printf '%s\n' "$halt" | "$exe" "$@" -h > /dev/null
213 printf '%s\n' "$halt" | "$exe" "$@" -P > /dev/null
214 printf '%s\n' "$halt" | "$exe" "$@" -v > /dev/null
215 printf '%s\n' "$halt" | "$exe" "$@" -V > /dev/null
216
217 set +e
218
219 "$exe" "$@" -f "saotehasotnehasthistohntnsahxstnhalcrgxgrlpyasxtsaosysxsatnhoy.txt" > /dev/null 2> "$out2"
220 err="$?"
221
222 checktest "$d" "$err" "invalid file argument" "$out2" "$d"
223
224 "$exe" "$@" "-$opt" -e "$exprs" > /dev/null 2> "$out2"
225 err="$?"
226
227 checktest "$d" "$err" "invalid option argument" "$out2" "$d"
228
229 "$exe" "$@" "--$lopt" -e "$exprs" > /dev/null 2> "$out2"
230 err="$?"
231
232 checktest "$d" "$err" "invalid long option argument" "$out2" "$d"
233
234 "$exe" "$@" "-u" -e "$exprs" > /dev/null 2> "$out2"
235 err="$?"
236
237 checktest "$d" "$err" "unrecognized option argument" "$out2" "$d"
238
239 "$exe" "$@" "--uniform" -e "$exprs" > /dev/null 2> "$out2"
240 err="$?"
241
242 checktest "$d" "$err" "unrecognized long option argument" "$out2" "$d"
243
244 "$exe" "$@" -f > /dev/null 2> "$out2"
245 err="$?"
246
247 checktest "$d" "$err" "missing required argument to short option" "$out2" "$d"
248
249 "$exe" "$@" --file > /dev/null 2> "$out2"
250 err="$?"
251
252 checktest "$d" "$err" "missing required argument to long option" "$out2" "$d"
253
254 "$exe" "$@" --version=5 > /dev/null 2> "$out2"
255 err="$?"
256
257 checktest "$d" "$err" "given argument to long option with no argument" "$out2" "$d"
258
259 printf 'pass\n'
260
261 printf 'Running %s directory test...' "$d"
262
263 "$exe" "$@" "$testdir" > /dev/null 2> "$out2"
264 err="$?"
265
266 checktest "$d" "$err" "directory" "$out2" "$d"
267
268 printf 'pass\n'
269
270 printf 'Running %s binary file test...' "$d"
271
272 bin="/bin/sh"
273
274 "$exe" "$@" "$bin" > /dev/null 2> "$out2"
275 err="$?"
276
277 checktest "$d" "$err" "binary file" "$out2" "$d"
278
279 printf 'pass\n'
280
281 printf 'Running %s binary stdin test...' "$d"
282
283 cat "$bin" | "$exe" "$@" > /dev/null 2> "$out2"
284 err="$?"
285
286 checktest "$d" "$err" "binary stdin" "$out2" "$d"
287
288 printf 'pass\n'
289
290 if [ "$d" = "bc" ]; then
291
292         printf 'Running %s limits tests...' "$d"
293         printf 'limits\n' | "$exe" "$@" > "$out2" /dev/null 2>&1
294
295         if [ ! -s "$out2" ]; then
296                 err_exit "$d did not produce output on the limits test" 1
297         fi
298
299         printf 'pass\n'
300
301 fi
302
303 printf '\nAll %s tests passed.\n' "$d"
304
305 printf '\n%s\n' "$stars"