mirror of
https://github.com/sigmasternchen/macrofuck
synced 2025-03-15 07:08:56 +00:00
feat: Add testing setup
This commit is contained in:
parent
aef64e273e
commit
65fa917001
3 changed files with 46 additions and 2 deletions
6
Makefile
6
Makefile
|
@ -30,8 +30,10 @@ obj/%.o: src/%.c obj
|
|||
macrofuck: $(OBJS)
|
||||
$(LD) $(LDFLAGS) -o $@ $^
|
||||
|
||||
test:
|
||||
@echo "Not yet implemented"
|
||||
test: macrofuck FORCE
|
||||
./test/tests.sh "./macrofuck"
|
||||
|
||||
FORCE: ;
|
||||
|
||||
clean:
|
||||
@echo "Cleaning up"
|
||||
|
|
2
test/cases/001-print-char.in
Normal file
2
test/cases/001-print-char.in
Normal file
|
@ -0,0 +1,2 @@
|
|||
print 'A';
|
||||
|
40
test/tests.sh
Executable file
40
test/tests.sh
Executable file
|
@ -0,0 +1,40 @@
|
|||
#/bin/sh
|
||||
|
||||
executable="$1"
|
||||
|
||||
tmpfile="/tmp/$$.tmp"
|
||||
resultsfile="/tmp/$$.results"
|
||||
touch "$resultsfile"
|
||||
|
||||
run_testcase() {
|
||||
test="$1"
|
||||
echo "Test: $test"
|
||||
|
||||
if "$executable" -o "$tmpfile" "$test.in"; then
|
||||
if diff -q "$test.out" "$tmpfile" > /dev/null; then
|
||||
printf " \033[32msuccess\033[0m\n"
|
||||
echo "$test: success" >> "$resultsfile"
|
||||
else
|
||||
printf " \033[31mfailed with diff\033[0m\n"
|
||||
echo "$test: fail" >> "$resultsfile"
|
||||
fi
|
||||
else
|
||||
printf " \033[31mfailed with error\033[0m\n"
|
||||
echo "$test: fail" >> "$resultsfile"
|
||||
fi
|
||||
|
||||
rm "$tmpfile";
|
||||
}
|
||||
|
||||
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