Browse Source

Add test suite

Forest Belton 1 year ago
parent
commit
93132803e3
4 changed files with 21 additions and 7 deletions
  1. 1
    1
      .gitignore
  2. 14
    5
      Makefile
  3. 2
    1
      main.c
  4. 4
    0
      test/001-trivial.c

+ 1
- 1
.gitignore View File

@@ -1,4 +1,4 @@
1 1
 *.swp
2 2
 *.o
3
-src/grammar.c
3
+grammar.c
4 4
 ccc

+ 14
- 5
Makefile View File

@@ -8,12 +8,15 @@ HEADERS := $(shell find include -type f -name '*.h')
8 8
 CFILES := $(shell find src -type f -name '*.c' -not -name 'grammar.c')
9 9
 OFILES := $(CFILES:%.c=%.o)
10 10
 
11
-.PHONY: clean
11
+TEST_SRCS := $(shell find test -type f -name '*.c')
12
+TESTS := $(TEST_SRCS:%.c=%)
12 13
 
13
-$(APP): src/grammar.c $(OFILES)
14
-	$(CC) $(LDFLAGS) $(OFILES) -o $@
14
+.PHONY: clean test
15 15
 
16
-src/grammar.c: grammar.peg
16
+$(APP): grammar.c main.c $(OFILES)
17
+	$(CC) $(CFLAGS) $(LDFLAGS) $(OFILES) main.c -o $@
18
+
19
+grammar.c: grammar.peg
17 20
 	leg -o $@ $<
18 21
 
19 22
 %.o: %.c $(HEADERS)
@@ -21,4 +24,10 @@ src/grammar.c: grammar.peg
21 24
 
22 25
 clean:
23 26
 	find src -type f -name '*.o' -delete
24
-	rm -f $(APP) src/grammar.c
27
+	rm -f $(APP) grammar.c
28
+
29
+test/%: test/%.c
30
+	$(CC) $(OFILES) $< -o $@
31
+	./$@
32
+
33
+test: $(APP) $(TESTS)

src/main.c → main.c View File

@@ -1,5 +1,6 @@
1 1
 #include <string.h>
2
-#include "grammar.c"
2
+
3
+#include "src/grammar.c"
3 4
 
4 5
 int main() {
5 6
     yycontext ctx;

+ 4
- 0
test/001-trivial.c View File

@@ -0,0 +1,4 @@
1
+int main() {
2
+    return 0;
3
+}
4
+

Loading…
Cancel
Save