Add Bash test runner

This commit is contained in:
Craig Barnes 2014-01-23 03:30:46 +00:00
parent e3d177ae67
commit 6621d8ef36
2 changed files with 38 additions and 1 deletions

View file

@ -14,7 +14,7 @@ HOEDOWN_SRC=\
src/markdown.o \ src/markdown.o \
src/stack.o src/stack.o
.PHONY: all test clean .PHONY: all test test-pl clean
all: libhoedown.so hoedown smartypants all: libhoedown.so hoedown smartypants
@ -45,6 +45,9 @@ src/html_blocks.c: html_block_names.gperf
# Testing # Testing
test: hoedown test: hoedown
test/runner.bash ./hoedown test/MarkdownTest_1.0.3/Tests
test-pl: hoedown
perl test/MarkdownTest_1.0.3/MarkdownTest.pl \ perl test/MarkdownTest_1.0.3/MarkdownTest.pl \
--script=./hoedown --testdir=test/MarkdownTest_1.0.3/Tests --tidy --script=./hoedown --testdir=test/MarkdownTest_1.0.3/Tests --tidy

34
test/runner.bash Executable file
View file

@ -0,0 +1,34 @@
#!/bin/bash
TIDY='tidy --show-body-only 1 --quiet 1 --show-warnings 0'
SCRIPT="$1"
TESTDIR="$2"
PASSED=0
FAILED=0
abort() {
echo "Error: $*"
exit 1
}
test -f "$SCRIPT" || abort "argument #1 invalid; not a file"
test -x "$SCRIPT" || abort "argument #1 invalid; not executable"
"$SCRIPT" <<< "" || abort "argument #1 invalid; script failed to run"
test -d "$TESTDIR" || abort "argument #2 invalid; not a directory"
for TEXT in "$TESTDIR"/*.text; do
test -f "$TEXT" || abort "empty or invalid test directory"
printf "$(basename "$TEXT" .text) ... "
HTML="${TEXT/%.text/.html}"
DIFF=`diff <($SCRIPT "$TEXT" | $TIDY) <($TIDY "$HTML")`
if test $? == 0; then
((PASSED++))
echo OK
else
((FAILED++))
echo FAILED
printf "\n$DIFF\n\n"
fi
done
printf "\n\n$PASSED passed; $FAILED failed.\n"