summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn MacFarlane <jgm@berkeley.edu>2014-11-27 12:23:47 -0800
committerJohn MacFarlane <jgm@berkeley.edu>2014-11-27 12:25:20 -0800
commitf320d9f9ea2f983d9a0f5d01f1235eef1df28f37 (patch)
treeae4c04f75e82d293609b865c255dcc03fdf1003f
parentab37be988c414646fa4813af9cf1ee0823a436fe (diff)
Added pathological_tests.py to test suite.
-rw-r--r--CMakeLists.txt4
-rw-r--r--pathological_tests.py82
2 files changed, 86 insertions, 0 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index e554266..2eb9815 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -26,6 +26,10 @@ add_test(spectest_library
python "${CMAKE_SOURCE_DIR}/runtests.py" "--no-normalize" "--spec"
"${CMAKE_SOURCE_DIR}/spec.txt" "--library-dir" "${CMAKE_BINARY_DIR}/src"
)
+add_test(pathological_tests_library
+ python "${CMAKE_SOURCE_DIR}/pathological_tests.py"
+ "--library-dir" "${CMAKE_BINARY_DIR}/src"
+)
add_test(NAME api_test COMMAND api_test)
if (WIN32)
file(TO_NATIVE_PATH ${CMAKE_BINARY_DIR}/src WIN_DLL_DIR)
diff --git a/pathological_tests.py b/pathological_tests.py
new file mode 100644
index 0000000..999a467
--- /dev/null
+++ b/pathological_tests.py
@@ -0,0 +1,82 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+
+from ctypes import CDLL, c_char_p, c_long
+from subprocess import *
+import re
+import argparse
+import sys
+import platform
+
+if __name__ == "__main__":
+ parser = argparse.ArgumentParser(description='Run cmark tests.')
+ parser.add_argument('--program', dest='program', nargs='?', default=None,
+ help='program to test')
+ parser.add_argument('--library-dir', dest='library_dir', nargs='?',
+ default=None, help='directory containing dynamic library')
+ args = parser.parse_args(sys.argv[1:])
+
+if not args.program:
+ sysname = platform.system()
+ libname = "libcmark"
+ if sysname == 'Darwin':
+ libname += ".dylib"
+ elif sysname == 'Windows':
+ libname += ".dll"
+ else:
+ libname += ".so"
+ if args and args.library_dir:
+ libpath = args.library_dir + "/" + libname
+ else:
+ libpath = "build/src/" + libname
+ cmark = CDLL(libpath)
+
+ markdown = cmark.cmark_markdown_to_html
+ markdown.restype = c_char_p
+ markdown.argtypes = [c_char_p, c_long]
+
+def md2html(text, prog):
+ if prog:
+ p1 = Popen(prog.split(), stdout=PIPE, stdin=PIPE, stderr=PIPE)
+ [result, err] = p1.communicate(input=text)
+ return [p1.returncode, result, err]
+ else:
+ return [0, markdown(text, len(text)), '']
+
+pathological = {
+ "nested strong emph":
+ (("*a **a " * 100000) + "b" + (" a** a*" * 100000),
+ "<p>" + ("<em>a <strong>a " * 100000) + "b" +
+ (" a</strong> a</em>" * 100000) + "</p>"),
+ "nested brackets":
+ (("[" * 50000) + "a" + ("]" * 50000),
+ "<p>" + ("[" * 50000) + "a" + ("]" * 50000) + "</p>")
+ }
+
+whitespace_re = re.compile('/s+/')
+passed = 0
+errored = 0
+failed = 0
+
+print "Testing pathological cases:"
+for description in pathological:
+ print description
+ (inp, expected) = pathological[description]
+ [rc, actual, err] = md2html(inp, args.program)
+ if rc != 0:
+ errored += 1
+ print description
+ print "program returned error code %d" % rc
+ print(err)
+ elif whitespace_re.sub(' ', actual.rstrip()) == expected.rstrip():
+ passed += 1
+ else:
+ print description, 'failed'
+ print(actual)
+ failed += 1
+
+print "%d passed, %d failed, %d errored" % (passed, failed, errored)
+if (failed == 0 and errored == 0):
+ exit(0)
+else:
+ exit(1)