* Example XSLT from Graeme Geldenhuys to transform test results to HTML

git-svn-id: trunk@5431 -
This commit is contained in:
michael 2006-11-20 08:29:40 +00:00
parent dee22e8b4a
commit d294359999
4 changed files with 328 additions and 0 deletions

3
.gitattributes vendored
View File

@ -784,6 +784,9 @@ fcl/fpcunit/Makefile.fpc svneol=native#text/plain
fcl/fpcunit/README.txt svneol=native#text/plain
fcl/fpcunit/demo/consolerunner/suiteconfig.pp svneol=native#text/plain
fcl/fpcunit/demo/consolerunner/testrunner.pp svneol=native#text/plain
fcl/fpcunit/example_xsl/fpcunit.css svneol=native#text/plain
fcl/fpcunit/example_xsl/fpcunit.xsl svneol=native#text/plain
fcl/fpcunit/example_xsl/readme.txt svneol=native#text/plain
fcl/fpcunit/exampletests/Makefile svneol=native#text/plain
fcl/fpcunit/exampletests/Makefile.fpc svneol=native#text/plain
fcl/fpcunit/exampletests/fpcunittests.pp svneol=native#text/plain

View File

@ -0,0 +1,106 @@
body
{
font-family: verdana, arial, helvetica, Sans-Serif;
font-size: x-small;
background: #FFFFFF;
}
a
{
text-decoration: none;
background-color: Transparent
}
a:link
{
color: #0033ff;
}
a:visited
{
color: #003399;
}
a:active, a:hover
{
color:#69c;
}
h2
{
padding: 4px 4px 4px 6px;
font-size: large;
border: 1px solid black;
font-weight: bold;
color: white;
background-color: #006699;
}
h3
{
padding: 4px 4px 4px 6px;
border: 1px solid #003399;
color: #FFFFFF;
/* #003399; */
background-color: #0099CC;
font-weight: normal;
font-size: medium;
}
table
{
padding:0px;
width: 100%;
margin-left: -2px;
margin-right: -2px;
}
th, td
{
padding: 2px 4px 2px 4px;
vertical-align: top;
font-size: x-small;
}
address
{
font-family: verdana, arial, helvetica, Sans-Serif;
font-size: 8pt;
font-style: normal;
text-align: right;
}
.title
{
background-color: #bbb;
/* #bbb; #D8D8D8 #D3E4FF */
color: white;
}
.resultmessage
{
background-color: #D3E4FF;
}
.success
{
background-color: lightgreen;
color: black;
}
.failure
{
background-color: #FF00FF;
color: black;
}
.notrun
{
background-color: yellow;
color: black;
}
.error
{
background-color: red;
color: black;
font-size: 9pt;
}
.right
{
font-size: 8pt;
text-align: right;
}
.backToTop
{
text-align: right;
}

View File

