Blame testsuite/check.sh

Packit Bot a3ac83
#! /bin/sh
Packit Bot a3ac83
# check script for GNU ed - The GNU line editor
Packit Bot a3ac83
# Copyright (C) 2006-2017 Antonio Diaz Diaz.
Packit Bot a3ac83
#
Packit Bot a3ac83
# This script is free software; you have unlimited permission
Packit Bot a3ac83
# to copy, distribute and modify it.
Packit Bot a3ac83
Packit Bot a3ac83
LC_ALL=C
Packit Bot a3ac83
export LC_ALL
Packit Bot a3ac83
objdir=`pwd`
Packit Bot a3ac83
testdir=`cd "$1" ; pwd`
Packit Bot a3ac83
ED="${objdir}"/ed
Packit Bot a3ac83
framework_failure() { echo "failure in testing framework" ; exit 1 ; }
Packit Bot a3ac83
Packit Bot a3ac83
if [ ! -f "${ED}" ] || [ ! -x "${ED}" ] ; then
Packit Bot a3ac83
	echo "${ED}: cannot execute"
Packit Bot a3ac83
	exit 1
Packit Bot a3ac83
fi
Packit Bot a3ac83
Packit Bot a3ac83
if [ -d tmp ] ; then rm -rf tmp ; fi
Packit Bot a3ac83
mkdir tmp
Packit Bot a3ac83
cd "${objdir}"/tmp || framework_failure
Packit Bot a3ac83
Packit Bot a3ac83
cat "${testdir}"/test.txt > test.txt || framework_failure
Packit Bot a3ac83
cat "${testdir}"/test.bin > test.bin || framework_failure
Packit Bot a3ac83
touch zero || framework_failure
Packit Bot a3ac83
fail=0
Packit Bot a3ac83
Packit Bot a3ac83
printf "testing ed-%s...\n" "$2"
Packit Bot a3ac83
Packit Bot a3ac83
# Run the .err scripts first with a regular file connected to standard
Packit Bot a3ac83
# input, since these don't generate output; they exit with non-zero status.
Packit Bot a3ac83
for i in "${testdir}"/*.err ; do
Packit Bot a3ac83
	if "${ED}" -s test.txt < "$i" > /dev/null 2>&1 ; then
Packit Bot a3ac83
		echo "*** The script $i exited abnormally ***"
Packit Bot a3ac83
		fail=127
Packit Bot a3ac83
	fi
Packit Bot a3ac83
done
Packit Bot a3ac83
Packit Bot a3ac83
# Run the .err scripts again with a regular file connected to standard
Packit Bot a3ac83
# input, but with '--loose-exit-status'; they should exit with zero status.
Packit Bot a3ac83
for i in "${testdir}"/*.err ; do
Packit Bot a3ac83
	if "${ED}" -sl test.txt < "$i" > /dev/null 2>&1 ; then
Packit Bot a3ac83
		true
Packit Bot a3ac83
	else
Packit Bot a3ac83
		echo "*** The script $i failed '--loose-exit-status' ***"
Packit Bot a3ac83
		fail=127
Packit Bot a3ac83
	fi
Packit Bot a3ac83
done
Packit Bot a3ac83
Packit Bot a3ac83
# Run the .err scripts again as pipes - these should exit with non-zero
Packit Bot a3ac83
# status without altering the contents of the buffer; the produced
Packit Bot a3ac83
# 'out.ro' must be identical to 'test.txt'.
Packit Bot a3ac83
for i in "${testdir}"/*.err ; do
Packit Bot a3ac83
	base=`echo "$i" | sed 's,^.*/,,;s,\.err$,,'`	# remove dir and ext
Packit Bot a3ac83
	if cat "$i" | "${ED}" -s test.txt > /dev/null 2>&1 ; then
Packit Bot a3ac83
		echo "*** The piped script $i exited abnormally ***"
Packit Bot a3ac83
		fail=127
Packit Bot a3ac83
	else
Packit Bot a3ac83
		if cmp -s out.ro test.txt ; then
Packit Bot a3ac83
			true
Packit Bot a3ac83
		else
Packit Bot a3ac83
			mv -f out.ro ${base}.ro
Packit Bot a3ac83
			echo "*** Output ${base}.ro of piped script $i is incorrect ***"
Packit Bot a3ac83
			fail=127
Packit Bot a3ac83
		fi
Packit Bot a3ac83
	fi
Packit Bot a3ac83
	rm -f out.ro
Packit Bot a3ac83
done
Packit Bot a3ac83
Packit Bot a3ac83
# Run the .ed scripts and compare their output against the .r files,
Packit Bot a3ac83
# which contain the correct output.
Packit Bot a3ac83
# The .ed scripts should exit with zero status.
Packit Bot a3ac83
for i in "${testdir}"/*.ed ; do
Packit Bot a3ac83
	base=`echo "$i" | sed 's,^.*/,,;s,\.ed$,,'`	# remove dir and ext
Packit Bot a3ac83
	if "${ED}" -s test.txt < "$i" > /dev/null 2> out.log ; then
Packit Bot a3ac83
		if cmp -s out.o "${testdir}"/${base}.r ; then
Packit Bot a3ac83
			true
Packit Bot a3ac83
		else
Packit Bot a3ac83
			mv -f out.o ${base}.o
Packit Bot a3ac83
			echo "*** Output ${base}.o of script $i is incorrect ***"
Packit Bot a3ac83
			fail=127
Packit Bot a3ac83
		fi
Packit Bot a3ac83
	else
Packit Bot a3ac83
		mv -f out.log ${base}.log
Packit Bot a3ac83
		echo "*** The script $i exited abnormally ***"
Packit Bot a3ac83
		fail=127
Packit Bot a3ac83
	fi
Packit Bot a3ac83
	rm -f out.o out.log
Packit Bot a3ac83
done
Packit Bot a3ac83
Packit Bot a3ac83
rm -f test.txt test.bin zero
Packit Bot a3ac83
Packit Bot a3ac83
if [ ${fail} = 0 ] ; then
Packit Bot a3ac83
	echo "tests completed successfully."
Packit Bot a3ac83
	cd "${objdir}" && rm -r tmp
Packit Bot a3ac83
else
Packit Bot a3ac83
	echo "tests failed."
Packit Bot a3ac83
	echo "Please, send a bug report to bug-ed@gnu.org."
Packit Bot a3ac83
	echo "Include the (compressed) contents of '${objdir}/tmp' in the report."
Packit Bot a3ac83
fi
Packit Bot a3ac83
exit ${fail}