@@ -16,10 +16,12 @@ LEX_OUT = lex.yy.c
1616YACC_OUT = parser.tab.c
1717YACC_HEADER = parser.tab.h
1818
19- SMOKE_DIR = tests/smoke
20- SMOKE_SOURCES := $(wildcard $(SMOKE_DIR ) /* .c)
21- SMOKE_CASES := $(basename $(notdir $(SMOKE_SOURCES ) ) )
22- SEMANTIC_SCRIPT = scripts/run_semantic_tests.sh
19+ PASS_DIR = tests/pass
20+ PASS_SOURCES := $(wildcard $(PASS_DIR ) /* .c)
21+ PASS_CASES := $(basename $(notdir $(PASS_SOURCES ) ) )
22+ FAIL_DIR = tests/fail
23+ FAIL_SOURCES := $(wildcard $(FAIL_DIR ) /* .c)
24+ FAIL_CASES := $(basename $(notdir $(FAIL_SOURCES ) ) )
2325
2426all : $(TARGET )
2527
@@ -35,14 +37,16 @@ $(YACC_OUT) $(YACC_HEADER): $(YACC_SRC) src/ast.h src/ast.c
3537clean :
3638 rm -f $(TARGET ) $(LEX_OUT ) $(YACC_OUT ) $(YACC_HEADER )
3739
38- test : all
39- @echo " == Running smoke tests =="
40- @if [ -z " $( SMOKE_CASES) " ]; then \
41- echo " No smoke tests found under $( SMOKE_DIR) " ; \
40+ test : test-pass test-fail
41+
42+ test-pass : all
43+ @echo " == Running pass tests =="
44+ @if [ -z " $( PASS_CASES) " ]; then \
45+ echo " No pass tests found under $( PASS_DIR) " ; \
4246 else \
43- for case in $( SMOKE_CASES ) ; do \
44- input=" $( SMOKE_DIR ) /$$ case.c" ; \
45- expected_file=" $( SMOKE_DIR ) /$$ case.lua" ; \
47+ for case in $( PASS_CASES ) ; do \
48+ input=" $( PASS_DIR ) /$$ case.c" ; \
49+ expected_file=" $( PASS_DIR ) /$$ case.lua" ; \
4650 if [ ! -f " $$ expected_file" ]; then \
4751 echo " Missing expected Lua file for $$ case" ; \
4852 exit 1; \
@@ -58,9 +62,41 @@ test: all
5862 exit 1; \
5963 fi ; \
6064 done ; \
61- echo " All smoke tests passed." ; \
65+ echo " All pass tests passed." ; \
6266 fi
6367
64- semantic-test : all
65- @echo " == Running semantic tests =="
66- @COMPILER_CMD=./c2lua bash $(SEMANTIC_SCRIPT )
68+ test-fail : all
69+ @echo " == Running fail tests =="
70+ @if [ -z " $( FAIL_CASES) " ]; then \
71+ echo " No fail tests found under $( FAIL_DIR) " ; \
72+ else \
73+ for case in $( FAIL_CASES) ; do \
74+ input=" $( FAIL_DIR) /$$ case.c" ; \
75+ expected_err=" $( FAIL_DIR) /$$ case.err" ; \
76+ if [ ! -f " $$ expected_err" ]; then \
77+ echo " Missing expected .err file for $$ case" ; \
78+ exit 1; \
79+ fi ; \
80+ tmp_err=$$(mktemp ) ; \
81+ if ./c2lua " $$ input" > /dev/null 2> " $$ tmp_err" ; then \
82+ echo " -- $$ case... fail" ; \
83+ echo " Expected compilation error but succeeded." ; \
84+ rm -f " $$ tmp_err" ; \
85+ exit 1; \
86+ fi ; \
87+ if diff -u " $$ expected_err" " $$ tmp_err" > /dev/null; then \
88+ echo " -- $$ case... ok" ; \
89+ else \
90+ echo " -- $$ case... fail" ; \
91+ echo " Expected:" ; \
92+ cat " $$ expected_err" ; \
93+ echo ; \
94+ echo " Got:" ; \
95+ cat " $$ tmp_err" ; \
96+ rm -f " $$ tmp_err" ; \
97+ exit 1; \
98+ fi ; \
99+ rm -f " $$ tmp_err" ; \
100+ done ; \
101+ echo " All fail tests passed." ; \
102+ fi
0 commit comments