@ -0,0 +1,203 @@
<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html" encoding="UTF-8"/>
<xsl:template match="/">
<html>
<head>
<title>fpcUnit Results</title>
<style type="text/css" title="fpcUnit" media="screen">
@import "fpcunit.css";
</style>
</head>
<body>
<a name="Summary"/>
<h2>fpcUnit Results</h2>
<xsl:apply-templates/>
<address>
<a href="http://opensoft.homeip.net">fpcUnit Report</a> 0.3.1 © 2006 by
<a href="mailto:graemeg@gmail.com?subject=Comments about fpcUnit Report">Graeme Geldenhuys</a>.<br/>
Licensed under the <a href="http://www.gnu.org/copyleft/gpl.html">GNU General Public License</a>.<br/>
</address>
</body>
</html>
</xsl:template>
<xsl:template match="TestResults">
<xsl:variable name="runCount" select="NumberOfRunTests"/>
<xsl:variable name="failureCount" select="NumberOfFailures"/>
<xsl:variable name="errorCount" select="NumberOfErrors"/>
<xsl:variable name="elapsedTime" select="TotalElapsedTime"/>
<xsl:variable name="dateRan" select="DateTimeRan"/>
<h3>Summary</h3>
<!-- Summary Table -->
<table border="0" rules="none" width="100%">
<tr align="left" class="title">
<th width="45%" align="left">Name</th>
<th width="7%" align="left">Tests</th>
<th width="8%" align="left">Failures</th>
<th width="8%" align="left">Errors</th>
<th width="11%" align="left">Elapsed Time</th>
<th width="14%" align="left">Run Date</th>
</tr>
<xsl:choose>
<xsl:when test="$errorCount &gt; 0">
<tr class="error">
<td>Summary</td>
<td><xsl:value-of select="$runCount"/></td>
<td><xsl:value-of select="$failureCount"/></td>
<td><xsl:value-of select="$errorCount"/></td>
<td><xsl:value-of select="$elapsedTime"/></td>
<td><xsl:value-of select="$dateRan"/></td>
</tr>
</xsl:when>
<xsl:when test="$failureCount &gt; 0">
<tr class="failure">
<td>Summary</td>
<td><xsl:value-of select="$runCount"/></td>
<td><xsl:value-of select="$failureCount"/></td>
<td><xsl:value-of select="$errorCount"/></td>
<td><xsl:value-of select="$elapsedTime"/></td>
<td><xsl:value-of select="$dateRan"/></td>
</tr>
</xsl:when>
<xsl:otherwise>
<tr class="success">
<td>Summary</td>
<td><xsl:value-of select="$runCount"/></td>
<td><xsl:value-of select="$failureCount"/></td>
<td><xsl:value-of select="$errorCount"/></td>
<td><xsl:value-of select="$elapsedTime"/></td>
<td><xsl:value-of select="$dateRan"/></td>
</tr>
</xsl:otherwise>
</xsl:choose>
</table>
<p>Note: <i>Failures</i> are anticipated and checked for with assertions. <i>Errors</i> are
unexpected results.</p>
<hr/>
<xsl:call-template name="test_listing"/>
<xsl:call-template name="test_failures"/>
<xsl:call-template name="test_errors"/>
</xsl:template>
<xsl:template name="test_listing">
<div id="testlisting">
<a name="Test_Listing"/>
<h3>Test Listing</h3>
<p>
[<a href="#Summary">Summary</a>]
[<a href="#Test_Listing">Test Listing</a>]
[<a href="#Failures">Failures</a>]
[<a href="#Errors">Errors</a>]
</p>
<!-- Test Listing Table -->
<table border="0" rules="none" width="100%">
<tr align="left" class="title">
<th width="89%" align="left">Name</th>
<th width="11%" align="left">Elapsed Time<br/>(hh:mm:ss.zzz)</th>
</tr>
<xsl:for-each select="TestListing/TestSuite/Test">
<xsl:variable name="testName" select="@Name"/>
<xsl:variable name="elapsedTime" select="ElapsedTime"/>
<tr class="success">
<td><xsl:value-of select="$testName"/></td>
<td><xsl:value-of select="ElapsedTime"/></td>
</tr>
</xsl:for-each>
</table>
</div> <!-- testlisting -->
</xsl:template>
<xsl:template name="test_failures">
<div id="failures">
<a name="Failures"/>
<h3>Failures:</h3>
<p>
[<a href="#Summary">Summary</a>]
[<a href="#Test_Listing">Test Listing</a>]
[<a href="#Failures">Failures</a>]
[<a href="#Errors">Errors</a>]
</p>
<xsl:for-each select="ListOfFailures/Failure">
<p class="backToTop">
[<a href="#Failures">Back to top</a>]
</p>
<table>
<!-- Error Table Body -->
<TR>
<TD valign="top" class="title" width="300">Message:</TD>
<TD valign="top" class="resultmessage"><xsl:value-of select="Message"/></TD>
</TR>
<TR>
<TD valign="top" class="title">Exception Class:</TD>
<TD valign="top" class="resultmessage"><xsl:value-of select="ExceptionClass"/></TD>
</TR>
<TR>
<TD valign="top" class="title">Exception Message:</TD>
<TD valign="top" class="resultmessage"><xsl:value-of select="ExceptionMessage"/></TD>
</TR>
</table>
</xsl:for-each>
</div> <!-- failures -->
</xsl:template>
<xsl:template name="test_errors">
<div id="errors">
<a name="Errors"/>
<h3>Errors</h3>
<p>
[<a href="#Summary">Summary</a>]
[<a href="#Test_Listing">Test Listing</a>]
[<a href="#Failures">Failures</a>]
[<a href="#Errors">Errors</a>]
</p>
<xsl:for-each select="ListOfErrors/Error">
<p class="backToTop">
[<a href="#Errors">Back to top</a>]
</p>
<table>
<!-- Error Table Body -->
<TR>
<TD valign="top" class="title" width="300">Message:</TD>
<TD valign="top" class="resultmessage"><xsl:value-of select="Message"/></TD>
</TR>
<TR>
<TD valign="top" class="title">Exception Class:</TD>
<TD valign="top" class="resultmessage"><xsl:value-of select="ExceptionClass"/></TD>
</TR>
<TR>
<TD valign="top" class="title">Exception Message:</TD>
<TD valign="top" class="resultmessage"><xsl:value-of select="ExceptionMessage"/></TD>
</TR>
<TR>
<TD valign="top" class="title">UnitName:</TD>
<TD valign="top" class="resultmessage"><xsl:value-of select="SourceUnitName"/></TD>
</TR>
<TR>
<TD valign="top" class="title">LineNumber:</TD>
<TD valign="top" class="resultmessage"><xsl:value-of select="LineNumber"/></TD>
</TR>
<TR>
<TD valign="top" class="title">Method Name:</TD>
<TD valign="top" class="resultmessage"><xsl:value-of select="FailedMethodName"/></TD>
</TR>
</table>
</xsl:for-each>
</div> <!-- errors -->
</xsl:template>
</xsl:stylesheet>

View File

@ -0,0 +1,16 @@
Sample XSLT processing
----------------------
The fpcunit.xsl and fpcunit.css demonstrates how I create a Results HTML
page from the XML generated by my unit tests.
I use the following command line application under Linux to process the XML
file.
xsltproc -o index.html fpcunit.xsl results.xml
Graeme Geldenhuys.
graemeg@gmail.com