File: transform_xunit_to_appveyor.xsl

package info (click to toggle)
python-jpype 0.6.3%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 1,560 kB
  • sloc: cpp: 11,957; python: 3,844; java: 986; ansic: 875; makefile: 149; xml: 76; sh: 62
file content (101 lines) | stat: -rw-r--r-- 3,460 bytes parent folder | download
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
<!--
This xslt stylesheet transforms (JUnit) xunit xml output to xunit.net xml, which
is eg. used at AppVeyor CI.

See for reference:
https://xunit.codeplex.com/wikipage?title=XmlFormat

tested with saxon and xsltproc against output of nosetests &#8211;&#8211; with-xml (Python)

Author: Martin Scherer <m.scherer@fu-berlin.de>
-->
<xsl:stylesheet version="1.0"
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:output method="xml" encoding="UTF-8" indent="yes" />

<!-- xunit.net handles failures and errors the same -->
  <xsl:template match="failure|error">
    <xsl:attribute name="exception-type">
        <xsl:value-of select="@type" />
    </xsl:attribute>
    <message>
      <xsl:value-of select="@message" />
    </message>
    <stack-trace>
      <xsl:value-of select="." />
    </stack-trace>
  </xsl:template>
  
  <!-- use classnames as key -->
  <xsl:key name="class" match="/testsuite/testcase/@classname"
    use="." />
  <xsl:template match="testsuite">
    <assembly name="python">
      <xsl:attribute name="total">
        <xsl:value-of select="@tests" />
      </xsl:attribute>
      <xsl:attribute name="passed">
        <xsl:value-of select="@tests - @errors - @failures - @skip" />
      </xsl:attribute>
      <xsl:attribute name="failed">
        <xsl:value-of select="@errors" />
      </xsl:attribute>
      <xsl:attribute name="skipped">
        <xsl:value-of select="@skip" />
      </xsl:attribute>

<!-- class names, only unique -->
      <xsl:for-each
        select="/testsuite/testcase/@classname[generate-id()
                                       = generate-id(key('class',.)[1])]">
        <class>
          <xsl:variable name="className" select="." />
          <xsl:attribute name="name">
            <xsl:value-of select="." />
          </xsl:attribute>
    
    <!-- select only those testcases, which match the current classname -->
          <xsl:for-each select="/testsuite/testcase[@classname=$className]">
            <test>
              <xsl:attribute name="name">
                <xsl:value-of select="@name" />
            </xsl:attribute>
              <xsl:attribute name="time">
                <xsl:value-of select="@time" />
            </xsl:attribute>
              <xsl:variable name="result">
                <xsl:choose>
                  <xsl:when test="error or failure">Fail</xsl:when>
                  <xsl:when test="skipped">Skip</xsl:when>
                  <xsl:otherwise>Pass</xsl:otherwise>
                </xsl:choose>
              </xsl:variable>
              <xsl:attribute name="result">
                <xsl:value-of select="$result" />
            </xsl:attribute>
              <xsl:choose>
                <xsl:when test="error or failure">
                  <failure>
                    <xsl:apply-templates />
                  </failure>
                </xsl:when>
                <xsl:when test="skipped">
                  <reason>
                    <xsl:value-of select="skipped/@message" />
                  </reason>
                </xsl:when>
              </xsl:choose>
              <xsl:choose>
                <xsl:when test="system-out">
                  <output>
                    <xsl:value-of select="system-out/." />
                  </output>
                </xsl:when>
              </xsl:choose>
            </test>
          </xsl:for-each>
        </class>
      </xsl:for-each>
    </assembly>
  </xsl:template>
</xsl:stylesheet>