From eba54eb5769075d29f21f11cbb011f6d537d9f8c Mon Sep 17 00:00:00 2001 From: John MacFarlane Date: Thu, 11 Jun 2015 08:01:07 -0700 Subject: 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. --- test/pathological_tests.py | 44 +++++++++++++++++++++++++++++--------------- 1 file changed, 29 insertions(+), 15 deletions(-) (limited to 'test/pathological_tests.py') 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) -- cgit v1.2.3