3 # SPDX-License-Identifier: BSD-2-Clause
5 # Copyright (c) 2018-2020 Gavin D. Howard and contributors.
7 # Redistribution and use in source and binary forms, with or without
8 # modification, are permitted provided that the following conditions are met:
10 # * Redistributions of source code must retain the above copyright notice, this
11 # list of conditions and the following disclaimer.
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.
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.
33 testdir=$(dirname "$script")
35 . "$testdir/../functions.sh"
37 if [ "$#" -ge 1 ]; then
41 err_exit "usage: $script dir [run_extra_tests] [run_stack_tests] [gen_tests] [time_tests] [exec args...]" 1
44 if [ "$#" -lt 1 ]; then
51 if [ "$#" -lt 1 ]; then
58 if [ "$#" -lt 1 ]; then
65 if [ "$#" -lt 1 ]; then
72 if [ "$#" -lt 1 ]; then
73 exe="$testdir/../bin/$d"
79 stars="***********************************************************************"
80 printf '%s\n' "$stars"
82 if [ "$d" = "bc" ]; then
93 printf '\nRunning %s tests...\n\n' "$d"
97 if [ "$extra" -eq 0 ]; then
98 if [ "$t" = "trunc" ] || [ "$t" = "places" ] || [ "$t" = "shift" ] || \
99 [ "$t" = "lib2" ] || [ "$t" = "scientific" ] || [ "$t" = "rand" ] || \
100 [ "$t" = "engineering" ]
102 printf 'Skipping %s %s\n' "$d" "$t"
107 sh "$testdir/test.sh" "$d" "$t" "$generate_tests" "$time_tests" "$exe" "$@"
109 done < "$testdir/$d/all.txt"
111 sh "$testdir/stdin.sh" "$d" "$exe" "$@"
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" "$@"
117 num=100000000000000000000000000000000000000000000000000000000000000000000000000000
119 num70="10000000000000000000000000000000000000000000000000000000000000000000\\
122 if [ "$d" = "bc" ]; then
125 lopt="extended-register"
126 line_var="BC_LINE_LENGTH"
131 line_var="DC_LINE_LENGTH"
135 printf '\nRunning %s quit test...' "$d"
137 printf '%s\n' "$halt" | "$exe" "$@" > /dev/null 2>&1
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
149 base=$(basename "$exe")
151 if [ "$base" != "bc" -a "$base" != "dc" ]; then
155 printf 'Running %s environment var tests...' "$d"
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
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
171 out1="$testdir/../.log_$d.txt"
172 out2="$testdir/../.log_${d}_test.txt"
174 printf 'Running %s line length tests...' "$d"
176 printf '%s\n' "$numres" > "$out1"
178 export "$line_var"=80
179 printf '%s\n' "$num" | "$exe" "$@" > "$out2"
183 printf '%s\n' "$num70" > "$out1"
185 export "$line_var"=2147483647
186 printf '%s\n' "$num" | "$exe" "$@" > "$out2"
192 printf 'Running %s arg tests...' "$d"
194 f="$testdir/$d/add.txt"
196 results=$(cat "$testdir/$d/add_results.txt")
198 printf '%s\n%s\n%s\n%s\n' "$results" "$results" "$results" "$results" > "$out1"
200 "$exe" "$@" -e "$exprs" -f "$f" --expression "$exprs" --file "$f" -e "$halt" > "$out2"
204 printf '%s\n' "$halt" | "$exe" "$@" -- "$f" "$f" "$f" "$f" > "$out2"
208 if [ "$d" = "bc" ]; then
209 printf '%s\n' "$halt" | "$exe" "$@" -i > /dev/null 2>&1
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
219 "$exe" "$@" -f "saotehasotnehasthistohntnsahxstnhalcrgxgrlpyasxtsaosysxsatnhoy.txt" > /dev/null 2> "$out2"
222 checktest "$d" "$err" "invalid file argument" "$out2" "$d"
224 "$exe" "$@" "-$opt" -e "$exprs" > /dev/null 2> "$out2"
227 checktest "$d" "$err" "invalid option argument" "$out2" "$d"
229 "$exe" "$@" "--$lopt" -e "$exprs" > /dev/null 2> "$out2"
232 checktest "$d" "$err" "invalid long option argument" "$out2" "$d"
234 "$exe" "$@" "-u" -e "$exprs" > /dev/null 2> "$out2"
237 checktest "$d" "$err" "unrecognized option argument" "$out2" "$d"
239 "$exe" "$@" "--uniform" -e "$exprs" > /dev/null 2> "$out2"
242 checktest "$d" "$err" "unrecognized long option argument" "$out2" "$d"
244 "$exe" "$@" -f > /dev/null 2> "$out2"
247 checktest "$d" "$err" "missing required argument to short option" "$out2" "$d"
249 "$exe" "$@" --file > /dev/null 2> "$out2"
252 checktest "$d" "$err" "missing required argument to long option" "$out2" "$d"
254 "$exe" "$@" --version=5 > /dev/null 2> "$out2"
257 checktest "$d" "$err" "given argument to long option with no argument" "$out2" "$d"
261 printf 'Running %s directory test...' "$d"
263 "$exe" "$@" "$testdir" > /dev/null 2> "$out2"
266 checktest "$d" "$err" "directory" "$out2" "$d"
270 printf 'Running %s binary file test...' "$d"
274 "$exe" "$@" "$bin" > /dev/null 2> "$out2"
277 checktest "$d" "$err" "binary file" "$out2" "$d"
281 printf 'Running %s binary stdin test...' "$d"
283 cat "$bin" | "$exe" "$@" > /dev/null 2> "$out2"
286 checktest "$d" "$err" "binary stdin" "$out2" "$d"
290 if [ "$d" = "bc" ]; then
292 printf 'Running %s limits tests...' "$d"
293 printf 'limits\n' | "$exe" "$@" > "$out2" /dev/null 2>&1
295 if [ ! -s "$out2" ]; then
296 err_exit "$d did not produce output on the limits test" 1
303 printf '\nAll %s tests passed.\n' "$d"
305 printf '\n%s\n' "$stars"