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 30# WARNING: Test files cannot have empty lines! 31 32script="$0" 33testdir=$(dirname "$script") 34 35. "$testdir/../functions.sh" 36 37if [ "$#" -eq 0 ]; then 38 printf 'usage: %s dir [exec args...]\n' "$script" 39 exit 1 40else 41 d="$1" 42 shift 43fi 44 45if [ "$#" -lt 1 ]; then 46 exe="$testdir/../bin/$d" 47else 48 exe="$1" 49 shift 50fi 51 52unset BC_ENV_ARGS 53unset BC_LINE_LENGTH 54unset DC_ENV_ARGS 55unset DC_LINE_LENGTH 56 57out="$testdir/${d}_outputs/errors_results.txt" 58outdir=$(dirname "$out") 59 60if [ ! -d "$outdir" ]; then 61 mkdir -p "$outdir" 62fi 63 64exebase=$(basename "$exe") 65 66posix="posix_errors" 67read_errors="read_errors" 68 69if [ "$d" = "bc" ]; then 70 opts="-l" 71 halt="halt" 72 read_call="read()" 73 read_expr="${read_call}\n5+5;" 74else 75 opts="-x" 76 halt="q" 77fi 78 79for testfile in $testdir/$d/*errors.txt; do 80 81 if [ -z "${testfile##*$read_errors*}" ]; then 82 # We don't test read errors here. Skip. 83 continue 84 fi 85 86 if [ -z "${testfile##*$posix*}" ]; then 87 88 line="last" 89 printf '%s\n' "$line" | "$exe" "$@" "-lw" 2> "$out" > /dev/null 90 err="$?" 91 92 if [ "$err" -ne 0 ]; then 93 die "$d" "returned an error ($err)" "POSIX warning" 1 94 fi 95 96 checkerrtest "$d" "1" "$line" "$out" "$exebase" 97 98 options="-ls" 99 else 100 options="$opts" 101 fi 102 103 base=$(basename "$testfile") 104 base="${base%.*}" 105 printf 'Running %s %s...' "$d" "$base" 106 107 while read -r line; do 108 109 rm -f "$out" 110 111 printf '%s\n' "$line" | "$exe" "$@" "$options" 2> "$out" > /dev/null 112 err="$?" 113 114 checkerrtest "$d" "$err" "$line" "$out" "$exebase" 115 116 done < "$testfile" 117 118 printf 'pass\n' 119 120done 121 122for testfile in $testdir/$d/errors/*.txt; do 123 124 printf 'Running %s error file %s...' "$d" "$testfile" 125 126 printf '%s\n' "$halt" | "$exe" "$@" $opts "$testfile" 2> "$out" > /dev/null 127 err="$?" 128 129 checkerrtest "$d" "$err" "$testfile" "$out" "$exebase" 130 131 printf 'pass\n' 132 133 printf 'Running %s error file %s through cat...' "$d" "$testfile" 134 135 cat "$testfile" | "$exe" "$@" $opts 2> "$out" > /dev/null 136 err="$?" 137 138 checkcrash "$d" "$err" "$testfile" 139 140 printf 'pass\n' 141 142done 143