-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathdoxy2junit.py
84 lines (70 loc) · 2.57 KB
/
doxy2junit.py
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
import os
import pathlib
import re
import sys
import xml.etree.ElementTree as etree
import xml.dom.minidom as minidom
RE_WARN_LOGFILE = re.compile(r"WARN_LOGFILE\s*=\s*(.+)")
DETAILS_TEMPLATE = """\
In file {relpath} on line {lineno}:
{message}
"""
def path_to_dotted(path, prefix):
split_path = [part.replace(".", "_")
for part in ("zordzman",) + path.relative_to(prefix).parts]
return ".".join(split_path[:-1]), split_path[-1]
def build_report(issues, path_prefix):
tree = etree.ElementTree(etree.Element("testsuite", tests=str(len(issues))))
test_suite = tree.getroot()
for issue in issues:
issue["relpath"] = issue["path"].relative_to(path_prefix)
class_, name = path_to_dotted(issue["path"], path_prefix)
test_case = etree.Element("testcase", classname=class_, name=name)
failure = etree.Element("failure", type=issue["type"])
failure.text = DETAILS_TEMPLATE.format(**issue)
test_case.append(failure)
test_suite.append(test_case)
return tree
def log_to_junit(log, dest, path_prefix):
issues = []
with log.open() as log_fp:
for line in log_fp:
try:
path, lineno, type_, message = line.split(":", 3)
except ValueError:
# Message spans multiple lines
issues[-1]["message"] += line
else:
path = pathlib.Path(path)
lineno = int(lineno)
type_ = type_.strip()
message = message.strip()
while message.endswith("\n"):
message[:-1]
issues.append({
"path": path,
"lineno": lineno,
"type": type_,
"message": message,
})
with dest.open("w") as report_fp:
ugly = etree.tostring(build_report(issues,
path_prefix).getroot(), "utf-8")
parsed = minidom.parseString(ugly)
report_fp.write(parsed.toprettyxml(indent=" "))
def main(argv):
logfile = None
with open("Doxyfile", "r") as doxy_config:
for line in doxy_config:
match = RE_WARN_LOGFILE.match(line)
if match:
logfile = match.groups()[0].rstrip()
if not logfile:
print("No WARN_LOGFILE found in Doxyfile")
return 1
prefix = pathlib.Path(os.getcwd())
logfile = pathlib.Path(logfile)
log_to_junit(logfile, logfile.parent / "doxygen.xml", prefix)
return 0
if __name__ == "__main__":
main(sys.argv[1:])