File: run_test.sh

package info (click to toggle)
tapecalc 20230205-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 1,172 kB
  • sloc: sh: 3,582; ansic: 2,470; makefile: 103
file content (100 lines) | stat: -rwxr-xr-x 1,760 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#!/bin/sh
# $Id: run_test.sh,v 1.15 2022/11/04 21:45:18 tom Exp $
# regression script for 'add'
if test $# = 0
then
	eval "$0" ./*.add
	exit
fi
#
: "${EXECUTABLE:=../add}"
: "${PROGRAM:=add}"
#
CASE64=`file "$EXECUTABLE" 2>/dev/null | grep 64-bit`
#
LINES=24;export LINES
COLS=80;export COLS
rm -f un*ble
touch unwritable unreadable
chmod 444 unwritable
chmod 000 unreadable
trap "rm -f un*ble" EXIT INT QUIT HUP TERM
#
# test references are for POSIX locale...
unset LANG
unset LC_ALL
unset LC_CTYPE
#
EXIT=0
for i in "$@"
do
	I=`basename "$i" .add`
	NUL=/dev/null
	OUT="$I.out"
	ERR="$I.err"
	REF="$I.ref"
	TMP="$I.tmp"
	OPT=""
	if test -n "$CASE64"
	then
		test -f "$I-64.ref" && REF="$I-64.ref"
	fi
	if test -f "$I".opt
	then
		OPT=`cat "$I".opt`
	fi
	rm -f "$OUT" "$ERR" "$TMP"
	# Build a script that's guaranteed to write an output. Some curses
	# implementations don't allow us to simply pipe to the application.
	cp "$I".add "$TMP"
	chmod 644 "$TMP"
	echo ':w' >>"$TMP"
	echo 'Q'  >>"$TMP"

	"$EXECUTABLE" $OPT -o "$OUT" "$TMP" >"$NUL" 2>"$ERR"

	if test -s "$ERR"; then
		sed -e "s/: \<$PROGRAM\>/: add/" "$ERR" >"$TMP"
		mv "$TMP" "$ERR"
	fi
	rm -f "$TMP"

	if test -s "$ERR"
	then
		if ( grep 'Electric Fence' "$ERR" >/dev/null )
		then
			sed -e '1,/Electric Fence/d' \
				| tr '\007' @ \
				| sed -e 's/@//g' <"$ERR" \
				>>"$OUT"
		else
			tr '\007' @ <"$ERR" \
				| sed -e 's/@//g' \
				>>"$OUT"
		fi
	fi
	rm -f "$ERR"

	if test -f "$OUT"
	then
		if test -f "$REF"
		then
			if ( cmp -s "$OUT" "$REF" )
			then
				echo "** ok: $I"
				rm -f "$OUT"
			else
				echo "?? fail: $I"
				diff "$REF" "$OUT"
				EXIT=1
			fi
		else
			echo "...saving $REF"
			mv "$OUT" "$REF"
		fi
	else
		echo "? no output for $I"
		exit 1
	fi
done
exit $EXIT