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
|
from my_typing import *
from datetime import datetime
import xml.etree.ElementTree as ET
from testglobals import TestRun
def junit(t: TestRun) -> ET.ElementTree:
testsuites = ET.Element('testsuites')
testsuite = ET.SubElement(testsuites, 'testsuite',
id = "0",
package = 'ghc',
tests = str(t.total_tests),
failures = str(len(t.unexpected_failures)
+ len(t.unexpected_stat_failures)
+ len(t.unexpected_passes)),
errors = str(len(t.framework_failures)),
timestamp = datetime.now().isoformat())
for res_type, group in [('stat failure', t.unexpected_stat_failures),
('unexpected failure', t.unexpected_failures),
('unexpected pass', t.unexpected_passes),
('fragile failure', t.fragile_failures),
('fragile pass', t.fragile_passes)]:
for tr in group:
testcase = ET.SubElement(testsuite, 'testcase',
classname = tr.way,
name = '%s(%s)' % (tr.testname, tr.way))
message = [] # type: List[str]
if tr.stdout:
message += ['', 'stdout:', '==========', tr.stdout]
if tr.stderr:
message += ['', 'stderr:', '==========', tr.stderr]
result = ET.SubElement(testcase, 'failure',
type = res_type,
message = tr.reason)
result.text = '\n'.join(message)
for tr in t.framework_failures:
testcase = ET.SubElement(testsuite, 'testcase',
classname = tr.way,
name = '%s(%s)' % (tr.testname, tr.way))
result = ET.SubElement(testcase, 'error',
type = "framework failure",
message = tr.reason)
for tr in t.expected_passes:
testcase = ET.SubElement(testsuite, 'testcase',
classname = tr.way,
name = '%s(%s)' % (tr.testname, tr.way))
return ET.ElementTree(testsuites)
|