diff options
Diffstat (limited to 'contrib/bc/tests/test.sh')
-rwxr-xr-x | contrib/bc/tests/test.sh | 39 |
1 files changed, 30 insertions, 9 deletions
diff --git a/contrib/bc/tests/test.sh b/contrib/bc/tests/test.sh index 9d557a715dc0..343705bf10a9 100755 --- a/contrib/bc/tests/test.sh +++ b/contrib/bc/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: @@ -37,19 +37,32 @@ testdir=$(dirname "$script") outputdir=${BC_TEST_OUTPUT_DIR:-$testdir} -# Command-line processing. -if [ "$#" -lt 2 ]; then +# 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" @@ -58,22 +71,28 @@ 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="$outputdir/${d}_outputs/${t}_results.txt" @@ -119,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 @@ -136,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 |