Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/freebsd-src
Path: blob/main/contrib/bc/tests/error.sh
39507 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
outputdir=${BC_TEST_OUTPUT_DIR:-$testdir}
36
37
# Just print the usage and exit with an error. This can receive a message to
38
# print.
39
# @param 1 A message to print.
40
usage() {
41
if [ $# -eq 1 ]; then
42
printf '%s\n\n' "$1"
43
fi
44
printf 'usage: %s dir test problematic_tests [exec args...]\n' "$script"
45
exit 1
46
}
47
48
# Command-line processing.
49
if [ "$#" -lt 3 ]; then
50
usage "Not enough arguments"
51
else
52
53
d="$1"
54
shift
55
check_d_arg "$d"
56
57
t="$1"
58
shift
59
60
problematic="$1"
61
shift
62
check_bool_arg "$problematic"
63
64
fi
65
66
testfile="$testdir/$d/errors/$t"
67
check_file_arg "$testfile"
68
69
if [ "$#" -lt 1 ]; then
70
exe="$testdir/../bin/$d"
71
else
72
exe="$1"
73
shift
74
fi
75
76
# Just skip tests that are problematic on FreeBSD. These tests can cause FreeBSD
77
# to kill bc from memory exhaustion because of overcommit.
78
if [ "$d" = "bc" ] && [ "$problematic" -eq 0 ]; then
79
if [ "$t" = "33.txt" ]; then
80
printf 'Skipping problematic %s error file %s...\n' "$d" "$t"
81
exit 0
82
fi
83
fi
84
85
# I use these, so unset them to make the tests work.
86
unset BC_ENV_ARGS
87
unset BC_LINE_LENGTH
88
unset DC_ENV_ARGS
89
unset DC_LINE_LENGTH
90
91
out="$outputdir/${d}_outputs/error_results_${t}"
92
outdir=$(dirname "$out")
93
94
# Make sure the directory exists.
95
if [ ! -d "$outdir" ]; then
96
mkdir -p "$outdir"
97
fi
98
99
# Set stuff for the correct calculator.
100
if [ "$d" = "bc" ]; then
101
opts="-l"
102
halt="halt"
103
else
104
opts="-x"
105
halt="q"
106
fi
107
108
printf 'Running %s error file %s with clamping...' "$d" "$t"
109
110
printf '%s\n' "$halt" 2> /dev/null | "$exe" "$@" $opts -c "$testfile" 2> "$out" > /dev/null
111
err="$?"
112
113
checkerrtest "$d" "$err" "$testfile" "$out" "$exebase" > /dev/null
114
115
printf 'pass\n'
116
117
printf 'Running %s error file %s without clamping...' "$d" "$t"
118
119
printf '%s\n' "$halt" 2> /dev/null | "$exe" "$@" $opts -C "$testfile" 2> "$out" > /dev/null
120
err="$?"
121
122
checkerrtest "$d" "$err" "$testfile" "$out" "$exebase" > /dev/null
123
124
printf 'pass\n'
125
126
printf 'Running %s error file %s through cat with clamping...' "$d" "$t"
127
128
cat "$testfile" 2> /dev/null | "$exe" "$@" $opts -c 2> "$out" > /dev/null
129
err="$?"
130
131
checkerrtest "$d" "$err" "$testfile" "$out" "$exebase"
132
133
printf 'pass\n'
134
135
printf 'Running %s error file %s through cat without clamping...' "$d" "$t"
136
137
cat "$testfile" 2> /dev/null | "$exe" "$@" $opts -C 2> "$out" > /dev/null
138
err="$?"
139
140
checkerrtest "$d" "$err" "$testfile" "$out" "$exebase"
141
142
printf 'pass\n'
143
144