summaryrefslogtreecommitdiff
path: root/testsuite/driver/junit.py
blob: d376a061c8aebd25071c573d1615f19e39412bf3 (plain)
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
from datetime import datetime
import xml.etree.ElementTree as ET

def junit(t):
    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_passes', t.unexpected_passes)]:
        for tr in group:
            testcase = ET.SubElement(testsuite, 'testcase',
                                     classname = tr.way,
                                     name = '%s(%sb)' % (tr.testname, tr.way))
            new_reason = "\n".join([tr.reason, "STDERR:", tr.stderr.decode("utf-8")]) if tr.stderr else tr.reason
            result = ET.SubElement(testcase, 'failure',
                                   type = res_type,
                                   message = new_reason)

    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)