#! /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#2829script="$0"30testdir=$(dirname "$script")3132. "$testdir/../scripts/functions.sh"3334outputdir=${BC_TEST_OUTPUT_DIR:-$testdir}3536# Just print the usage and exit with an error. This can receive a message to37# print.38# @param 1 A message to print.39usage() {40if [ $# -eq 1 ]; then41printf '%s\n\n' "$1"42fi43printf 'usage: %s dir test problematic_tests [exec args...]\n' "$script"44exit 145}4647# Command-line processing.48if [ "$#" -lt 3 ]; then49usage "Not enough arguments"50else5152d="$1"53shift54check_d_arg "$d"5556t="$1"57shift5859problematic="$1"60shift61check_bool_arg "$problematic"6263fi6465testfile="$testdir/$d/errors/$t"66check_file_arg "$testfile"6768if [ "$#" -lt 1 ]; then69exe="$testdir/../bin/$d"70else71exe="$1"72shift73fi7475# Just skip tests that are problematic on FreeBSD. These tests can cause FreeBSD76# to kill bc from memory exhaustion because of overcommit.77if [ "$d" = "bc" ] && [ "$problematic" -eq 0 ]; then78if [ "$t" = "33.txt" ]; then79printf 'Skipping problematic %s error file %s...\n' "$d" "$t"80exit 081fi82fi8384# I use these, so unset them to make the tests work.85unset BC_ENV_ARGS86unset BC_LINE_LENGTH87unset DC_ENV_ARGS88unset DC_LINE_LENGTH8990out="$outputdir/${d}_outputs/error_results_${t}"91outdir=$(dirname "$out")9293# Make sure the directory exists.94if [ ! -d "$outdir" ]; then95mkdir -p "$outdir"96fi9798# Set stuff for the correct calculator.99if [ "$d" = "bc" ]; then100opts="-l"101halt="halt"102else103opts="-x"104halt="q"105fi106107printf 'Running %s error file %s with clamping...' "$d" "$t"108109printf '%s\n' "$halt" 2> /dev/null | "$exe" "$@" $opts -c "$testfile" 2> "$out" > /dev/null110err="$?"111112checkerrtest "$d" "$err" "$testfile" "$out" "$exebase" > /dev/null113114printf 'pass\n'115116printf 'Running %s error file %s without clamping...' "$d" "$t"117118printf '%s\n' "$halt" 2> /dev/null | "$exe" "$@" $opts -C "$testfile" 2> "$out" > /dev/null119err="$?"120121checkerrtest "$d" "$err" "$testfile" "$out" "$exebase" > /dev/null122123printf 'pass\n'124125printf 'Running %s error file %s through cat with clamping...' "$d" "$t"126127cat "$testfile" 2> /dev/null | "$exe" "$@" $opts -c 2> "$out" > /dev/null128err="$?"129130checkerrtest "$d" "$err" "$testfile" "$out" "$exebase"131132printf 'pass\n'133134printf 'Running %s error file %s through cat without clamping...' "$d" "$t"135136cat "$testfile" 2> /dev/null | "$exe" "$@" $opts -C 2> "$out" > /dev/null137err="$?"138139checkerrtest "$d" "$err" "$testfile" "$out" "$exebase"140141printf 'pass\n'142143144