#! /bin/sh1#2# SPDX-License-Identifier: BSD-2-Clause3#4# Copyright (c) 2018-2025 Gavin D. Howard and contributors.5#6# Redistribution and use in source and binary forms, with or without7# modification, are permitted provided that the following conditions are met:8#9# * Redistributions of source code must retain the above copyright notice, this10# list of conditions and the following disclaimer.11#12# * Redistributions in binary form must reproduce the above copyright notice,13# this list of conditions and the following disclaimer in the documentation14# and/or other materials provided with the distribution.15#16# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"17# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE18# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE19# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE20# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR21# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF22# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS23# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN24# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)25# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE26# POSSIBILITY OF SUCH DAMAGE.27#2829set -e3031script="$0"3233testdir=$(dirname "$script")3435. "$testdir/../scripts/functions.sh"3637outputdir=${BC_TEST_OUTPUT_DIR:-$testdir}3839# Just print the usage and exit with an error. This can receive a message to40# print.41# @param 1 A message to print.42usage() {43if [ $# -eq 1 ]; then44printf '%s\n\n' "$1"45fi46printf 'usage: %s dir [exe [args...]]\n' "$0"47printf 'valid dirs are:\n'48printf '\n'49cat "$testdir/all.txt"50printf '\n'51exit 152}5354# Command-line processing.55if [ "$#" -lt 1 ]; then56usage "Not enough arguments"57fi5859d="$1"60shift61check_d_arg "$d"6263if [ "$#" -gt 0 ]; then64exe="$1"65shift66check_exec_arg "$exe"67else68exe="$testdir/../bin/$d"69check_exec_arg "$exe"70fi7172out="$outputdir/${d}_outputs/stdin_results.txt"73outdir=$(dirname "$out")7475# Make sure the directory exists.76if [ ! -d "$outdir" ]; then77mkdir -p "$outdir"78fi7980# Set stuff for the correct calculator.81if [ "$d" = "bc" ]; then82options="-lq"83else84options="-x"85fi8687rm -f "$out"8889# I use these, so unset them to make the tests work.90unset BC_ENV_ARGS91unset BC_LINE_LENGTH92unset DC_ENV_ARGS93unset DC_LINE_LENGTH9495set +e9697printf 'Running %s stdin tests...' "$d"9899# Run the file through stdin.100cat "$testdir/$d/stdin.txt" | "$exe" "$@" "$options" > "$out" 2> /dev/null101checktest "$d" "$?" "stdin" "$testdir/$d/stdin_results.txt" "$out"102103# bc has some more tests; run those.104if [ "$d" = "bc" ]; then105106cat "$testdir/$d/stdin1.txt" | "$exe" "$@" "$options" > "$out" 2> /dev/null107checktest "$d" "$?" "stdin1" "$testdir/$d/stdin1_results.txt" "$out"108109cat "$testdir/$d/stdin2.txt" | "$exe" "$@" "$options" > "$out" 2> /dev/null110checktest "$d" "$?" "stdin2" "$testdir/$d/stdin2_results.txt" "$out"111fi112113rm -f "$out"114115exec printf 'pass\n'116117118