summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorJohn MacFarlane <jgm@berkeley.edu>2016-06-02 10:43:47 -0700
committerJohn MacFarlane <jgm@berkeley.edu>2016-06-02 10:45:19 -0700
commit8a53ee9b579fef9a75bd25f881827f28739a1f68 (patch)
treea921525ef8a37e0e147f2b203acc2f951de7b28d /test
parentf4a82cf6a5f553c2c886de02c23b41f06f8a19c6 (diff)
Added new roundtrip_tests.py.
This replaces the old use of simple shell scripts. It is much faster, and more flexible. (We will be able to do custom normalization and skip certain tests.)
Diffstat (limited to 'test')
-rwxr-xr-xtest/CMakeLists.txt7
-rwxr-xr-xtest/roundtrip.bat1
-rwxr-xr-xtest/roundtrip.sh2
-rw-r--r--test/roundtrip_tests.py38
4 files changed, 42 insertions, 6 deletions
diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt
index 09af8a4..dd850b6 100755
--- a/test/CMakeLists.txt
+++ b/test/CMakeLists.txt
@@ -48,9 +48,10 @@ IF (PYTHONINTERP_FOUND)
add_test(roundtriptest_executable
${PYTHON_EXECUTABLE}
- "${CMAKE_CURRENT_SOURCE_DIR}/spec_tests.py" "--no-normalize"
- "--spec" "${CMAKE_CURRENT_SOURCE_DIR}/spec.txt" "--program"
- "${ROUNDTRIP} ${CMAKE_CURRENT_BINARY_DIR}/../src/cmark"
+ "${CMAKE_CURRENT_SOURCE_DIR}/roundtrip_tests.py"
+ "--spec" "${CMAKE_CURRENT_SOURCE_DIR}/spec.txt"
+ "--no-normalize"
+ "--library-dir" "${CMAKE_CURRENT_BINARY_DIR}/../src"
)
add_test(regressiontest_executable
diff --git a/test/roundtrip.bat b/test/roundtrip.bat
deleted file mode 100755
index ac4c9ed..0000000
--- a/test/roundtrip.bat
+++ /dev/null
@@ -1 +0,0 @@
-"%1" -t commonmark | "%1"
diff --git a/test/roundtrip.sh b/test/roundtrip.sh
deleted file mode 100755
index ec4f135..0000000
--- a/test/roundtrip.sh
+++ /dev/null
@@ -1,2 +0,0 @@
-#!/bin/sh
-"$1" -t commonmark | "$1"
diff --git a/test/roundtrip_tests.py b/test/roundtrip_tests.py
new file mode 100644
index 0000000..8becb08
--- /dev/null
+++ b/test/roundtrip_tests.py
@@ -0,0 +1,38 @@
+import sys
+from spec_tests import get_tests, do_test
+from cmark import CMark
+import argparse
+
+if __name__ == "__main__":
+ parser = argparse.ArgumentParser(description='Run cmark roundtrip tests.')
+ parser.add_argument('-p', '--program', dest='program', nargs='?', default=None,
+ help='program to test')
+ parser.add_argument('-s', '--spec', dest='spec', nargs='?', default='spec.txt',
+ help='path to spec')
+ parser.add_argument('-P', '--pattern', dest='pattern', nargs='?',
+ default=None, help='limit to sections matching regex pattern')
+ parser.add_argument('--library-dir', dest='library_dir', nargs='?',
+ default=None, help='directory containing dynamic library')
+ parser.add_argument('--no-normalize', dest='normalize',
+ action='store_const', const=False, default=True,
+ help='do not normalize HTML')
+ parser.add_argument('-n', '--number', type=int, default=None,
+ help='only consider the test with the given number')
+ args = parser.parse_args(sys.argv[1:])
+
+spec = sys.argv[1]
+
+def converter(md):
+ cmark = CMark(prog=args.program, library_dir=args.library_dir)
+ [ec, result, err] = cmark.to_commonmark(md)
+ if ec == 0:
+ return cmark.to_html(result)
+ else:
+ return [ec, result, err]
+
+tests = get_tests(args.spec)
+result_counts = {'pass': 0, 'fail': 0, 'error': 0, 'skip': 0}
+for test in tests:
+ do_test(converter, test, args.normalize, result_counts)
+
+exit(result_counts['fail'] + result_counts['error'])