diff options
Diffstat (limited to 'tests/errors.sh')
-rwxr-xr-x | tests/errors.sh | 78 |
1 files changed, 23 insertions, 55 deletions
diff --git a/tests/errors.sh b/tests/errors.sh index d6c120aa..081beb72 100755 --- a/tests/errors.sh +++ b/tests/errors.sh @@ -2,7 +2,7 @@ # # SPDX-License-Identifier: BSD-2-Clause # -# Copyright (c) 2018-2021 Gavin D. Howard and contributors. +# Copyright (c) 2018-2023 Gavin D. Howard and contributors. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions are met: @@ -34,20 +34,35 @@ testdir=$(dirname "$script") . "$testdir/../scripts/functions.sh" -# Command-line processing. -if [ "$#" -eq 0 ]; then +outputdir=${BC_TEST_OUTPUT_DIR:-$testdir} + +# Just print the usage and exit with an error. This can receive a message to +# print. +# @param 1 A message to print. +usage() { + if [ $# -eq 1 ]; then + printf '%s\n\n' "$1" + fi printf 'usage: %s dir [exec args...]\n' "$script" exit 1 +} + +# Command-line processing. +if [ "$#" -eq 0 ]; then + usage "Not enough arguments" else d="$1" shift + check_d_arg "$d" fi if [ "$#" -lt 1 ]; then exe="$testdir/../bin/$d" + check_exec_arg "$exe" else exe="$1" shift + check_exec_arg "$exe" fi # I use these, so unset them to make the tests work. @@ -56,7 +71,7 @@ unset BC_LINE_LENGTH unset DC_ENV_ARGS unset DC_LINE_LENGTH -out="$testdir/${d}_outputs/errors_results.txt" +out="$outputdir/${d}_outputs/errors_results.txt" outdir=$(dirname "$out") # Make sure the directory exists. @@ -83,12 +98,12 @@ fi printf 'Running %s command-line error tests...' "$d" -printf '%s\n' "$halt" | "$exe" "$@" -e "1+1" -f- -e "2+2" 2> "$out" > /dev/null +printf '%s\n' "$halt" 2> /dev/null | "$exe" "$@" -e "1+1" -f- -e "2+2" 2> "$out" > /dev/null err="$?" checkerrtest "$d" "$err" "command-line -e test" "$out" "$exebase" -printf '%s\n' "$halt" | "$exe" "$@" -e "1+1" -f- -f "$testdir/$d/decimal.txt" 2> "$out" > /dev/null +printf '%s\n' "$halt" 2> /dev/null | "$exe" "$@" -e "1+1" -f- -f "$testdir/$d/decimal.txt" 2> "$out" > /dev/null err="$?" checkerrtest "$d" "$err" "command-line -f test" "$out" "$exebase" @@ -108,7 +123,7 @@ for testfile in $testdir/$d/*errors.txt; do # Just test warnings. line="last" - printf '%s\n' "$line" | "$exe" "$@" "-lw" 2> "$out" > /dev/null + printf '%s\n' "$line" 2> /dev/null | "$exe" "$@" "-lw" 2> "$out" > /dev/null err="$?" if [ "$err" -ne 0 ]; then @@ -135,7 +150,7 @@ for testfile in $testdir/$d/*errors.txt; do rm -f "$out" - printf '%s\n' "$line" | "$exe" "$@" "$options" 2> "$out" > /dev/null + printf '%s\n' "$line" 2> /dev/null | "$exe" "$@" "$options" 2> "$out" > /dev/null err="$?" checkerrtest "$d" "$err" "$line" "$out" "$exebase" @@ -145,50 +160,3 @@ for testfile in $testdir/$d/*errors.txt; do printf 'pass\n' done - -# I need to skip a test here on FreeBSD. -os=$(uname) - -# The list of files we need to skip. -skip_files=" -33.txt -" - -# Test all the files in the errors directory. While the loop above does one test -# for every line, this does one test per file, but it runs the file through -# stdin and as a file on the command-line. -for testfile in $testdir/$d/errors/*.txt; do - - # If we are on FreeBSD... - if [ "$os" = "FreeBSD" ] && [ "$d" = "dc" ]; then - - b=$(basename "$testfile") - - # If the file is one of the skip files... - if [ -z "${skip_files##*$b*}" ]; then - - printf 'On FreeBSD; skipping %s...\n' "$testfile" - continue - - fi - fi - - printf 'Running %s error file %s...' "$d" "$testfile" - - printf '%s\n' "$halt" | "$exe" "$@" $opts "$testfile" 2> "$out" > /dev/null - err="$?" - - checkerrtest "$d" "$err" "$testfile" "$out" "$exebase" - - printf 'pass\n' - - printf 'Running %s error file %s through cat...' "$d" "$testfile" - - cat "$testfile" | "$exe" "$@" $opts 2> "$out" > /dev/null - err="$?" - - checkcrash "$d" "$err" "$testfile" - - printf 'pass\n' - -done |