Skip to content

Instantly share code, notes, and snippets.

@jakoch
Created January 13, 2023 18:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jakoch/29318e07f2735f7bbb6d754a427de5c4 to your computer and use it in GitHub Desktop.
Save jakoch/29318e07f2735f7bbb6d754a427de5c4 to your computer and use it in GitHub Desktop.
gtest_to_junit.xml
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright (c) 2021, Jens A. Koch.
License: BSL-1.0, see https://opensource.org/licenses/BSL-1.0
Usage Github Actions with Powershell to transform googletest results of standalone executables:
- name: ♻ Transform Test Results (gtest ➔ junit)
working-directory: build-dbg
shell: pwsh
run: |
$xsl = New-Object System.Xml.Xsl.XslCompiledTransform
$xsl.Load("${{github.workspace}}\.github\gtest_to_junit.xsl")
$xsl.Transform((Resolve-Path .\test_results_gtest.xml), "${{github.workspace}}\test_results_${{matrix.config.NAME}}.xml")
Superseded by:
ctest --output-junit "${{github.workspace}}\test_results_${{matrix.config.NAME}}.xml"
-->
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" indent="yes" />
<xsl:template match="/">
<xsl:apply-templates/>
</xsl:template>
<xsl:template match="//testsuites">
<testsuites>
<xsl:apply-templates/>
</testsuites>
</xsl:template>
<xsl:template match="//testsuite">
<testsuite>
<xsl:attribute name="name"> <xsl:value-of select="@name"/></xsl:attribute>
<xsl:attribute name="tests"> <xsl:value-of select="@tests"/></xsl:attribute>
<xsl:attribute name="failures"> <xsl:value-of select="@failures"/></xsl:attribute>
<xsl:attribute name="errors"> <xsl:value-of select="@errors"/></xsl:attribute>
<xsl:attribute name="skipped"> <xsl:value-of select="@disabled + count(testcase[@result = 'skipped'])"/></xsl:attribute>
<xsl:attribute name="time"> <xsl:value-of select="@time"/></xsl:attribute>
<xsl:apply-templates select="testcase"/>
</testsuite>
</xsl:template>
<xsl:template match="//testcase">
<testcase>
<xsl:choose>
<xsl:when test="@value_param">
<xsl:attribute name="name">
<xsl:value-of select="@name"/> (<xsl:value-of select="@value_param"/>)
</xsl:attribute>
</xsl:when>
<xsl:otherwise>
<xsl:attribute name="name">
<xsl:value-of select="@name"/>
</xsl:attribute>
</xsl:otherwise>
</xsl:choose>
<xsl:attribute name="time">
<xsl:value-of select="@time"/>
</xsl:attribute>
<xsl:attribute name="classname">
<xsl:value-of select="@classname"/>
</xsl:attribute>
<xsl:if test="@status = 'notrun' or @result = 'skipped'">
<skipped/>
</xsl:if>
<xsl:if test="failure">
<failure>
<xsl:for-each select="failure">
<xsl:if test="not(position()=1)">
<xsl:text>&#xa;&#xa;</xsl:text>
</xsl:if>
<xsl:value-of select="@message"/>
</xsl:for-each>
</failure>
<system-out>
<xsl:for-each select="failure">
<xsl:if test="not(position()=1)">
<xsl:text>&#xa;&#xa;</xsl:text>
</xsl:if>
<xsl:value-of select="."/>
</xsl:for-each>
</system-out>
</xsl:if>
<xsl:if test="error">
<failure>
<xsl:for-each select="error">
<xsl:if test="not(position()=1)">
<xsl:text>&#xa;&#xa;</xsl:text>
</xsl:if>
<xsl:value-of select="@message"/>
</xsl:for-each>
</failure>
<system-out>
<xsl:for-each select="error">
<xsl:if test="not(position()=1)">
<xsl:text>&#xa;&#xa;</xsl:text>
</xsl:if>
<xsl:value-of select="."/>
</xsl:for-each>
</system-out>
</xsl:if>
</testcase>
</xsl:template>
</xsl:stylesheet>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment