From 4ed8651821fb9368b161f828de37ee9ecb90168a Mon Sep 17 00:00:00 2001 From: hyung-hwan Date: Sat, 4 May 2024 00:49:27 +0900 Subject: [PATCH] added t/err.sh for testing errors --- Makefile.in | 7 +++-- configure | 4 ++- configure.ac | 1 + t/Makefile.am | 14 ++++++++-- t/Makefile.in | 31 +++++++++++++++++---- t/e-001.err | 24 ++++++++++++++++ t/err.sh | 77 +++++++++++++++++++++++++++++++++++++++++++++++++++ 7 files changed, 146 insertions(+), 12 deletions(-) create mode 100644 t/e-001.err create mode 100644 t/err.sh diff --git a/Makefile.in b/Makefile.in index df83fa56..64a36c18 100644 --- a/Makefile.in +++ b/Makefile.in @@ -166,9 +166,10 @@ am__DIST_COMMON = $(srcdir)/Makefile.in $(top_srcdir)/ac/ar-lib \ $(top_srcdir)/ac/compile $(top_srcdir)/ac/config.guess \ $(top_srcdir)/ac/config.sub $(top_srcdir)/ac/install-sh \ $(top_srcdir)/ac/ltmain.sh $(top_srcdir)/ac/missing \ - $(top_srcdir)/ac/tap-driver.sh $(top_srcdir)/pkgs/hawk.spec.in \ - README.md ac/ar-lib ac/compile ac/config.guess ac/config.sub \ - ac/depcomp ac/install-sh ac/ltmain.sh ac/missing + $(top_srcdir)/ac/tap-driver.sh $(top_srcdir)/ac/test-driver \ + $(top_srcdir)/pkgs/hawk.spec.in README.md ac/ar-lib ac/compile \ + ac/config.guess ac/config.sub ac/depcomp ac/install-sh \ + ac/ltmain.sh ac/missing DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST) distdir = $(PACKAGE)-$(VERSION) top_distdir = $(distdir) diff --git a/configure b/configure index 25a9bf79..7042f239 100755 --- a/configure +++ b/configure @@ -3176,7 +3176,7 @@ as_fn_append ac_header_c_list " sys/types.h sys_types_h HAVE_SYS_TYPES_H" as_fn_append ac_header_c_list " unistd.h unistd_h HAVE_UNISTD_H" # Auxiliary files required by this configure script. -ac_aux_files="config.guess config.sub ltmain.sh tap-driver.sh compile ar-lib missing install-sh" +ac_aux_files="config.guess config.sub ltmain.sh test-driver tap-driver.sh compile ar-lib missing install-sh" # Locations in which to look for auxiliary files. ac_aux_dir_candidates="${srcdir}/ac" @@ -5409,6 +5409,8 @@ esac + + # Check whether --enable-silent-rules was given. if test ${enable_silent_rules+y} then : diff --git a/configure.ac b/configure.ac index dc26d476..ee0ef71d 100644 --- a/configure.ac +++ b/configure.ac @@ -14,6 +14,7 @@ AM_INIT_AUTOMAKE([-Wall -Werror subdir-objects foreign]) AM_PROG_AR AC_REQUIRE_AUX_FILE([tap-driver.sh]) +AC_REQUIRE_AUX_FILE([test-driver]) dnl enable silent rules if automake supports them. m4_ifdef([AM_SILENT_RULES], [AM_SILENT_RULES([no])]) diff --git a/t/Makefile.am b/t/Makefile.am index 4e6eadb5..9e86db1a 100644 --- a/t/Makefile.am +++ b/t/Makefile.am @@ -14,8 +14,11 @@ LDFLAGS_COMMON=-L$(abs_builddir)/../lib -L$(libdir) LIBADD_COMMON = ../lib/libhawk.la $(LIBM) check_SCRIPTS = h-001.hawk h-002.hawk h-003.hawk h-004.hawk h-009.hawk + +check_ERRORS = e-001.err + ##noinst_SCRIPTS = $(check_SCRIPTS) -EXTRA_DIST = $(check_SCRIPTS) tap.inc \ +EXTRA_DIST = $(check_SCRIPTS) $(check_ERRORS) tap.inc err.sh \ journal-toc.hawk journal-toc.in journal-toc.out journal-toc-html.out \ bibtex-to-html.hawk bibtex-to-html.out @@ -55,9 +58,14 @@ t_006_LDFLAGS = $(LDFLAGS_COMMON) t_006_LDADD = $(LIBADD_COMMON) LOG_DRIVER = env AM_TAP_AWK='$(AWK)' $(SHELL) $(top_srcdir)/ac/tap-driver.sh -TESTS = $(check_PROGRAMS) $(check_SCRIPTS) +TESTS = $(check_PROGRAMS) $(check_SCRIPTS) $(check_ERRORS) + +TEST_EXTENSIONS = .hawk .err -TEST_EXTENSIONS = .hawk HAWK_LOG_DRIVER = $(LOG_DRIVER) HAWK_LOG_COMPILER = ../bin/hawk AM_HAWK_LOG_FLAGS = -vTDIR=${abs_srcdir} --modlibdirs=../lib/.libs:../mod/.libs -f + +ERR_LOG_DRIVER = $(SHELL) $(top_srcdir)/ac/test-driver +ERR_LOG_COMPILER = $(SHELL) $(abs_srcdir)/err.sh ../bin/hawk -vTDIR=${abs_srcdir} --modlibdirs=../lib/.libs:../mod/.libs -f +AM_ERR_LOG_FLAGS = diff --git a/t/Makefile.in b/t/Makefile.in index 8b572318..ac5f7439 100644 --- a/t/Makefile.in +++ b/t/Makefile.in @@ -409,9 +409,12 @@ am__set_b = \ esac am__test_logs1 = $(TESTS:=.log) am__test_logs2 = $(am__test_logs1:@EXEEXT@.log=.log) -TEST_LOGS = $(am__test_logs2:.hawk.log=.log) +am__test_logs3 = $(am__test_logs2:.hawk.log=.log) HAWK_LOG_COMPILE = $(HAWK_LOG_COMPILER) $(AM_HAWK_LOG_FLAGS) \ $(HAWK_LOG_FLAGS) +TEST_LOGS = $(am__test_logs3:.err.log=.log) +ERR_LOG_COMPILE = $(ERR_LOG_COMPILER) $(AM_ERR_LOG_FLAGS) \ + $(ERR_LOG_FLAGS) am__DIST_COMMON = $(srcdir)/Makefile.in $(top_srcdir)/ac/depcomp DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST) ACLOCAL = @ACLOCAL@ @@ -579,7 +582,8 @@ CFLAGS_COMMON = LDFLAGS_COMMON = -L$(abs_builddir)/../lib -L$(libdir) LIBADD_COMMON = ../lib/libhawk.la $(LIBM) check_SCRIPTS = h-001.hawk h-002.hawk h-003.hawk h-004.hawk h-009.hawk -EXTRA_DIST = $(check_SCRIPTS) tap.inc \ +check_ERRORS = e-001.err +EXTRA_DIST = $(check_SCRIPTS) $(check_ERRORS) tap.inc err.sh \ journal-toc.hawk journal-toc.in journal-toc.out journal-toc-html.out \ bibtex-to-html.hawk bibtex-to-html.out @@ -611,15 +615,18 @@ t_006_CFLAGS = $(CFLAGS_COMMON) t_006_LDFLAGS = $(LDFLAGS_COMMON) t_006_LDADD = $(LIBADD_COMMON) LOG_DRIVER = env AM_TAP_AWK='$(AWK)' $(SHELL) $(top_srcdir)/ac/tap-driver.sh -TESTS = $(check_PROGRAMS) $(check_SCRIPTS) -TEST_EXTENSIONS = .hawk +TESTS = $(check_PROGRAMS) $(check_SCRIPTS) $(check_ERRORS) +TEST_EXTENSIONS = .hawk .err HAWK_LOG_DRIVER = $(LOG_DRIVER) HAWK_LOG_COMPILER = ../bin/hawk AM_HAWK_LOG_FLAGS = -vTDIR=${abs_srcdir} --modlibdirs=../lib/.libs:../mod/.libs -f +ERR_LOG_DRIVER = $(SHELL) $(top_srcdir)/ac/test-driver +ERR_LOG_COMPILER = $(SHELL) $(abs_srcdir)/err.sh ../bin/hawk -vTDIR=${abs_srcdir} --modlibdirs=../lib/.libs:../mod/.libs -f +AM_ERR_LOG_FLAGS = all: all-am .SUFFIXES: -.SUFFIXES: .c .hawk .hawk$(EXEEXT) .lo .log .o .obj .trs +.SUFFIXES: .c .err .err$(EXEEXT) .hawk .hawk$(EXEEXT) .lo .log .o .obj .trs $(srcdir)/Makefile.in: $(srcdir)/Makefile.am $(am__configure_deps) @for dep in $?; do \ case '$(am__configure_deps)' in \ @@ -1065,6 +1072,20 @@ t-006.log: t-006$(EXEEXT) @am__EXEEXT_TRUE@ --log-file $$b.log --trs-file $$b.trs \ @am__EXEEXT_TRUE@ $(am__common_driver_flags) $(AM_HAWK_LOG_DRIVER_FLAGS) $(HAWK_LOG_DRIVER_FLAGS) -- $(HAWK_LOG_COMPILE) \ @am__EXEEXT_TRUE@ "$$tst" $(AM_TESTS_FD_REDIRECT) +.err.log: + @p='$<'; \ + $(am__set_b); \ + $(am__check_pre) $(ERR_LOG_DRIVER) --test-name "$$f" \ + --log-file $$b.log --trs-file $$b.trs \ + $(am__common_driver_flags) $(AM_ERR_LOG_DRIVER_FLAGS) $(ERR_LOG_DRIVER_FLAGS) -- $(ERR_LOG_COMPILE) \ + "$$tst" $(AM_TESTS_FD_REDIRECT) +@am__EXEEXT_TRUE@.err$(EXEEXT).log: +@am__EXEEXT_TRUE@ @p='$<'; \ +@am__EXEEXT_TRUE@ $(am__set_b); \ +@am__EXEEXT_TRUE@ $(am__check_pre) $(ERR_LOG_DRIVER) --test-name "$$f" \ +@am__EXEEXT_TRUE@ --log-file $$b.log --trs-file $$b.trs \ +@am__EXEEXT_TRUE@ $(am__common_driver_flags) $(AM_ERR_LOG_DRIVER_FLAGS) $(ERR_LOG_DRIVER_FLAGS) -- $(ERR_LOG_COMPILE) \ +@am__EXEEXT_TRUE@ "$$tst" $(AM_TESTS_FD_REDIRECT) distdir: $(BUILT_SOURCES) $(MAKE) $(AM_MAKEFLAGS) distdir-am diff --git a/t/e-001.err b/t/e-001.err new file mode 100644 index 00000000..78356933 --- /dev/null +++ b/t/e-001.err @@ -0,0 +1,24 @@ +BEGIN { + ##ERROR: unexpected end of input +--- + +function abc(x { ##ERROR: comma expected in place of +} + +--- + +BEGIN { + @argv = 10 ##ERROR: invalid assignment statement +} + +--- + +BEGIN { + @argc = 10 ##ERROR: invalid assignment statement +} + +--- + +BEGIN { + @nil = 10 ##ERROR: invalid assignment statement +} diff --git a/t/err.sh b/t/err.sh new file mode 100644 index 00000000..b98486c4 --- /dev/null +++ b/t/err.sh @@ -0,0 +1,77 @@ +#!/bin/sh + +for i in $@; do :; done +script="$i" + +run_partfile() { + l_cmd=""; + l_nargs=$# + + while [ $# -gt 3 ] + do + l_cmd="$l_cmd $1" + shift + done + + l_script="$1" + shift ## skip the original script. + l_partno="$1" + shift ## partno + + l_partfile="$1" + l_cmd="$l_cmd $l_partfile" + + l_expected_errinfo=$(grep -n -o -E "##ERROR: .+" "$l_partfile" 2>/dev/null) + [ -z "$l_expected_errinfo" ] && { + echo "ERROR: INVALID TESTER - $l_script($l_partno) contains no ERROR information" + return 1 + } + + l_expected_errline=$(echo $l_expected_errinfo | cut -d: -f1) + l_xlen=$(echo $l_expected_errline | wc -c) + l_xlen=$(expr $l_xlen + 10) + l_expected_errmsg=$(echo $l_expected_errinfo | cut -c${l_xlen}-) + l_output=`$l_cmd 2>&1` + ## the regular expression is not escaped properly. the error information must not + ## include specifial regex characters to avoid problems. + echo "$l_output" | grep -E "ERROR: .+ LINE ${l_expected_errline} .+ FILE ${l_partfile} - ${l_expected_errmsg}" >/dev/null 2>&1 || { + echo "ERROR: error not raised at line $l_expected_errline - $l_script($l_partno) - $l_output" + return 1 + } + + echo "OK" + return 0 +} + + +ever_failed=0 +partfile=`mktemp` +partno=0 +partlines=0 +> "$partfile" + +## dash behaves differently for read -r. +## while \n is read in literally by bash or other shells, dash converts it to a new-line +while IFS= read -r line +do + if [ "$line" = "---" ] + then + [ $partlines -gt 0 ] && { + run_partfile "$@" "$partno" "$partfile" || ever_failed=1 + } + partno=`expr $partno + 1` + partlines=0 + > "$partfile" + else + echo "$line" >> "$partfile" + partlines=`expr $partlines + 1` + fi +done < "$script" + +[ $partlines -gt 0 ] && { + run_partfile "$@" "$partno" "$partfile" || ever_failed=1 +} + +rm -f "$partfile" +exit $ever_failed +