From e91dde6213d050b2af589088f593e230c53f0fc6 Mon Sep 17 00:00:00 2001 From: hyung-hwan Date: Mon, 27 Nov 2023 00:08:59 +0900 Subject: [PATCH] added some error check scripts --- bin/main.c | 2 +- lib/hcl-cmn.h | 12 +++++++++++- lib/hcl.h | 8 +++++--- t/Makefile.am | 16 +++++++++++----- t/Makefile.in | 37 ++++++++++++++++++++++++++++++------- t/err.sh | 22 ++++++++++++++++++++++ t/var-01.err | 14 ++++++++++++++ t/var-02.err | 3 +++ 8 files changed, 97 insertions(+), 17 deletions(-) create mode 100644 t/err.sh create mode 100644 t/var-01.err create mode 100644 t/var-02.err diff --git a/bin/main.c b/bin/main.c index 6afc2c9..f3d4a2e 100644 --- a/bin/main.c +++ b/bin/main.c @@ -423,7 +423,7 @@ static hcl_oop_t execute_in_batch_mode (hcl_t* hcl, int verbose) hcl_oop_t retv; hcl_decode (hcl, 0, hcl_getbclen(hcl)); - HCL_LOG2 (hcl, HCL_LOG_MNEMONIC, "BYTECODES bclen = > %zu lflen => %zu\n", hcl_getbclen(hcl), hcl_getlflen(hcl)); + HCL_LOG3 (hcl, HCL_LOG_MNEMONIC, "BYTECODES bclen=%zu lflen=%zu ngtmprs=%zu\n", hcl_getbclen(hcl), hcl_getlflen(hcl), hcl_getngtmprs(hcl)); g_hcl = hcl; /*setup_tick ();*/ diff --git a/lib/hcl-cmn.h b/lib/hcl-cmn.h index 305cff8..1f2fe71 100644 --- a/lib/hcl-cmn.h +++ b/lib/hcl-cmn.h @@ -859,6 +859,14 @@ typedef struct hcl_t hcl_t; # define HCL_UNUSED #endif +#if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 202311L) +# define HCL_NORETURN noreturn +#elif defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 201112L) +# define HCL_NORETURN _Noreturn +#else +# define HCL_NORETURN +#endif + /** * The HCL_TYPE_IS_SIGNED() macro determines if a type is signed. * \code @@ -1077,7 +1085,9 @@ typedef struct hcl_t hcl_t; #define HCL_STATIC_JOIN_INNER(x, y) x ## y #define HCL_STATIC_JOIN(x, y) HCL_STATIC_JOIN_INNER(x, y) -#if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 201112L) +#if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 202311L) +# define HCL_STATIC_ASSERT(expr) static_assert (expr, "invalid assertion") +#elif defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 201112L) # define HCL_STATIC_ASSERT(expr) _Static_assert (expr, "invalid assertion") #elif defined(__cplusplus) && (__cplusplus >= 201103L) # define HCL_STATIC_ASSERT(expr) static_assert (expr, "invalid assertion") diff --git a/lib/hcl.h b/lib/hcl.h index 9ac2645..f8d13ce 100644 --- a/lib/hcl.h +++ b/lib/hcl.h @@ -2369,12 +2369,14 @@ HCL_EXPORT int hcl_decode ( ); #if defined(HCL_HAVE_INLINE) - static HCL_INLINE hcl_oow_t hcl_getbclen (hcl_t* hcl) { return hcl->code.bc.len; } - static HCL_INLINE hcl_oow_t hcl_getlflen (hcl_t* hcl) { return hcl->code.lit.len; } - static HCL_INLINE hcl_ooi_t hcl_getip (hcl_t* hcl) { return hcl->ip; } +static HCL_INLINE hcl_oow_t hcl_getbclen (hcl_t* hcl) { return hcl->code.bc.len; } +static HCL_INLINE hcl_oow_t hcl_getlflen (hcl_t* hcl) { return hcl->code.lit.len; } +static HCL_INLINE hcl_oow_t hcl_getngtmprs (hcl_t* hcl) { return hcl->code.ngtmprs; } +static HCL_INLINE hcl_ooi_t hcl_getip (hcl_t* hcl) { return hcl->ip; } #else # define hcl_getbclen(hcl) ((hcl)->code.bc.len) # define hcl_getlflen(hcl) ((hcl)->code.lit.len) +# define hcl_getngtmprs(hcl) ((hcl)->code.ngtmprs) # define hcl_getip(hcl) ((hcl)->ip) #endif diff --git a/t/Makefile.am b/t/Makefile.am index 1a172ce..31a5432 100644 --- a/t/Makefile.am +++ b/t/Makefile.am @@ -6,17 +6,23 @@ check_SCRIPTS = \ insta-02.hcl \ ret-01.hcl \ retvar-01.hcl \ - va-01.hcl \ - var-01.hcl + va-01.hcl + +check_ERRORS = \ + var-01.err \ + var-02.err ##noinst_SCRIPTS = $(check_SCRIPTS) -EXTRA_DIST = $(check_SCRIPTS) +EXTRA_DIST = $(check_SCRIPTS) $(check_ERRORS) check_PROGRAMS = +TESTS = $(check_PROGRAMS) $(check_SCRIPTS) $(check_ERRORS) -TESTS = $(check_PROGRAMS) $(check_SCRIPTS) +TEST_EXTENSIONS = .hcl .err -TEST_EXTENSIONS = .hcl HCL_LOG_COMPILER = sh $(abs_srcdir)/run.sh ../bin/hcl -x AM_HCL_LOG_FLAGS = + +ERR_LOG_COMPILER = sh $(abs_srcdir)/err.sh ../bin/hcl -x +AM_ERR_LOG_FLAGS = diff --git a/t/Makefile.in b/t/Makefile.in index 13ccfa6..5af72df 100644 --- a/t/Makefile.in +++ b/t/Makefile.in @@ -88,7 +88,7 @@ POST_UNINSTALL = : build_triplet = @build@ host_triplet = @host@ check_PROGRAMS = -TESTS = $(am__EXEEXT_1) $(check_SCRIPTS) +TESTS = $(am__EXEEXT_1) $(check_SCRIPTS) $(check_ERRORS) subdir = t ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 am__aclocal_m4_deps = $(top_srcdir)/m4/ax_check_sign.m4 \ @@ -312,7 +312,7 @@ am__EXEEXT_1 = TEST_SUITE_LOG = test-suite.log am__test_logs1 = $(TESTS:=.log) am__test_logs2 = $(am__test_logs1:@EXEEXT@.log=.log) -TEST_LOGS = $(am__test_logs2:.hcl.log=.log) +am__test_logs3 = $(am__test_logs2:.hcl.log=.log) HCL_LOG_DRIVER = $(SHELL) $(top_srcdir)/ac/test-driver HCL_LOG_COMPILE = $(HCL_LOG_COMPILER) $(AM_HCL_LOG_FLAGS) \ $(HCL_LOG_FLAGS) @@ -326,6 +326,10 @@ am__set_b = \ *) \ b='$*';; \ esac +TEST_LOGS = $(am__test_logs3:.err.log=.log) +ERR_LOG_DRIVER = $(SHELL) $(top_srcdir)/ac/test-driver +ERR_LOG_COMPILE = $(ERR_LOG_COMPILER) $(AM_ERR_LOG_FLAGS) \ + $(ERR_LOG_FLAGS) am__DIST_COMMON = $(srcdir)/Makefile.in $(top_srcdir)/ac/test-driver DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST) ACLOCAL = @ACLOCAL@ @@ -473,17 +477,22 @@ check_SCRIPTS = \ insta-02.hcl \ ret-01.hcl \ retvar-01.hcl \ - va-01.hcl \ - var-01.hcl + va-01.hcl -EXTRA_DIST = $(check_SCRIPTS) -TEST_EXTENSIONS = .hcl +check_ERRORS = \ + var-01.err \ + var-02.err + +EXTRA_DIST = $(check_SCRIPTS) $(check_ERRORS) +TEST_EXTENSIONS = .hcl .err HCL_LOG_COMPILER = sh $(abs_srcdir)/run.sh ../bin/hcl -x AM_HCL_LOG_FLAGS = +ERR_LOG_COMPILER = sh $(abs_srcdir)/err.sh ../bin/hcl -x +AM_ERR_LOG_FLAGS = all: all-am .SUFFIXES: -.SUFFIXES: .hcl .hcl$(EXEEXT) .log .trs +.SUFFIXES: .err .err$(EXEEXT) .hcl .hcl$(EXEEXT) .log .trs $(srcdir)/Makefile.in: $(srcdir)/Makefile.am $(am__configure_deps) @for dep in $?; do \ case '$(am__configure_deps)' in \ @@ -690,6 +699,20 @@ recheck: all $(check_PROGRAMS) $(check_SCRIPTS) @am__EXEEXT_TRUE@ --log-file $$b.log --trs-file $$b.trs \ @am__EXEEXT_TRUE@ $(am__common_driver_flags) $(AM_HCL_LOG_DRIVER_FLAGS) $(HCL_LOG_DRIVER_FLAGS) -- $(HCL_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/err.sh b/t/err.sh new file mode 100644 index 0000000..5a1cf57 --- /dev/null +++ b/t/err.sh @@ -0,0 +1,22 @@ +#!/bin/sh + +for i in $@; do :; done +script="$i" + +expected_errinfo=$(grep -E "##[[:space:]]+ERROR:" "$script" 2>/dev/null) +[ -z "$expected_errinfo" ] && { + echo "INVALID TESTER - $script contains no ERROR information" + exit 1 +} + +expected_errline=$(echo $expected_errinfo | cut -d: -f1) +xlen=$(echo $expected_errline | wc -c) +xlen=$(expr $xlen + 2) +expected_errmsg=$(echo $expected_errinfo | cut -c${xlen}-) + +output=$($@ 2>&1) +echo "$output" | grep -E "ERROR:.+${script}.+${expected_errmsg}" || { + echo "$script - $output" + exit 1 +} +exit 0 diff --git a/t/var-01.err b/t/var-01.err new file mode 100644 index 0000000..ff50054 --- /dev/null +++ b/t/var-01.err @@ -0,0 +1,14 @@ +defclass Object { + { + ## this must not be allowed at this level. if it's allowed, + ## it should be at the top-level which is above the class level. this is confusing. + | j | ## ERROR: syntax error + set j 20; + printf ">>> %d\n" j; + } + + defun ::* init() { + printf "Object init...\n"; + return self; + }; +}; diff --git a/t/var-02.err b/t/var-02.err new file mode 100644 index 0000000..6851a3b --- /dev/null +++ b/t/var-02.err @@ -0,0 +1,3 @@ +## if you want local temporaries variables at the top-level, use the blocked expression. +| a | ## ERROR: syntax error - variable declaration disallowed +set a 10; \ No newline at end of file