1#! /bin/sh 2# 3# SPDX-License-Identifier: BSD-2-Clause 4# 5# Copyright (c) 2018-2023 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 30script="$0" 31testdir=$(dirname "$script") 32 33. "$testdir/../scripts/functions.sh" 34 35# We need to figure out if we should run stuff in parallel. 36pll=1 37 38while getopts "n" opt; do 39 40 case "$opt" in 41 n) pll=0 ; shift ; set -e ;; 42 ?) usage "Invalid option: $opt" ;; 43 esac 44 45done 46 47# Command-line processing. 48if [ "$#" -ge 1 ]; then 49 d="$1" 50 shift 51else 52 err_exit "usage: $script [-n] dir [run_extra_tests] [run_stack_tests] [gen_tests] [run_problematic_tests] [time_tests] [exec args...]" 1 53fi 54 55if [ "$#" -lt 1 ]; then 56 extra=1 57else 58 extra="$1" 59 shift 60fi 61 62if [ "$#" -lt 1 ]; then 63 run_stack_tests=1 64else 65 run_stack_tests="$1" 66 shift 67fi 68 69if [ "$#" -lt 1 ]; then 70 generate_tests=1 71else 72 generate_tests="$1" 73 shift 74fi 75 76if [ "$#" -lt 1 ]; then 77 problematic_tests=1 78else 79 problematic_tests="$1" 80 shift 81fi 82 83if [ "$#" -lt 1 ]; then 84 time_tests=0 85else 86 time_tests="$1" 87 shift 88fi 89 90if [ "$#" -lt 1 ]; then 91 exe="$testdir/../bin/$d" 92else 93 exe="$1" 94 shift 95fi 96 97stars="***********************************************************************" 98printf '%s\n' "$stars" 99 100# Set stuff for the correct calculator. 101if [ "$d" = "bc" ]; then 102 halt="quit" 103else 104 halt="q" 105fi 106 107# I use these, so unset them to make the tests work. 108unset BC_ENV_ARGS 109unset BC_LINE_LENGTH 110unset DC_ENV_ARGS 111unset DC_LINE_LENGTH 112 113# Get the list of tests that require extra math. 114extra_required=$(cat "$testdir/extra_required.txt") 115 116pids="" 117 118printf '\nRunning %s tests...\n\n' "$d" 119 120# Run the tests one at a time. 121while read t; do 122 123 # If it requires extra, then skip if we don't have it. 124 if [ "$extra" -eq 0 ]; then 125 if [ -z "${extra_required##*$t*}" ]; then 126 printf 'Skipping %s %s\n' "$d" "$t" 127 continue 128 fi 129 fi 130 131 if [ "$pll" -ne 0 ]; then 132 sh "$testdir/test.sh" "$d" "$t" "$generate_tests" "$time_tests" "$exe" "$@" & 133 pids="$pids $!" 134 else 135 sh "$testdir/test.sh" "$d" "$t" "$generate_tests" "$time_tests" "$exe" "$@" 136 fi 137 138done < "$testdir/$d/all.txt" 139 140# stdin tests. 141if [ "$pll" -ne 0 ]; then 142 sh "$testdir/stdin.sh" "$d" "$exe" "$@" & 143 pids="$pids $!" 144else 145 sh "$testdir/stdin.sh" "$d" "$exe" "$@" 146fi 147 148# Script tests. 149if [ "$pll" -ne 0 ]; then 150 sh "$testdir/scripts.sh" "$d" "$extra" "$run_stack_tests" "$generate_tests" \ 151 "$time_tests" "$exe" "$@" & 152 pids="$pids $!" 153else 154 sh "$testdir/scripts.sh" -n "$d" "$extra" "$run_stack_tests" "$generate_tests" \ 155 "$time_tests" "$exe" "$@" 156fi 157 158# Read tests. 159if [ "$pll" -ne 0 ]; then 160 sh "$testdir/read.sh" "$d" "$exe" "$@" & 161 pids="$pids $!" 162else 163 sh "$testdir/read.sh" "$d" "$exe" "$@" 164fi 165 166# Error tests. 167if [ "$pll" -ne 0 ]; then 168 sh "$testdir/errors.sh" "$d" "$exe" "$@" & 169 pids="$pids $!" 170else 171 sh "$testdir/errors.sh" "$d" "$exe" "$@" 172fi 173 174# Test all the files in the errors directory. While the other error test (in 175# tests/errors.sh) does a test for every line, this does one test per file, but 176# it runs the file through stdin and as a file on the command-line. 177for testfile in $testdir/$d/errors/*.txt; do 178 179 b=$(basename "$testfile") 180 181 if [ "$pll" -ne 0 ]; then 182 sh "$testdir/error.sh" "$d" "$b" "$problematic_tests" "$@" & 183 pids="$pids $!" 184 else 185 sh "$testdir/error.sh" "$d" "$b" "$problematic_tests" "$@" 186 fi 187 188done 189 190# Other tests. 191if [ "$pll" -ne 0 ]; then 192 sh "$testdir/other.sh" "$d" "$extra" "$exe" "$@" & 193 pids="$pids $!" 194else 195 sh "$testdir/other.sh" "$d" "$extra" "$exe" "$@" 196fi 197 198if [ "$pll" -ne 0 ]; then 199 200 exit_err=0 201 202 for p in $pids; do 203 204 wait "$p" 205 err="$?" 206 207 if [ "$err" -ne 0 ]; then 208 printf 'A test failed!\n' 209 exit_err=1 210 fi 211 done 212 213 if [ "$exit_err" -ne 0 ]; then 214 exit 1 215 fi 216 217fi 218 219printf '\nAll %s tests passed.\n' "$d" 220 221printf '\n%s\n' "$stars" 222