1#! /bin/sh 2# 3# SPDX-License-Identifier: BSD-2-Clause 4# 5# Copyright (c) 2018-2021 Gavin D. Howard and contributors. 6# 7# Redistribution and use in source and binary forms, with or without 8# modification, are permitted provided that the following conditions are met: 9# 10# * Redistributions of source code must retain the above copyright notice, this 11# list of conditions and the following disclaimer. 12# 13# * Redistributions in binary form must reproduce the above copyright notice, 14# this list of conditions and the following disclaimer in the documentation 15# and/or other materials provided with the distribution. 16# 17# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 18# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 21# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 22# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 23# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 24# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 25# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 26# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 27# POSSIBILITY OF SUCH DAMAGE. 28# 29 30set -e 31 32script="$0" 33testdir=$(dirname "$script") 34 35. "$testdir/../scripts/functions.sh" 36 37# Command-line processing. 38if [ "$#" -ge 1 ]; then 39 d="$1" 40 shift 41else 42 err_exit "usage: $script dir [run_extra_tests] [run_stack_tests] [gen_tests] [time_tests] [exec args...]" 1 43fi 44 45if [ "$#" -lt 1 ]; then 46 extra=1 47else 48 extra="$1" 49 shift 50fi 51 52if [ "$#" -lt 1 ]; then 53 run_stack_tests=1 54else 55 run_stack_tests="$1" 56 shift 57fi 58 59if [ "$#" -lt 1 ]; then 60 generate_tests=1 61else 62 generate_tests="$1" 63 shift 64fi 65 66if [ "$#" -lt 1 ]; then 67 time_tests=0 68else 69 time_tests="$1" 70 shift 71fi 72 73if [ "$#" -lt 1 ]; then 74 exe="$testdir/../bin/$d" 75else 76 exe="$1" 77 shift 78fi 79 80stars="***********************************************************************" 81printf '%s\n' "$stars" 82 83# Set stuff for the correct calculator. 84if [ "$d" = "bc" ]; then 85 halt="quit" 86else 87 halt="q" 88fi 89 90# I use these, so unset them to make the tests work. 91unset BC_ENV_ARGS 92unset BC_LINE_LENGTH 93unset DC_ENV_ARGS 94unset DC_LINE_LENGTH 95 96# Get the list of tests that require extra math. 97extra_required=$(cat "$testdir/extra_required.txt") 98 99printf '\nRunning %s tests...\n\n' "$d" 100 101# Run the tests one at a time. 102while read t; do 103 104 # If it requires extra, then skip if we don't have it. 105 if [ "$extra" -eq 0 ]; then 106 if [ -z "${extra_required##*$t*}" ]; then 107 printf 'Skipping %s %s\n' "$d" "$t" 108 continue 109 fi 110 fi 111 112 sh "$testdir/test.sh" "$d" "$t" "$generate_tests" "$time_tests" "$exe" "$@" 113 114done < "$testdir/$d/all.txt" 115 116# stdin tests. 117sh "$testdir/stdin.sh" "$d" "$exe" "$@" 118 119# Script tests. 120sh "$testdir/scripts.sh" "$d" "$extra" "$run_stack_tests" "$generate_tests" \ 121 "$time_tests" "$exe" "$@" 122 123# Read tests. 124sh "$testdir/read.sh" "$d" "$exe" "$@" 125 126# Error tests. 127sh "$testdir/errors.sh" "$d" "$exe" "$@" 128 129# Other tests. 130sh "$testdir/other.sh" "$d" "$extra" "$exe" "$@" 131 132printf '\nAll %s tests passed.\n' "$d" 133 134printf '\n%s\n' "$stars" 135