-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMake.test
46 lines (37 loc) · 1.82 KB
/
Make.test
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
CCFLAGS ?= -Wall -Werror -std=c99 -O3
LEXER_TEST_FILES := $(shell find $(TESTS_DIR)/lexer -name '*.b')
PARSER_TEST_FILES := $(shell find $(TESTS_DIR)/parser -name '*.b')
RESOLVER_TEST_FILES := $(shell find $(TESTS_DIR)/resolver -name '*.b')
CODEGEN_TEST_FILES := $(shell find $(TESTS_DIR)/codegen -name '*.b')
RUN_TEST_FILES := $(shell find $(TESTS_DIR)/run -name '*.b')
LEXER_TESTS := $(patsubst %.b, %.lex, $(LEXER_TEST_FILES))
PARSER_TESTS := $(patsubst %.b, %.parse, $(PARSER_TEST_FILES))
RESOLVER_TESTS := $(patsubst %.b, %.resolve, $(RESOLVER_TEST_FILES))
CODEGEN_TESTS := $(patsubst %.b, %.codegen, $(CODEGEN_TEST_FILES))
RUN_TESTS := $(patsubst %.b, %.run, $(RUN_TEST_FILES))
.PHONY: test
test: $(LEXER_TESTS) $(PARSER_TESTS) $(RESOLVER_TESTS) $(CODEGEN_TESTS) $(RUN_TESTS)
@echo "All tests passed."
%.lex: %.b %.test $(BC_NEW)
@$(BC_NEW) -l $< > $@ 2>&1 || (exit 0)
@diff -q $(word 2, $^) $@ >/dev/null || (echo "Test $@ failed" && exit 1)
%.parse: %.b %.test $(BC_NEW)
@$(BC_NEW) -p $< > $@ 2>&1 || (exit 0)
@diff -q $(word 2, $^) $@ >/dev/null || (echo "Test $@ failed" && exit 1)
%.resolve: %.b %.test $(BC_NEW)
@$(BC_NEW) -r $< > $@ 2>&1 || (exit 0)
@diff -q $(word 2, $^) $@ >/dev/null || (echo "Test $@ failed" && exit 1)
%.codegen: %.b %.test $(BC_NEW)
@$(BC_NEW) -g $< > $@ 2>&1 || (exit 0)
@diff -q $(word 2, $^) $@ >/dev/null || (echo "Test $@ failed" && exit 1)
%.run: %.b %.test $(BC_NEW)
@$(BC_NEW) -g $< > [email protected] 2>$@
@$(CC) $(CCFLAGS) -o [email protected] [email protected]
@diff -q $(word 2, $^) $@ >/dev/null || (echo "Test $@ failed" && exit 1)
clean::
@find $(TESTS_DIR)/lexer -name '*.lex' -delete
@find $(TESTS_DIR)/parser -name '*.parse' -delete
@find $(TESTS_DIR)/resolver -name '*.resolve' -delete
@find $(TESTS_DIR)/codegen -name '*.codegen' -delete
@find $(TESTS_DIR)/run -name '*.run' -delete