Skip to content

Commit

Permalink
add failing test files
Browse files Browse the repository at this point in the history
where the C compiler should throw compile-time errors
for GH rui314#41
  • Loading branch information
rurban committed Feb 17, 2023
1 parent 28fd55e commit 2d98f08
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 2 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@
/thirdparty
/chibicc
/test/*.exe
/test/*.fail
/stage2
11 changes: 9 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ SRCS=$(wildcard *.c)
OBJS=$(SRCS:.c=.o)

TEST_SRCS=$(wildcard test/*.c)
FAIL_TEST_SRCS=$(wildcard test/*.c_fail)
TESTS=$(TEST_SRCS:.c=.exe)
FAIL_TESTS=$(FAIL_TEST_SRCS:.c_fail=.fail)

# Stage 1

Expand All @@ -17,7 +19,12 @@ test/%.exe: chibicc test/%.c
./chibicc -Iinclude -Itest -c -o test/$*.o test/$*.c
$(CC) -pthread -o $@ test/$*.o -xc test/common

test: $(TESTS)
test/%.fail: chibicc test/%.c_fail
echo "cat <<EOF" >test/$*.fail
./chibicc -Iinclude -Itest -xc -c test/$*.c_fail 2>>test/$*.fail || \
(echo OK; printf "EOF\necho OK\n" >>test/$*.fail; chmod +x test/$*.fail)

test: $(TESTS) $(FAIL_TESTS)
for i in $^; do echo $$i; ./$$i || exit 1; echo; done
test/driver.sh ./chibicc

Expand Down Expand Up @@ -50,7 +57,7 @@ install:
sudo cp chibicc /usr/local/bin/chibicc

clean:
rm -rf chibicc tmp* $(TESTS) test/*.s test/*.exe stage2
rm -rf chibicc tmp* $(TESTS) test/*.s test/*.exe stage2 test/*.fail
find * -type f '(' -name '*~' -o -name '*.o' ')' -exec rm {} ';'

.PHONY: test clean test-stage2
7 changes: 7 additions & 0 deletions test/void1.c_fail
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// Assigning expression with void type.
void foo() {}
void bar() {int x = foo();}

int main() {
return 1;
}
8 changes: 8 additions & 0 deletions test/void2.c_fail
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// Return nothing in a non-void type function.
int bar() {
return;
}

int main() {
return 1;
}
10 changes: 10 additions & 0 deletions test/void3.c_fail
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// Return void type expression in a non-void function.
void foo() {}

int bar() {
return foo();
}

int main() {
return 1;
}
9 changes: 9 additions & 0 deletions test/void4.c_fail
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// Return non-void type expression in a void type function.
void foo() {
return 1;
}


int main() {
return 1;
}

0 comments on commit 2d98f08

Please sign in to comment.