Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/freebsd-src
Path: blob/main/contrib/bc/tests/all.sh
39536 views
1
#! /bin/sh
2
#
3
# SPDX-License-Identifier: BSD-2-Clause
4
#
5
# Copyright (c) 2018-2025 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
script="$0"
31
testdir=$(dirname "$script")
32
33
. "$testdir/../scripts/functions.sh"
34
35
# Just print the usage and exit with an error. This can receive a message to
36
# print.
37
# @param 1 A message to print.
38
usage() {
39
if [ $# -eq 1 ]; then
40
printf '%s\n\n' "$1"
41
fi
42
print 'usage: %s [-n] dir [run_extra_tests] [run_stack_tests] [gen_tests] [run_problematic_tests] [exec args...]\n' \
43
"$script"
44
exit 1
45
}
46
47
# We need to figure out if we should run stuff in parallel.
48
pll=1
49
50
while getopts "n" opt; do
51
52
case "$opt" in
53
n) pll=0 ; set -e ;;
54
?) usage "Invalid option: $opt" ;;
55
esac
56
57
done
58
shift $(($OPTIND - 1))
59
60
# Command-line processing.
61
if [ "$#" -ge 1 ]; then
62
d="$1"
63
shift
64
check_d_arg "$d"
65
else
66
usage "Not enough arguments"
67
fi
68
69
if [ "$#" -lt 1 ]; then
70
extra=1
71
check_bool_arg "$extra"
72
else
73
extra="$1"
74
shift
75
check_bool_arg "$extra"
76
fi
77
78
if [ "$#" -lt 1 ]; then
79
run_stack_tests=1
80
check_bool_arg "$run_stack_tests"
81
else
82
run_stack_tests="$1"
83
shift
84
check_bool_arg "$run_stack_tests"
85
fi
86
87
if [ "$#" -lt 1 ]; then
88
generate_tests=1
89
check_bool_arg "$generate_tests"
90
else
91
generate_tests="$1"
92
shift
93
check_bool_arg "$generate_tests"
94
fi
95
96
if [ "$#" -lt 1 ]; then
97
problematic_tests=1
98
check_bool_arg "$problematic_tests"
99
else
100
problematic_tests="$1"
101
shift
102
check_bool_arg "$problematic_tests"
103
fi
104
105
if [ "$#" -lt 1 ]; then
106
exe="$testdir/../bin/$d"
107
check_exec_arg "$exe"
108
else
109
exe="$1"
110
shift
111
check_exec_arg "$exe"
112
fi
113
114
stars="***********************************************************************"
115
printf '%s\n' "$stars"
116
117
# Set stuff for the correct calculator.
118
if [ "$d" = "bc" ]; then
119
halt="quit"
120
else
121
halt="q"
122
fi
123
124
# I use these, so unset them to make the tests work.
125
unset BC_ENV_ARGS
126
unset BC_LINE_LENGTH
127
unset DC_ENV_ARGS
128
unset DC_LINE_LENGTH
129
130
# Get the list of tests that require extra math.
131
extra_required=$(cat "$testdir/extra_required.txt")
132
133
pids=""
134
135
printf '\nRunning %s tests...\n\n' "$d"
136
137
# Run the tests one at a time.
138
while read t; do
139
140
# If it requires extra, then skip if we don't have it.
141
if [ "$extra" -eq 0 ]; then
142
if [ -z "${extra_required##*$t*}" ]; then
143
printf 'Skipping %s %s\n' "$d" "$t"
144
continue
145
fi
146
fi
147
148
if [ "$pll" -ne 0 ]; then
149
sh "$testdir/test.sh" "$d" "$t" "$generate_tests" "$exe" "$@" &
150
pids="$pids $!"
151
else
152
sh "$testdir/test.sh" "$d" "$t" "$generate_tests" "$exe" "$@"
153
fi
154
155
done < "$testdir/$d/all.txt"
156
157
# stdin tests.
158
if [ "$pll" -ne 0 ]; then
159
sh "$testdir/stdin.sh" "$d" "$exe" "$@" &
160
pids="$pids $!"
161
else
162
sh "$testdir/stdin.sh" "$d" "$exe" "$@"
163
fi
164
165
# Script tests.
166
if [ "$pll" -ne 0 ]; then
167
sh "$testdir/scripts.sh" "$d" "$extra" "$run_stack_tests" "$generate_tests" \
168
"$exe" "$@" &
169
pids="$pids $!"
170
else
171
sh "$testdir/scripts.sh" -n "$d" "$extra" "$run_stack_tests" "$generate_tests" \
172
"$exe" "$@"
173
fi
174
175
# Error tests.
176
if [ "$pll" -ne 0 ]; then
177
sh "$testdir/errors.sh" "$d" "$exe" "$@" &
178
pids="$pids $!"
179
else
180
sh "$testdir/errors.sh" "$d" "$exe" "$@"
181
fi
182
183
# Test all the files in the errors directory. While the other error test (in
184
# tests/errors.sh) does a test for every line of certain error files in the main
185
# directory, this does one test per file in the errors directory, but it runs
186
# the file through stdin and as a file on the command-line.
187
for testfile in $testdir/$d/errors/*.txt; do
188
189
b=$(basename "$testfile")
190
191
if [ "$pll" -ne 0 ]; then
192
sh "$testdir/error.sh" "$d" "$b" "$problematic_tests" "$@" &
193
pids="$pids $!"
194
else
195
sh "$testdir/error.sh" "$d" "$b" "$problematic_tests" "$@"
196
fi
197
198
done
199
200
if [ "$pll" -ne 0 ]; then
201
202
exit_err=0
203
204
for p in $pids; do
205
206
wait "$p"
207
err="$?"
208
209
if [ "$err" -ne 0 ]; then
210
printf 'A test failed!\n'
211
exit_err=1
212
fi
213
done
214
215
if [ "$exit_err" -ne 0 ]; then
216
exit 1
217
fi
218
219
fi
220
221
printf '\nAll %s tests passed.\n' "$d"
222
223
printf '\n%s\n' "$stars"
224
225