diff --git a/tests/autolink.t b/tests/autolink.t index a471fea..b19dcb3 100644 --- a/tests/autolink.t +++ b/tests/autolink.t @@ -1,28 +1,8 @@ -./echo 'Reddit-style automatic links' +. tests/functions.sh + +title 'Reddit-style automatic links' rc=0 -try() { - unset FLAGS - case "$1" in - -*) FLAGS=$1 - shift ;; - esac - - ./echo -n " $1" '..................................' | ./cols 36 - - Q=`./echo "$2" | ./markdown $FLAGS` - - - if [ "$3" = "$Q" ]; then - ./echo " ok" - else - ./echo " FAILED" - ./echo "wanted: $3" - ./echo "got : $Q" - rc=1 - fi -} - try -fautolink 'single link' \ 'http://www.pell.portland.or.us/~orc/Code/discount' \ '
http://www.pell.portland.or.us/~orc/Code/discount
' @@ -43,4 +23,5 @@ try -fautolink 'parenthesised (url)' \ try -fautolink 'token with trailing @' 'orc@' 'orc@
' +summary $0 exit $rc diff --git a/tests/automatic.t b/tests/automatic.t index 89c3e6a..2d91032 100644 --- a/tests/automatic.t +++ b/tests/automatic.t @@ -1,41 +1,10 @@ -./echo "automatic links" +. tests/functions.sh + +title "automatic links" rc=0 MARKDOWN_FLAGS= -try() { - unset FLAGS - case "$1" in - -*) FLAGS=$1 - shift ;; - esac - - ./echo -n " $1" '..................................' | ./cols 36 - - Q=`./echo "$2" | ./markdown $FLAGS` - - - if [ "$3" = "$Q" ]; then - ./echo " ok" - else - ./echo " FAILED" - ./echo "wanted: $3" - ./echo "got : $Q" - rc=1 - fi -} - -match() { - ./echo -n " $1" '..................................' | ./cols 36 - - if ./echo "$2" | ./markdown | grep "$3" >/dev/null; then - ./echo " ok" - else - ./echo " FAILED" - rc=1 - fi -} - try 'http url' '`hi there
' try 'unclosed double backtick' '``hi there' '``hi there
' try 'remove space around code' '`` hi there ``' 'hi there
white space''
and more
'
+summary $0
exit $rc
diff --git a/tests/crash.t b/tests/crash.t
index c0443ee..b553ce5 100644
--- a/tests/crash.t
+++ b/tests/crash.t
@@ -1,57 +1,30 @@
-./echo "crashes"
+. tests/functions.sh
+
+title "crashes"
rc=0
MARKDOWN_FLAGS=
-./echo -n ' zero-length input ................ '
+try 'zero-length input' '' ''
-if ./markdown < /dev/null >/dev/null; then
- ./echo "ok"
-else
- ./echo "FAILED"
- rc=1
-fi
+try 'hanging quote in list' \
+' * > this should not die
-./echo -n ' hanging quote in list ............ '
+no.' \
+'this should not die
no.
' -if [ "$?" -eq 0 ]; then - ./echo "ok" -else - ./echo "FAILED" - rc=1 -fi +try 'dangling list item' ' - ' \ +'more
hi
' try '* -> *' 'A * A' 'A * A
' try -fstrict '***A**B*' '***A**B*' 'AB
' @@ -37,4 +17,5 @@ if ./markdown -V | grep RELAXED >/dev/null; then try -fstrict '_A_B with -fstrict' '_A_B' 'AB
' fi +summary $0 exit $rc diff --git a/tests/flow.t b/tests/flow.t index 3541727..44cf53a 100644 --- a/tests/flow.t +++ b/tests/flow.t @@ -1,30 +1,10 @@ -./echo "paragraph flow" +. tests/functions.sh + +title "paragraph flow" rc=0 MARKDOWN_FLAGS= -try() { - unset FLAGS - case "$1" in - -*) FLAGS=$1 - shift ;; - esac - - ./echo -n " $1" '..................................' | ./cols 36 - - Q=`./echo "$2" | ./markdown $FLAGS` - - - if [ "$3" = "$Q" ]; then - ./echo " ok" - else - ./echo " FAILED" - ./echo "wanted: $3" - ./echo "got : $Q" - rc=1 - fi -} - try 'header followed by paragraph' \ '###Hello, sailor### And how are you today?' \ @@ -49,4 +29,5 @@ try 'two lists punctuated with a HR' \[a][] [b][]:
' try 'a valid footnote' \ '[alink][] @@ -31,4 +12,5 @@ try 'a valid footnote' \ [alink]: link_me' \ '' +summary $0 exit $rc diff --git a/tests/functions.sh b/tests/functions.sh new file mode 100644 index 0000000..745cc80 --- /dev/null +++ b/tests/functions.sh @@ -0,0 +1,77 @@ +__tests=0 +__passed=0 +__failed=0 +__title= + +title() { + __title="$*" + if [ "$VERBOSE" ]; then + ./echo "$__title" + else + ./echo -n "$__title" \ +'.................................................................' | ./cols 54 + fi +} + + +summary() { + if [ -z "$VERBOSE" ]; then + if [ $__failed -eq 0 ]; then + ./echo " OK" + else + ./echo + ./echo "$1: $__tests tests; $__failed failed/$__passed passed" + ./echo + fi + fi +} + + +try() { + unset FLAGS + case "$1" in + -*) FLAGS=$1 + shift ;; + esac + + testcase=`./echo -n " $1" '..................................' | ./cols 36` + __tests=`expr $__tests + 1` + + + test "$VERBOSE" && ./echo -n "$testcase" + + case "$2" in + -t*) Q=`./markdown $FLAGS "$2"` ;; + *) Q=`./echo "$2" | ./markdown $FLAGS` ;; + esac + + if [ "$3" = "$Q" ]; then + __passed=`expr $__passed + 1` + test $VERBOSE && ./echo " ok" + else + __failed=`expr $__failed + 1` + if [ -z "$VERBOSE" ]; then + ./echo + ./echo "$1" + fi + ./echo "wanted: $3" + ./echo "got : $Q" + rc=1 + fi +} + +match() { + testcase=`./echo -n " $1" '..................................' | ./cols 36` + + test $VERBOSE && ./echo -n "$testcase" + + if ./echo "$2" | ./markdown | grep "$3" >/dev/null; then + test $VERBOSE && ./echo " ok" + else + if [ -z "$VERBOSE" ]; then + ./echo + ./echo "$testcase" + fi + rc=1 + fi +} diff --git a/tests/header.t b/tests/header.t index aaab824..d72a516 100644 --- a/tests/header.t +++ b/tests/header.t @@ -1,31 +1,10 @@ -./echo "headers" +. tests/functions.sh + +title "headers" rc=0 MARKDOWN_FLAGS= -try() { - unset FLAGS - case "$1" in - -*) FLAGS=$1 - shift ;; - esac - - S=`./echo -n "$1" '..................................' | ./cols 34` - ./echo -n " $S " - - Q=`./echo "$2" | ./markdown $FLAGS` - - - if [ "$3" = "$Q" ]; then - ./echo "ok" - else - ./echo "FAILED" - ./echo "wanted: $3" - ./echo "got : $Q" - rc=1 - fi -} - try 'single #' '#' '#
' try 'empty ETX' '##' '[test] (me)
' +summary $0 exit $rc diff --git a/tests/linkypix.t b/tests/linkypix.t index 8ecfd41..5c7572a 100644 --- a/tests/linkypix.t +++ b/tests/linkypix.t @@ -1,29 +1,10 @@ -./echo "embedded images" +. tests/functions.sh + +title "embedded images" rc=0 MARKDOWN_FLAGS= -try() { - unset FLAGS - case "$1" in - -*) FLAGS=$1 - shift ;; - esac - - ./echo -n " $1" '..................................' | ./cols 36 - - Q=`./echo "$2" | ./markdown $FLAGS` - - if [ "$3" = "$Q" ]; then - ./echo " ok" - else - ./echo " FAILED" - ./echo "wanted: $3" - ./echo "got : $Q" - rc=1 - fi -} - try 'image with size extension' \ '' \ 'AAA
' try '< -> <' '<' '<
' try '`>` ->>' '`>`' '>
`' '`` ` ``' '`
a
' +summary $0 exit $rc diff --git a/tests/paranoia.t b/tests/paranoia.t index f2b1024..a12147b 100644 --- a/tests/paranoia.t +++ b/tests/paranoia.t @@ -1,31 +1,12 @@ -./echo "paranoia" +. tests/functions.sh + +title "paranoia" rc=0 MARKDOWN_FLAGS= -try() { - unset FLAGS - case "$1" in - -*) FLAGS=$1 - shift ;; - esac - - ./echo -n " $1" '..................................' | ./cols 36 - - Q=`./echo "$2" | ./markdown $FLAGS` - - - if [ "$3" = "$Q" ]; then - ./echo " ok" - else - ./echo " FAILED" - ./echo "wanted: $3" - ./echo "got : $Q" - rc=1 - fi -} - try -fsafelink 'bogus url (-fsafelink)' '[test](bad:protocol)' '[test](bad:protocol)
' try -fnosafelink 'bogus url (-fnosafelink)' '[test](bad:protocol)' '' +summary $0 exit $rc diff --git a/tests/peculiarities.t b/tests/peculiarities.t index 8a199bd..3f3b63b 100644 --- a/tests/peculiarities.t +++ b/tests/peculiarities.t @@ -1,29 +1,10 @@ -./echo "markup peculiarities" +. tests/functions.sh + +title "markup peculiarities" rc=0 MARKDOWN_FLAGS= -try() { - unset FLAGS - case "$1" in - -*) FLAGS=$1 - shift ;; - esac - - ./echo -n " $1" '..................................' | ./cols 36 - - Q=`./echo "$2" | ./markdown $FLAGS` - - if [ "$3" = "$Q" ]; then - ./echo " ok" - else - ./echo " FAILED" - ./echo "wanted: $3" - ./echo "got : $Q" - rc=1 - fi -} - try 'list followed by header .......... ' \ " - AAA @@ -63,4 +44,5 @@ try -fnohtml 'markdownfoo
is
[foo](id:bar)
' try '[](class:) links' '[foo](class:bar)' '' @@ -32,4 +12,5 @@ try -fnoext '[](class:) links with -fnoext' '[foo](class:bar)' '
[foo](class:b try '[](raw:) links' '[foo](raw:bar)' '
bar
' try -fnoext '[](raw:) links with -fnoext' '[foo](raw:bar)' '[foo](raw:bar)
' +summary $0 exit $rc diff --git a/tests/reddit.t b/tests/reddit.t index 9552885..268cbcf 100644 --- a/tests/reddit.t +++ b/tests/reddit.t @@ -1,31 +1,10 @@ -./echo "bugs & misfeatures found during the Reddit rollout" +. tests/functions.sh + +title "bugs & misfeatures found during the Reddit rollout" rc=0 MARKDOWN_FLAGS= -try() { - unset FLAGS - case "$1" in - -*) FLAGS=$1 - shift ;; - esac - - S=`./echo -n "$1" '..................................' | ./cols 34` - ./echo -n " $S " - - Q=`./echo "$2" | ./markdown $FLAGS` - - - if [ "$3" = "$Q" ]; then - ./echo "ok" - else - ./echo "FAILED" - ./echo "wanted: $3" - ./echo "got : $Q" - rc=1 - fi -} - try 'smiley faces?' '[8-9] <]:-( x ---> [4]' \ '[8-9] <]:–( x —–> [4]
' @@ -44,4 +23,5 @@ try 'unescaping " " inside []()' \ bar)' \ '' +summary $0 exit $rc diff --git a/tests/reparse.t b/tests/reparse.t index b6bebd8..93e11b5 100644 --- a/tests/reparse.t +++ b/tests/reparse.t @@ -1,34 +1,14 @@ -./echo "footnotes inside reparse sections" +. tests/functions.sh + +title "footnotes inside reparse sections" rc=0 -try() { - unset FLAGS - case "$1" in - -*) FLAGS=$1 - shift ;; - esac - - ./echo -n " $1" '..................................' | ./cols 36 - - Q=`./echo "$2" | ./markdown $FLAGS` - - - if [ "$3" = "$Q" ]; then - ./echo " ok" - else - ./echo " FAILED" - ./echo "wanted: $3" - ./echo "got : $Q" - rc=1 - fi -} - - try 'footnote inside [] section' \ '[![foo][]](bar) [foo]: bar2' \ '' +summary $0 exit $rc diff --git a/tests/schiraldi.t b/tests/schiraldi.t index 2d90813..3af2f68 100644 --- a/tests/schiraldi.t +++ b/tests/schiraldi.t @@ -1,31 +1,10 @@ -./echo "Bugs & misfeatures reported by Mike Schiraldi" +. tests/functions.sh + +title "Bugs & misfeatures reported by Mike Schiraldi" rc=0 MARKDOWN_FLAGS= -try() { - unset FLAGS - case "$1" in - -*) FLAGS=$1 - shift ;; - esac - - S=`./echo -n "$1" '..................................' | ./cols 34` - ./echo -n " $S " - - Q=`./echo "$2" | ./markdown $FLAGS` - - - if [ "$3" = "$Q" ]; then - ./echo "ok" - else - ./echo "FAILED" - ./echo "wanted: $3" - ./echo "got : $Q" - rc=1 - fi -} - try -fnohtml 'breaks with -fnohtml' 'foo bar' 'foo
bar
©
' try '(r) -> ®' '(r)' '®
' try '(tm) -> ™' '(tm)' '™
' @@ -47,4 +26,5 @@ if ./markdown -V | grep SUPERSCRIPT >/dev/null; then try -frelax 'A^B in link title' '[link](here "A^B")' '' fi +summary $0 exit $rc diff --git a/tests/snakepit.t b/tests/snakepit.t index 886806f..447da60 100644 --- a/tests/snakepit.t +++ b/tests/snakepit.t @@ -1,30 +1,10 @@ -./echo "The snakepit of Markdown.pl compatability" +. tests/functions.sh + +title "The snakepit of Markdown.pl compatability" rc=0 MARKDOWN_FLAGS= -try() { - unset FLAGS - case "$1" in - -*) FLAGS=$1 - shift ;; - esac - - ./echo -n " $1" '..................................' | ./cols 36 - - Q=`./echo "$2" | ./markdown $FLAGS` - - - if [ "$3" = "$Q" ]; then - ./echo " ok" - else - ./echo " FAILED" - ./echo "wanted: $3" - ./echo "got : $Q" - rc=1 - fi -} - try '[](single quote) text (quote)' \ "[foo](http://Poe's law) will make this fail ('no, it won't!') here."\ 'foo here.
' @@ -42,4 +22,5 @@ try 'EOF
' +summary $0 exit $rc diff --git a/tests/style.t b/tests/style.t index 5e2a735..62303c9 100644 --- a/tests/style.t +++ b/tests/style.t @@ -1,32 +1,17 @@ -./echo "styles" +. tests/functions.sh + +title "styles" rc=0 MARKDOWN_FLAGS= -./echo -n ' ' | ./markdown|wc -c` - -if [ $count -eq 1 ]; then - ./echo "ok" -else - ./echo "FAILED" - rc=1 -fi - -./echo -n ' ' '' ASK='' -count=`./echo "$ASK" | ./markdown | wc -c` - -if [ $count -eq 1 ]; then - ./echo "ok" -else - ./echo "FAILED" - rc=1 -fi +try '