Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/freebsd-src
Path: blob/main/contrib/bc/tests/stdin.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
set -e
31
32
script="$0"
33
34
testdir=$(dirname "$script")
35
36
. "$testdir/../scripts/functions.sh"
37
38
outputdir=${BC_TEST_OUTPUT_DIR:-$testdir}
39
40
# Just print the usage and exit with an error. This can receive a message to
41
# print.
42
# @param 1 A message to print.
43
usage() {
44
if [ $# -eq 1 ]; then
45
printf '%s\n\n' "$1"
46
fi
47
printf 'usage: %s dir [exe [args...]]\n' "$0"
48
printf 'valid dirs are:\n'
49
printf '\n'
50
cat "$testdir/all.txt"
51
printf '\n'
52
exit 1
53
}
54
55
# Command-line processing.
56
if [ "$#" -lt 1 ]; then
57
usage "Not enough arguments"
58
fi
59
60
d="$1"
61
shift
62
check_d_arg "$d"
63
64
if [ "$#" -gt 0 ]; then
65
exe="$1"
66
shift
67
check_exec_arg "$exe"
68
else
69
exe="$testdir/../bin/$d"
70
check_exec_arg "$exe"
71
fi
72
73
out="$outputdir/${d}_outputs/stdin_results.txt"
74
outdir=$(dirname "$out")
75
76
# Make sure the directory exists.
77
if [ ! -d "$outdir" ]; then
78
mkdir -p "$outdir"
79
fi
80
81
# Set stuff for the correct calculator.
82
if [ "$d" = "bc" ]; then
83
options="-lq"
84
else
85
options="-x"
86
fi
87
88
rm -f "$out"
89
90
# I use these, so unset them to make the tests work.
91
unset BC_ENV_ARGS
92
unset BC_LINE_LENGTH
93
unset DC_ENV_ARGS
94
unset DC_LINE_LENGTH
95
96
set +e
97
98
printf 'Running %s stdin tests...' "$d"
99
100
# Run the file through stdin.
101
cat "$testdir/$d/stdin.txt" | "$exe" "$@" "$options" > "$out" 2> /dev/null
102
checktest "$d" "$?" "stdin" "$testdir/$d/stdin_results.txt" "$out"
103
104
# bc has some more tests; run those.
105
if [ "$d" = "bc" ]; then
106
107
cat "$testdir/$d/stdin1.txt" | "$exe" "$@" "$options" > "$out" 2> /dev/null
108
checktest "$d" "$?" "stdin1" "$testdir/$d/stdin1_results.txt" "$out"
109
110
cat "$testdir/$d/stdin2.txt" | "$exe" "$@" "$options" > "$out" 2> /dev/null
111
checktest "$d" "$?" "stdin2" "$testdir/$d/stdin2_results.txt" "$out"
112
fi
113
114
rm -f "$out"
115
116
exec printf 'pass\n'
117
118