mirror of
https://github.com/libguestfs/libguestfs.git
synced 2026-03-21 22:53:37 +00:00
tests: provide a simple way to extract the tests data from run
If the RUN_OUTPUT_FILE environment variable is set, "run" will output to the file indicated by that snippets of XML with the results and outputs of the tests run. Together with the run-xml-to-junit.sh (and its associated run-xml-to-junit.xsl style sheet) it is possible to convert that output file to a jUnit-like XML file, which could be used in CI systems.
This commit is contained in:
8
run.in
8
run.in
@@ -260,5 +260,13 @@ else
|
||||
cat $tmpout
|
||||
echo "$b/run: command failed with exit code $fail"
|
||||
fi
|
||||
if [ -n "$RUN_OUTPUT_FILE" ]; then
|
||||
testname=`echo "$1" | sed -e 's,^./,,g'`
|
||||
echo "<test rescode=\"$fail\" name=\"$testname\" time=\"$(($end_t - $start_t))\">" >> $RUN_OUTPUT_FILE
|
||||
echo "<![CDATA[" >> $RUN_OUTPUT_FILE
|
||||
cat $tmpout >> $RUN_OUTPUT_FILE
|
||||
echo "]]>" >> $RUN_OUTPUT_FILE
|
||||
echo "</test>" >> $RUN_OUTPUT_FILE
|
||||
fi
|
||||
rm -f $tmpout
|
||||
exit $fail
|
||||
|
||||
24
tests/run-xml-to-junit.sh
Executable file
24
tests/run-xml-to-junit.sh
Executable file
@@ -0,0 +1,24 @@
|
||||
#!/bin/sh
|
||||
|
||||
if [ $# -lt 2 ]; then
|
||||
echo "$0: output-of-run destination-xml"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
set -e
|
||||
|
||||
infile=$1
|
||||
outfile=$2
|
||||
owndir=`dirname $0`
|
||||
ownname=`basename $0`
|
||||
tmpfile=`mktemp --tmpdir $ownname.XXXXXXXXXX`
|
||||
|
||||
(
|
||||
echo '<?xml version="1.0" encoding="UTF-8"?>';
|
||||
echo '<tests>';
|
||||
cat $infile;
|
||||
echo '</tests>'
|
||||
) > $tmpfile
|
||||
|
||||
xsltproc --encoding UTF-8 $owndir/run-xml-to-junit.xsl $tmpfile > $outfile
|
||||
unlink $tmpfile
|
||||
41
tests/run-xml-to-junit.xsl
Normal file
41
tests/run-xml-to-junit.xsl
Normal file
@@ -0,0 +1,41 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
|
||||
<xsl:output indent="yes" cdata-section-elements="system-out skipped error"/>
|
||||
|
||||
<xsl:template match="/">
|
||||
<xsl:variable name="TestsTotal"><xsl:value-of select="count(tests/test)"/></xsl:variable>
|
||||
<xsl:variable name="TestsPassed"><xsl:value-of select="count(tests/test[@rescode = 0])"/></xsl:variable>
|
||||
<xsl:variable name="TestsSkipped"><xsl:value-of select="count(tests/test[@rescode = 77])"/></xsl:variable>
|
||||
<xsl:variable name="TestsTimedout"><xsl:value-of select="count(tests/test[@rescode = 124])"/></xsl:variable>
|
||||
<xsl:variable name="TestsFailures"><xsl:value-of select="$TestsTotal - $TestsPassed - $TestsSkipped - $TestsTimedout"/></xsl:variable>
|
||||
|
||||
<testsuites>
|
||||
<testsuite name="libguestfs" tests="{$TestsTotal}" failures="{$TestsFailures}" skipped="{$TestsSkipped}" errors="{$TestsTimedout}">
|
||||
<xsl:for-each select="tests/test">
|
||||
<xsl:variable name="TestcaseName"><xsl:value-of select="@name"/></xsl:variable>
|
||||
<xsl:variable name="TestcaseTime"><xsl:value-of select="@time"/></xsl:variable>
|
||||
<xsl:variable name="TestcaseRescode"><xsl:value-of select="@rescode"/></xsl:variable>
|
||||
<xsl:variable name="TestcaseOutput"><xsl:value-of select="."/></xsl:variable>
|
||||
<testcase name="{$TestcaseName}" classname="TestSuite" time="{$TestcaseTime}">
|
||||
<xsl:choose>
|
||||
<xsl:when test="$TestcaseRescode = 0">
|
||||
<system-out><xsl:value-of select="$TestcaseOutput"/></system-out>
|
||||
</xsl:when>
|
||||
<xsl:when test="$TestcaseRescode = 77">
|
||||
<skipped><xsl:value-of select="$TestcaseOutput"/></skipped>
|
||||
</xsl:when>
|
||||
<xsl:when test="$TestcaseRescode = 124">
|
||||
<error><xsl:value-of select="$TestcaseOutput"/></error>
|
||||
</xsl:when>
|
||||
<xsl:otherwise>
|
||||
<error><xsl:value-of select="$TestcaseOutput"/></error>
|
||||
</xsl:otherwise>
|
||||
</xsl:choose>
|
||||
</testcase>
|
||||
</xsl:for-each>
|
||||
</testsuite>
|
||||
</testsuites>
|
||||
|
||||
</xsl:template>
|
||||
|
||||
</xsl:stylesheet>
|
||||
Reference in New Issue
Block a user