Repository navigation
Expand file tree
/
Copy pathpathological-tests.py
More file actions
187 lines (178 loc) · 6.9 KB
/
Copy pathpathological-tests.py
File metadata and controls
187 lines (178 loc) · 6.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import argparse
import itertools
import multiprocessing
import re
import sys
import queue
from prog import Prog
from timeit import default_timer as timer
# list of pairs consisting of input and a regex that must match the output.
pathological = {
# note - some pythons have limit of 65535 for {num-matches} in re.
"U+0000":
("abc\u0000de\u0000",
re.compile("abc\ufffd?de\ufffd?")),
"CR and CR+LF line endings":
("# h1\r\n\r\na\rb\r\n\r- x\r\n- y\r",
re.compile("^<h1>h1</h1>\r?\n<p>a\r?\nb</p>\r?\n<ul>\r?\n<li>x</li>\r?\n<li>y</li>\r?\n</ul>\r?\n$")),
"U+FEFF (Unicode BOM)":
("\ufefffoo",
re.compile("<p>foo</p>")),
"nested strong emph":
(("*a **a " * 65000) + "b" + (" a** a*" * 65000),
re.compile("(<em>a <strong>a ){65000}b( a</strong> a</em>){65000}")),
"many emph closers with no openers":
(("a_ " * 65000),
re.compile("(a[_] ){64999}a_")),
"many emph openers with no closers":
(("_a " * 65000),
re.compile("(_a ){64999}_a")),
"many 3-emph openers with no closers":
(("a***" * 65000),
re.compile("(a<em><strong>a</strong></em>){32500}")),
"many link closers with no openers":
(("a]" * 65000),
re.compile(r"(a\]){65000}")),
"many link openers with no closers":
(("[a" * 65000),
re.compile(r"(\[a){65000}")),
"mismatched openers and closers":
(("*a_ " * 50000),
re.compile("([*]a[_] ){49999}[*]a_")),
"openers and closers multiple of 3":
(("a**b" + ("c* " * 50000)),
re.compile("a[*][*]b(c[*] ){49999}c[*]")),
"link openers and emph closers":
(("[ a_" * 50000),
re.compile(r"(\[ a_){50000}")),
"hard link/emph case":
("**x [a*b**c*](d)",
re.compile("\\*\\*x <a href=\"d\">a<em>b\\*\\*c</em></a>")),
"nested brackets":
(("[" * 50000) + "a" + ("]" * 50000),
re.compile(r"\[{50000}a\]{50000}")),
"nested block quotes":
((("> " * 50000) + "a"),
re.compile("(<blockquote>\r?\n){50000}")),
"backticks":
("".join(map(lambda x: ("e" + "`" * x), range(1,1000))),
re.compile("^<p>[e`]*</p>\r?\n$")),
"many links":
("[t](/u) " * 50000,
re.compile("(<a href=\"/u\">t</a> ?){50000}")),
"many references":
("".join(map(lambda x: ("[" + str(x) + "]: u\n"), range(1,20000 * 16))) + "[0] " * 20000,
re.compile(r"(\[0\] ){19999}")),
"deeply nested lists":
("".join(map(lambda x: (" " * x + "* a\n"), range(0,1000))),
re.compile("<ul>\r?\n(<li>a<ul>\r?\n){999}<li>a</li>\r?\n</ul>\r?\n(</li>\r?\n</ul>\r?\n){999}")),
"many html openers and closers":
(("<>" * 50000),
re.compile("(<>){50000}")),
"many html proc. inst. openers":
(("x" + "<?" * 50000),
re.compile("x(<\\?){50000}")),
"many html CDATA openers":
(("x" + "<,
re.compile(r"(\[ \(\]\(){50000}")),
"broken thematic break":
(("* " * 50000 + "a"),
re.compile("<ul>\r?\n(<li><ul>\r?\n){49999}<li>a</li>\r?\n</ul>\r?\n(</li>\r?\n</ul>\r?\n){49999}")),
"nested invalid link references":
(("[" * 50000 + "]" * 50000 + "\n\n[a]: /b"),
re.compile(r"\[{50000}\]{50000}")),
"many broken permissive autolinks":
(("www._" * 50000 + "x"),
re.compile("<p>(www._){50000}x</p>"),
"--fpermissive-www-autolinks"),
"huge table":
(("th|" * 10000 + "\n" + "-|" * 10000 + "\n" + "td\n" * 10000),
re.compile(""),
"--ftables"),
"many broken links":
(("]([\n" * 50000),
re.compile(r"<p>(\]\(\[\r?\n){49999}\]\(\[</p>")),
"many link ref. def. instantiations":
(("[x]: " + "x" * 50000 + "\n[x]" * 50000),
re.compile("")),
"many nested footnotes references":
(("[^na]:\n\n" + "[^" * 50000 + "x" + "]" * 50000),
re.compile(r"<p>(\[\^){49999}.*\]{49999}</p>"),
"--ffootnotes"),
}
whitespace_re = re.compile('/s+/')
def run_tests(args):
allowed_failures = {"many references": True}
TIMEOUT = 5
q = multiprocessing.Queue()
passed = []
errored = []
failed = []
ignored = []
#print("Testing pathological cases:")
for description in pathological:
if len(pathological[description]) == 2:
(inp, regex) = pathological[description]
prog = Prog(cmdline=args.program)
else:
(inp, regex, default_options) = pathological[description]
prog = Prog(cmdline=args.program, default_options=default_options)
start = timer()
p = multiprocessing.Process(
target=q.put(prog.to_html(inp)),
args=(q, inp, args.program))
end = timer()
p.start()
try:
# wait TIMEOUT seconds or until it finishes
rc, actual, err = q.get(True, TIMEOUT)
p.join()
if rc != 0:
print(description, '[ERRORED (return code %d)]' %rc)
print(err)
if description in allowed_failures:
ignored.append(description)
else:
errored.append(description)
elif regex.search(actual):
print('{:35} [PASSED] {:.3f} secs'.format(description, end-start))
passed.append(description)
else:
print(description, '[FAILED]')
print(repr(actual[:60]))
if description in allowed_failures:
ignored.append(description)
else:
failed.append(description)
except queue.Empty:
p.terminate()
p.join()
print(description, '[TIMEOUT]')
if description in allowed_failures:
ignored.append(description)
else:
errored.append(description)
print("%d passed, %d failed, %d errored" %
(len(passed), len(failed), len(errored)))
if ignored:
print("Ignoring these allowed failures:")
for x in ignored:
print(x)
if failed or errored:
exit(1)
else:
exit(0)
if __name__ == "__main__":
parser = argparse.ArgumentParser(description='Run Markdown tests.')
parser.add_argument('-p', '--program', dest='program', nargs='?', default=None,
help='program to test')
args = parser.parse_args(sys.argv[1:])
run_tests(args)