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