diff options
Diffstat (limited to 'tests/test.sh')
-rwxr-xr-x | tests/test.sh | 43 |
1 files changed, 33 insertions, 10 deletions
diff --git a/tests/test.sh b/tests/test.sh index ec7f6ba9..343705bf 100755 --- a/tests/test.sh +++ b/tests/test.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: @@ -35,19 +35,34 @@ testdir=$(dirname "$script") . "$testdir/../scripts/functions.sh" -# Command-line processing. -if [ "$#" -lt 2 ]; 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 test [generate_tests] [time_tests] [exe [args...]]\n' "$0" printf 'valid dirs are:\n' printf '\n' cat "$testdir/all.txt" printf '\n' exit 1 +} + +# Command-line processing. +if [ "$#" -lt 2 ]; then + usage "Need at least 2 arguments" fi d="$1" shift +check_d_arg "$d" +# We don't use check_file_arg on the test or the result because they might be +# generated. t="$1" name="$testdir/$d/$t.txt" results="$testdir/$d/${t}_results.txt" @@ -56,25 +71,31 @@ shift if [ "$#" -gt 0 ]; then generate_tests="$1" shift + check_bool_arg "$generate_tests" else generate_tests=1 + check_bool_arg "$generate_tests" fi if [ "$#" -gt 0 ]; then time_tests="$1" shift + check_bool_arg "$time_tests" else time_tests=0 + check_bool_arg "$time_tests" fi if [ "$#" -gt 0 ]; then exe="$1" shift + check_exec_arg "$exe" else exe="$testdir/../bin/$d" + check_exec_arg "$exe" fi -out="$testdir/${d}_outputs/${t}_results.txt" +out="$outputdir/${d}_outputs/${t}_results.txt" outdir=$(dirname "$out") # Make sure the directory exists. @@ -117,13 +138,15 @@ fi # If the results do not exist, generate.. if [ ! -f "$results" ]; then printf 'Generating %s %s results...' "$d" "$t" - printf '%s\n' "$halt" | "$d" $options "$name" > "$results" + printf '%s\n' "$halt" 2> /dev/null | "$d" $options "$name" > "$results" printf 'done\n' fi -# We set this here because GNU dc does not have it. -if [ "$d" = "dc" ]; then - options="-x" +# We set this here because GNU bc and dc does not have these options. +if [ "$d" = "bc" ]; then + options="-lqc" +else + options="-xc" fi export $var=string @@ -134,11 +157,11 @@ printf 'Running %s %s...' "$d" "$t" if [ "$time_tests" -ne 0 ]; then printf '\n' - printf '%s\n' "$halt" | /usr/bin/time -p "$exe" "$@" $options "$name" > "$out" + printf '%s\n' "$halt" 2> /dev/null | /usr/bin/time -p "$exe" "$@" $options "$name" > "$out" err="$?" printf '\n' else - printf '%s\n' "$halt" | "$exe" "$@" $options "$name" > "$out" + printf '%s\n' "$halt" 2> /dev/null | "$exe" "$@" $options "$name" > "$out" err="$?" fi |