File: qtestlib2junitxml.xsl

package info (click to toggle)
libmlocale 0.7.8-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 23,412 kB
  • sloc: cpp: 29,597; sh: 631; perl: 350; python: 220; makefile: 26; sed: 7
file content (82 lines) | stat: -rw-r--r-- 2,725 bytes parent folder | download | duplicates (2)
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
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">

<xsl:output method="xml" indent="yes" />
<xsl:decimal-format decimal-separator="." grouping-separator="," />

<!-- misc variables -->
<xsl:variable name="classname" select="/TestCase/@name" />
<xsl:variable name="total-tests" select="count(/TestCase/TestFunction)" />
<xsl:variable name="total-failures" select="count(/TestCase/TestFunction/Incident[@type='fail'])" />

<!-- main template call -->
<xsl:template match="/">
    <xsl:apply-templates select="TestCase"/>
</xsl:template>

<xsl:template match="TestCase">
  <testsuite name="{$classname}" tests="{$total-tests}" failures="{$total-failures}" errors="0" time="0.0">
        <xsl:apply-templates select="Environment"/>
        <xsl:apply-templates select="TestFunction" />
    <xsl:call-template name="display-system-out" />
    <xsl:call-template name="display-system-err" />
    </testsuite>
</xsl:template>

<xsl:template match="Environment">
    <properties>
        <xsl:for-each select="*">
            <property name="{name()}" value="{text()}" />
        </xsl:for-each>
    </properties>
</xsl:template>

<xsl:template match="TestFunction">
    <testcase classname="{$classname}" name="{@name}" time="0.0">
        <!-- handle fail -->
        <xsl:if test="Incident/@type = 'fail'">
      <!-- will be used to generate "nice" error message -->
      <xsl:variable name="file" select="Incident/@file" />
      <xsl:variable name="line" select="Incident/@line" />
      <xsl:variable name="description">
        <xsl:value-of select="Incident/Description" />
      </xsl:variable>

      <!-- display a reasonable error message -->
            <xsl:element name="failure">
                <xsl:attribute name="type">Standard</xsl:attribute>
                <xsl:attribute name="message">
          <xsl:value-of select="concat($file,':',$line,' :: ',$description)" />
                </xsl:attribute>
            </xsl:element>

        </xsl:if>

    <!-- handle skip -->
        <xsl:if test="Incident/@type = 'skip'">

        </xsl:if>
    </testcase>
</xsl:template>

<xsl:template name="display-system-out">
  <system-out>
    <xsl:for-each select="/TestCase/TestFunction/Incident[@type='fail'] | /TestCase/TestFunction/Message[@type='skip']">
      <xsl:choose>
        <xsl:when test="@type='fail'">
          <xsl:value-of select="Description"/>
        </xsl:when>
        <xsl:when test="@type='skip'">
          <xsl:value-of select="Description"/>
        </xsl:when>
      </xsl:choose>
    </xsl:for-each>
  </system-out>
</xsl:template>

<xsl:template name="display-system-err">
  <!-- do nothing for now -->
  <system-err />
</xsl:template>

</xsl:stylesheet>