diff options
author | John MacFarlane <jgm@berkeley.edu> | 2015-06-11 08:01:07 -0700 |
---|---|---|
committer | John MacFarlane <jgm@berkeley.edu> | 2015-06-11 08:01:07 -0700 |
commit | eba54eb5769075d29f21f11cbb011f6d537d9f8c (patch) | |
tree | d00782789876f852a212da84b6f76fb03c974009 /test | |
parent | 1bdb53d28f75db491e4706932fe0efd023f14d9f (diff) |
Added timetouts to pathological tests.
This way tests fail instead of just hanging.
Currently we use a 1 sec timeout.
Added a failing test from jgm/commonmark#43.
Diffstat (limited to 'test')
-rw-r--r-- | test/pathological_tests.py | 44 |
1 files changed, 29 insertions, 15 deletions
diff --git a/test/pathological_tests.py b/test/pathological_tests.py index 6e207ce..3b3374b 100644 --- a/test/pathological_tests.py +++ b/test/pathological_tests.py @@ -6,6 +6,8 @@ import argparse import sys import platform from cmark import CMark +from multiprocessing import Process, Value +import time if __name__ == "__main__": parser = argparse.ArgumentParser(description='Run cmark tests.') @@ -35,6 +37,9 @@ pathological = { "many link openers with no closers": (("[a" * 65000), re.compile("(\[a){65000}")), + "mismatched openers and closers": + (("*a_ " * 50000), + re.compile("([*]a[_] ){49999}[*]a_")), "nested brackets": (("[" * 50000) + "a" + ("]" * 50000), re.compile("\[{50000}a\]{50000}")), @@ -47,29 +52,38 @@ pathological = { } whitespace_re = re.compile('/s+/') -passed = 0 -errored = 0 -failed = 0 +passed = Value('i', 0) +errored = Value('i', 0) +failed = Value('i', 0) -print("Testing pathological cases:") -for description in pathological: - print(description) - (inp, regex) = pathological[description] +def do_cmark_test(inp, regex, passed, errored, failed): [rc, actual, err] = cmark.to_html(inp) if rc != 0: - errored += 1 - print(description) - print("program returned error code %d" % rc) + errored.value += 1 + print(description, '[ERRORED (return code %d)]' %rc) print(err) elif regex.search(actual): - passed += 1 + print(description, '[PASSED]') + passed.value += 1 else: - print(description, 'failed') + print(description, '[FAILED]') print(repr(actual)) - failed += 1 + failed.value += 1 + +print("Testing pathological cases:") +for description in pathological: + (inp, regex) = pathological[description] + p = Process(target=do_cmark_test, args=(inp, regex, passed, errored, failed)) + p.start() + p.join(1) + if p.is_alive(): + print(description, '[FAILED (timed out)]') + p.terminate() + p.join() + failed.value += 1 -print("%d passed, %d failed, %d errored" % (passed, failed, errored)) -if (failed == 0 and errored == 0): +print("%d passed, %d failed, %d errored" % (passed.value, failed.value, errored.value)) +if (failed.value == 0 and errored.value == 0): exit(0) else: exit(1) |