From c4c753da12df4fb515ee1bddca2d6b498ea1af52 Mon Sep 17 00:00:00 2001 From: david parsons Date: Fri, 7 Sep 2018 15:41:40 -0700 Subject: [PATCH] add in a handful of test to verify that empty pandoc headers are not auto-populated with % --- Makefile.in | 7 +++- tests/functions.sh | 15 ++++--- tests/pandoc.t | 47 ++++++++++++++++++++++ tools/{check_pandoc.c => pandoc_headers.c} | 17 ++++---- 4 files changed, 69 insertions(+), 17 deletions(-) rename tools/{check_pandoc.c => pandoc_headers.c} (84%) diff --git a/Makefile.in b/Makefile.in index 6235e30..0f8b9b0 100644 --- a/Makefile.in +++ b/Makefile.in @@ -19,7 +19,7 @@ OBJS=mkdio.o markdown.o dumptree.o generate.o \ xml.o Csio.o xmlpage.o basename.o emmatch.o \ github_flavoured.o setup.o tags.o html5.o flags.o \ @AMALLOC@ @H1TITLE@ -TESTFRAMEWORK=echo cols branch +TESTFRAMEWORK=echo cols branch pandoc_headers # modules that markdown, makepage, mkd2html, &tc use COMMON=pgm_options.o gethopt.o notspecial.o @@ -118,10 +118,13 @@ verify: echo tools/checkbits.sh @./echo -n "headers ... "; tools/checkbits.sh && echo "GOOD" test: $(PGMS) $(TESTFRAMEWORK) verify - @for x in tests/*.t; do \ + @for x in $${TESTS:-tests/*.t}; do \ @LD_LIBRARY_PATH@=`pwd` sh $$x || exit 1; \ done +pandoc_headers: tools/pandoc_headers.c config.h + $(CC) $(CFLAGS) $(LFLAGS) -o pandoc_headers \ + tools/pandoc_headers.c $(COMMON) -lmarkdown branch: tools/branch.c config.h $(CC) -o branch tools/branch.c cols: tools/cols.c config.h diff --git a/tests/functions.sh b/tests/functions.sh index 3ca8656..714095c 100644 --- a/tests/functions.sh +++ b/tests/functions.sh @@ -27,6 +27,15 @@ summary() { } +try_header() { + testcase=`./echo -n " $1" '........................................................' | ./cols 50` + __tests=`expr $__tests + 1` + + test "$VERBOSE" && ./echo -n "$testcase" +} + + + try() { unset FLAGS while [ "$1" ]; do @@ -37,11 +46,7 @@ try() { esac done - testcase=`./echo -n " $1" '........................................................' | ./cols 50` - __tests=`expr $__tests + 1` - - - test "$VERBOSE" && ./echo -n "$testcase" + try_header $1 case "$2" in -t*) Q=`./markdown $FLAGS "$2"` ;; diff --git a/tests/pandoc.t b/tests/pandoc.t index 5d312c3..4b4f486 100644 --- a/tests/pandoc.t +++ b/tests/pandoc.t @@ -40,5 +40,52 @@ try 'indented header' \ % author(s) % date

' + +# verify that empty pandoc header elements are handled properly + +check_null() { + try_header "$3" + res=`echo "$2" | ./pandoc_headers $1` + if [ "$res" ]; then + ./echo + test $VERBOSE || ./echo "$3" + echo "$res" + else + test $VERBOSE && ./echo " ok" + fi +} + +# pandoc headers left empty +EMPTY='% +% +% +stuff' + +# pandoc headers with whitespace, but no content +EMPTY1='% +% +% +stuff' + +AUTHOR='% +% bofh +% +stuff' +TITLE='%bofh +% +% +stuff' +DATE='% +% +%now +stuff' + +check_null -atd "$EMPTY" "empty" +check_null -atd "$EMPTY1" "whitespace" + +check_null -td "$AUTHOR" "author field" +check_null -ad "$TITLE" "title field" +check_null -at "$DATE" "date field" + summary $0 exit $rc diff --git a/tools/check_pandoc.c b/tools/pandoc_headers.c similarity index 84% rename from tools/check_pandoc.c rename to tools/pandoc_headers.c index 48577a4..c991c42 100644 --- a/tools/check_pandoc.c +++ b/tools/pandoc_headers.c @@ -26,7 +26,7 @@ #include "amalloc.h" #include "gethopt.h" -char *pgm = "check pandoc"; +char *pgm = "pandoc headers"; void fail(char *why, ...) @@ -82,19 +82,16 @@ char **argv; fail("could not compile input?"); if (show_author) { - res = mkd_doc_author(p); - printf("author:"); if ( res ) printf("%s", res); - putchar('\n'); + if ( res = mkd_doc_author(p) ) + printf("author: %s\n", res); } if (show_title) { - res = mkd_doc_title(p); - printf("title :"); if ( res ) printf("%s", res); - putchar('\n'); + if ( res = mkd_doc_title(p) ) + printf("title : %s\n", res); } if (show_date) { - res = mkd_doc_date(p); - printf("date :"); if ( res ) printf("%s", res); - putchar('\n'); + if ( res = mkd_doc_date(p) ) + printf("date : %s\n", res); } mkd_cleanup(p); exit(0);