mirror of
https://github.com/sigmasternchen/macrofuck
synced 2025-03-15 23:28:55 +00:00
feat: Add build infra + tests for brainfuck interpreter
This commit is contained in:
parent
9b1d59808e
commit
2d0d7691d7
14 changed files with 107 additions and 0 deletions
brainfuck
1
brainfuck/.gitignore
vendored
Normal file
1
brainfuck/.gitignore
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
bf
|
34
brainfuck/Makefile
Normal file
34
brainfuck/Makefile
Normal file
|
@ -0,0 +1,34 @@
|
|||
CC = gcc
|
||||
CFLAGS = -std=c11 -D_POSIX_C_SOURCE=200809L -Wall -Wpedantic -g
|
||||
LD = gcc
|
||||
LDFLAGS =
|
||||
AR = ar
|
||||
ARFLAGS = rcs
|
||||
|
||||
|
||||
OBJS = obj/main.o
|
||||
DEPS = $(OBJS:%.o=%.d)
|
||||
|
||||
-include $(DEPS)
|
||||
|
||||
all: bf test
|
||||
|
||||
obj/%.o: src/%.c obj
|
||||
$(CC) $(CFLAGS) -c -o $@ $<
|
||||
|
||||
|
||||
bf: $(OBJS)
|
||||
$(LD) $(LDFLAGS) -o $@ $^
|
||||
|
||||
|
||||
test: bf
|
||||
./test/tests.sh "./bf"
|
||||
|
||||
|
||||
FORCE: ;
|
||||
|
||||
clean:
|
||||
@echo "Cleaning up"
|
||||
@rm -f obj/*.o
|
||||
@rm -f obj/*.d
|
||||
@rm bf
|
2
brainfuck/obj/.gitignore
vendored
Normal file
2
brainfuck/obj/.gitignore
vendored
Normal file
|
@ -0,0 +1,2 @@
|
|||
*.o
|
||||
*.d
|
1
brainfuck/test/cases/001-simple-hello-world.in
Normal file
1
brainfuck/test/cases/001-simple-hello-world.in
Normal file
|
@ -0,0 +1 @@
|
|||
++++++++++[>+++++++>++++++++++>+++>+<<<<-]>++.>+.+++++++..+++.>++.<<+++++++++++++++.>.+++.------.--------.>+.>.
|
0
brainfuck/test/cases/001-simple-hello-world.stderr
Normal file
0
brainfuck/test/cases/001-simple-hello-world.stderr
Normal file
0
brainfuck/test/cases/001-simple-hello-world.stdin
Normal file
0
brainfuck/test/cases/001-simple-hello-world.stdin
Normal file
1
brainfuck/test/cases/001-simple-hello-world.stdout
Normal file
1
brainfuck/test/cases/001-simple-hello-world.stdout
Normal file
|
@ -0,0 +1 @@
|
|||
Hello World!
|
1
brainfuck/test/cases/002-minimal-hello-world.in
Normal file
1
brainfuck/test/cases/002-minimal-hello-world.in
Normal file
|
@ -0,0 +1 @@
|
|||
+[>>>->-[>->----<<<]>>]>.---.>+..+++.>>.<.>>---.<<<.+++.------.<-.>>+.
|
0
brainfuck/test/cases/002-minimal-hello-world.stderr
Normal file
0
brainfuck/test/cases/002-minimal-hello-world.stderr
Normal file
0
brainfuck/test/cases/002-minimal-hello-world.stdin
Normal file
0
brainfuck/test/cases/002-minimal-hello-world.stdin
Normal file
1
brainfuck/test/cases/002-minimal-hello-world.stdout
Normal file
1
brainfuck/test/cases/002-minimal-hello-world.stdout
Normal file
|
@ -0,0 +1 @@
|
|||
hello, world!
|
18
brainfuck/test/generate-results.sh
Executable file
18
brainfuck/test/generate-results.sh
Executable file
|
@ -0,0 +1,18 @@
|
|||
#!/bin/sh
|
||||
|
||||
tmpfile1="/tmp/$$-1.tmp"
|
||||
tmpfile2="/tmp/$$-2.tmp"
|
||||
|
||||
ls cases/*.in test/cases/*.in | sed -E 's/.in$//g' | while read test; do
|
||||
brainfuck < "$test.in" > $tmpfile1 2> $tmpfile2
|
||||
if test ! -e "$test.stdout"; then
|
||||
cp "$tmpfile1" "$test.stdout"
|
||||
fi
|
||||
|
||||
if test ! -e "$test.stderr"; then
|
||||
cp "$tmpfile2" "$test.stderr"
|
||||
fi
|
||||
done
|
||||
|
||||
rm "$tmpfile1"
|
||||
rm "$tmpfile2"
|
48
brainfuck/test/tests.sh
Executable file
48
brainfuck/test/tests.sh
Executable file
|
@ -0,0 +1,48 @@
|
|||
#/bin/sh
|
||||
|
||||
executable="$1"
|
||||
|
||||
tmpfile1="/tmp/$$-1.tmp"
|
||||
tmpfile2="/tmp/$$-2.tmp"
|
||||
resultsfile="/tmp/$$.results"
|
||||
|
||||
touch "$resultsfile"
|
||||
|
||||
run_testcase() {
|
||||
test="$1"
|
||||
echo "Test: $test"
|
||||
|
||||
if "$executable" "$test.in" < "$test.stdin" > "$tmpfile1" 2> "$tmpfile2" ; then
|
||||
if diff -q "$test.stderr" "$tmpfile2" > /dev/null; then
|
||||
if diff -q "$test.stdout" "$tmpfile1" > /dev/null; then
|
||||
printf " \033[32msuccess\033[0m\n"
|
||||
echo "$test: success" >> "$resultsfile"
|
||||
else
|
||||
printf " \033[31mfailed with stdout diff\033[0m\n"
|
||||
echo "$test: fail" >> "$resultsfile"
|
||||
fi
|
||||
else
|
||||
printf " \033[31mfailed with stderr diff\033[0m\n"
|
||||
echo "$test: fail" >> "$resultsfile"
|
||||
fi
|
||||
else
|
||||
printf " \033[31mfailed with error\033[0m\n"
|
||||
echo "$test: fail" >> "$resultsfile"
|
||||
fi
|
||||
|
||||
rm "$tmpfile1";
|
||||
rm "$tmpfile2";
|
||||
}
|
||||
|
||||
ls cases/*.in test/cases/*.in | sed -E 's/.in$//g' | while read test; do
|
||||
run_testcase "$test"
|
||||
done
|
||||
|
||||
echo
|
||||
echo
|
||||
echo "$(cat "$resultsfile" | wc -l) tests in total"
|
||||
echo "$(grep ": fail" "$resultsfile" | wc -l) tests failed"
|
||||
echo "$(grep ": success" "$resultsfile" | wc -l) tests succeeded"
|
||||
echo
|
||||
|
||||
rm "$resultsfile"
|
Loading…
Reference in a new issue