1 | <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0" |
---|
2 | xmlns:exsl="http://exslt.org/common" |
---|
3 | xmlns:str="http://exslt.org/strings" |
---|
4 | xmlns:date="http://exslt.org/dates-and-times" |
---|
5 | extension-element-prefixes="exsl str date"> |
---|
6 | <xsl:include href="str.replace.function.xsl"/> |
---|
7 | <xsl:output method="html" indent="yes" encoding="US-ASCII" |
---|
8 | doctype-public="-//W3C//DTD HTML 4.01 Transitional//EN" /> |
---|
9 | <xsl:decimal-format decimal-separator="." grouping-separator="," /> |
---|
10 | <!-- |
---|
11 | Copyright 2001-2004 The Apache Software Foundation |
---|
12 | |
---|
13 | Licensed under the Apache License, Version 2.0 (the "License"); |
---|
14 | you may not use this file except in compliance with the License. |
---|
15 | You may obtain a copy of the License at |
---|
16 | |
---|
17 | http://www.apache.org/licenses/LICENSE-2.0 |
---|
18 | |
---|
19 | Unless required by applicable law or agreed to in writing, software |
---|
20 | distributed under the License is distributed on an "AS IS" BASIS, |
---|
21 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
---|
22 | See the License for the specific language governing permissions and |
---|
23 | limitations under the License. |
---|
24 | --> |
---|
25 | |
---|
26 | <!-- |
---|
27 | |
---|
28 | Sample stylesheet to be used with Phing/PHPUnit2 output. |
---|
29 | Based on JUnit stylesheets from Apache Ant. |
---|
30 | |
---|
31 | It creates a non-framed report that can be useful to send via |
---|
32 | e-mail or such. |
---|
33 | |
---|
34 | @author Michiel Rook <a href="mailto:michiel.rook@gmail.com"/> |
---|
35 | @author Stephane Bailliez <a href="mailto:sbailliez@apache.org"/> |
---|
36 | @author Erik Hatcher <a href="mailto:ehatcher@apache.org"/> |
---|
37 | |
---|
38 | --> |
---|
39 | <xsl:template match="testsuites"> |
---|
40 | <html> |
---|
41 | <head> |
---|
42 | <title>Unit Test Results</title> |
---|
43 | <style type="text/css"> |
---|
44 | body { |
---|
45 | font-family: verdana,arial,helvetica; |
---|
46 | color:#000000; |
---|
47 | font-size: 12px; |
---|
48 | } |
---|
49 | table tr td, table tr th { |
---|
50 | font-family: verdana,arial,helvetica; |
---|
51 | font-size: 12px; |
---|
52 | } |
---|
53 | table.details tr th{ |
---|
54 | font-family: verdana,arial,helvetica; |
---|
55 | font-weight: bold; |
---|
56 | text-align:left; |
---|
57 | background:#a6caf0; |
---|
58 | } |
---|
59 | table.details tr td{ |
---|
60 | background:#eeeee0; |
---|
61 | } |
---|
62 | |
---|
63 | p { |
---|
64 | line-height:1.5em; |
---|
65 | margin-top:0.5em; margin-bottom:1.0em; |
---|
66 | font-size: 12px; |
---|
67 | } |
---|
68 | h1 { |
---|
69 | margin: 0px 0px 5px; |
---|
70 | font-family: verdana,arial,helvetica; |
---|
71 | } |
---|
72 | h2 { |
---|
73 | margin-top: 1em; margin-bottom: 0.5em; |
---|
74 | font-family: verdana,arial,helvetica; |
---|
75 | } |
---|
76 | h3 { |
---|
77 | margin-bottom: 0.5em; |
---|
78 | font-family: verdana,arial,helvetica; |
---|
79 | } |
---|
80 | h4 { |
---|
81 | margin-bottom: 0.5em; |
---|
82 | font-family: verdana,arial,helvetica; |
---|
83 | } |
---|
84 | h5 { |
---|
85 | margin-bottom: 0.5em; |
---|
86 | font-family: verdana,arial,helvetica; |
---|
87 | } |
---|
88 | h6 { |
---|
89 | margin-bottom: 0.5em; |
---|
90 | font-family: verdana,arial,helvetica; |
---|
91 | } |
---|
92 | .Error { |
---|
93 | font-weight:bold; color:red; |
---|
94 | } |
---|
95 | .Failure { |
---|
96 | font-weight:bold; color:purple; |
---|
97 | } |
---|
98 | .small { |
---|
99 | font-size: 9px; |
---|
100 | } |
---|
101 | a { |
---|
102 | color: #003399; |
---|
103 | } |
---|
104 | a:hover { |
---|
105 | color: #888888; |
---|
106 | } |
---|
107 | </style> |
---|
108 | </head> |
---|
109 | <body> |
---|
110 | <a name="top"></a> |
---|
111 | <xsl:call-template name="pageHeader"/> |
---|
112 | |
---|
113 | <!-- Summary part --> |
---|
114 | <xsl:call-template name="summary"/> |
---|
115 | <hr size="1" width="95%" align="left"/> |
---|
116 | |
---|
117 | <!-- Package List part --> |
---|
118 | <xsl:call-template name="packagelist"/> |
---|
119 | <hr size="1" width="95%" align="left"/> |
---|
120 | |
---|
121 | <!-- For each package create its part --> |
---|
122 | <xsl:call-template name="packages"/> |
---|
123 | <hr size="1" width="95%" align="left"/> |
---|
124 | |
---|
125 | <!-- For each class create the part --> |
---|
126 | <xsl:call-template name="classes"/> |
---|
127 | |
---|
128 | <xsl:call-template name="pageFooter"/> |
---|
129 | </body> |
---|
130 | </html> |
---|
131 | </xsl:template> |
---|
132 | |
---|
133 | |
---|
134 | |
---|
135 | <!-- ================================================================== --> |
---|
136 | <!-- Write a list of all packages with an hyperlink to the anchor of --> |
---|
137 | <!-- of the package name. --> |
---|
138 | <!-- ================================================================== --> |
---|
139 | <xsl:template name="packagelist"> |
---|
140 | <h2>Packages</h2> |
---|
141 | Note: package statistics are not computed recursively, they only sum up all of its testsuites numbers. |
---|
142 | <table class="details" border="0" cellpadding="5" cellspacing="2" width="95%"> |
---|
143 | <xsl:call-template name="testsuite.test.header"/> |
---|
144 | <!-- list all packages recursively --> |
---|
145 | <xsl:for-each select="./testsuite[not(./@package = preceding-sibling::testsuite/@package)]"> |
---|
146 | <xsl:sort select="@package"/> |
---|
147 | <xsl:variable name="testsuites-in-package" select="/testsuites/testsuite[./@package = current()/@package]"/> |
---|
148 | <xsl:variable name="testCount" select="sum($testsuites-in-package/@tests)"/> |
---|
149 | <xsl:variable name="errorCount" select="sum($testsuites-in-package/@errors)"/> |
---|
150 | <xsl:variable name="failureCount" select="sum($testsuites-in-package/@failures)"/> |
---|
151 | <xsl:variable name="timeCount" select="sum($testsuites-in-package/@time)"/> |
---|
152 | |
---|
153 | <!-- write a summary for the package --> |
---|
154 | <tr valign="top"> |
---|
155 | <!-- set a nice color depending if there is an error/failure --> |
---|
156 | <xsl:attribute name="class"> |
---|
157 | <xsl:choose> |
---|
158 | <xsl:when test="$failureCount > 0">Failure</xsl:when> |
---|
159 | <xsl:when test="$errorCount > 0">Error</xsl:when> |
---|
160 | </xsl:choose> |
---|
161 | </xsl:attribute> |
---|
162 | <td><a href="#{@package}"><xsl:value-of select="@package"/></a></td> |
---|
163 | <td><xsl:value-of select="$testCount"/></td> |
---|
164 | <td><xsl:value-of select="$errorCount"/></td> |
---|
165 | <td><xsl:value-of select="$failureCount"/></td> |
---|
166 | <td> |
---|
167 | <xsl:call-template name="display-time"> |
---|
168 | <xsl:with-param name="value" select="$timeCount"/> |
---|
169 | </xsl:call-template> |
---|
170 | </td> |
---|
171 | </tr> |
---|
172 | </xsl:for-each> |
---|
173 | </table> |
---|
174 | </xsl:template> |
---|
175 | |
---|
176 | |
---|
177 | <!-- ================================================================== --> |
---|
178 | <!-- Write a package level report --> |
---|
179 | <!-- It creates a table with values from the document: --> |
---|
180 | <!-- Name | Tests | Errors | Failures | Time --> |
---|
181 | <!-- ================================================================== --> |
---|
182 | <xsl:template name="packages"> |
---|
183 | <!-- create an anchor to this package name --> |
---|
184 | <xsl:for-each select="/testsuites/testsuite[not(./@package = preceding-sibling::testsuite/@package)]"> |
---|
185 | <xsl:sort select="@package"/> |
---|
186 | <a name="{@package}"></a> |
---|
187 | <h3>Package <xsl:value-of select="@package"/></h3> |
---|
188 | |
---|
189 | <table class="details" border="0" cellpadding="5" cellspacing="2" width="95%"> |
---|
190 | <xsl:call-template name="testsuite.test.header"/> |
---|
191 | |
---|
192 | <!-- match the testsuites of this package --> |
---|
193 | <xsl:apply-templates select="/testsuites/testsuite[./@package = current()/@package]" mode="print.test"/> |
---|
194 | </table> |
---|
195 | <a href="#top">Back to top</a> |
---|
196 | <p/> |
---|
197 | <p/> |
---|
198 | </xsl:for-each> |
---|
199 | </xsl:template> |
---|
200 | |
---|
201 | <xsl:template name="classes"> |
---|
202 | <xsl:for-each select="testsuite"> |
---|
203 | <xsl:sort select="@name"/> |
---|
204 | <!-- create an anchor to this class name --> |
---|
205 | <a name="{@name}"></a> |
---|
206 | <h3>TestCase <xsl:value-of select="@name"/></h3> |
---|
207 | |
---|
208 | <table class="details" border="0" cellpadding="5" cellspacing="2" width="95%"> |
---|
209 | <xsl:call-template name="testcase.test.header"/> |
---|
210 | <!-- |
---|
211 | test can even not be started at all (failure to load the class) |
---|
212 | so report the error directly |
---|
213 | --> |
---|
214 | <xsl:if test="./error"> |
---|
215 | <tr class="Error"> |
---|
216 | <td colspan="4"><xsl:apply-templates select="./error"/></td> |
---|
217 | </tr> |
---|
218 | </xsl:if> |
---|
219 | <xsl:apply-templates select="./testcase | ./testsuite/testcase" mode="print.test"/> |
---|
220 | </table> |
---|
221 | <p/> |
---|
222 | |
---|
223 | <a href="#top">Back to top</a> |
---|
224 | </xsl:for-each> |
---|
225 | </xsl:template> |
---|
226 | |
---|
227 | <xsl:template name="summary"> |
---|
228 | <h2>Summary</h2> |
---|
229 | <xsl:variable name="testCount" select="sum(testsuite/@tests)"/> |
---|
230 | <xsl:variable name="errorCount" select="sum(testsuite/@errors)"/> |
---|
231 | <xsl:variable name="failureCount" select="sum(testsuite/@failures)"/> |
---|
232 | <xsl:variable name="timeCount" select="sum(testsuite/@time)"/> |
---|
233 | <xsl:variable name="successRate" select="($testCount - $failureCount - $errorCount) div $testCount"/> |
---|
234 | <table class="details" border="0" cellpadding="5" cellspacing="2" width="95%"> |
---|
235 | <tr valign="top"> |
---|
236 | <th>Tests</th> |
---|
237 | <th>Failures</th> |
---|
238 | <th>Errors</th> |
---|
239 | <th>Success rate</th> |
---|
240 | <th>Time</th> |
---|
241 | </tr> |
---|
242 | <tr valign="top"> |
---|
243 | <xsl:attribute name="class"> |
---|
244 | <xsl:choose> |
---|
245 | <xsl:when test="$failureCount > 0">Failure</xsl:when> |
---|
246 | <xsl:when test="$errorCount > 0">Error</xsl:when> |
---|
247 | </xsl:choose> |
---|
248 | </xsl:attribute> |
---|
249 | <td><xsl:value-of select="$testCount"/></td> |
---|
250 | <td><xsl:value-of select="$failureCount"/></td> |
---|
251 | <td><xsl:value-of select="$errorCount"/></td> |
---|
252 | <td> |
---|
253 | <xsl:call-template name="display-percent"> |
---|
254 | <xsl:with-param name="value" select="$successRate"/> |
---|
255 | </xsl:call-template> |
---|
256 | </td> |
---|
257 | <td> |
---|
258 | <xsl:call-template name="display-time"> |
---|
259 | <xsl:with-param name="value" select="$timeCount"/> |
---|
260 | </xsl:call-template> |
---|
261 | </td> |
---|
262 | |
---|
263 | </tr> |
---|
264 | </table> |
---|
265 | <table border="0" width="95%"> |
---|
266 | <tr> |
---|
267 | <td style="text-align: justify;"> |
---|
268 | Note: <i>failures</i> are anticipated and checked for with assertions while <i>errors</i> are unanticipated. |
---|
269 | </td> |
---|
270 | </tr> |
---|
271 | </table> |
---|
272 | </xsl:template> |
---|
273 | |
---|
274 | <!-- Page HEADER --> |
---|
275 | <xsl:template name="pageHeader"> |
---|
276 | <h1>Unit Test Results</h1> |
---|
277 | <table width="100%"> |
---|
278 | <tr> |
---|
279 | <td align="left"></td> |
---|
280 | <td align="right">Designed for use with <a href='http://pear.php.net/package/PHPUnit2'>PHPUnit2</a> and <a href='http://phing.info/'>Phing</a>.</td> |
---|
281 | </tr> |
---|
282 | </table> |
---|
283 | <hr size="1"/> |
---|
284 | </xsl:template> |
---|
285 | |
---|
286 | <!-- Page Footer --> |
---|
287 | <xsl:template name="pageFooter"> |
---|
288 | <table width="100%"> |
---|
289 | <tr><td><hr noshade="yes" size="1"/></td></tr> |
---|
290 | <tr><td class="small">Report generated at <xsl:value-of select="date:date-time()"/></td></tr> |
---|
291 | </table> |
---|
292 | </xsl:template> |
---|
293 | |
---|
294 | <xsl:template match="testsuite" mode="header"> |
---|
295 | <tr valign="top"> |
---|
296 | <th width="80%">Name</th> |
---|
297 | <th>Tests</th> |
---|
298 | <th>Errors</th> |
---|
299 | <th>Failures</th> |
---|
300 | <th nowrap="nowrap">Time(s)</th> |
---|
301 | </tr> |
---|
302 | </xsl:template> |
---|
303 | |
---|
304 | <!-- class header --> |
---|
305 | <xsl:template name="testsuite.test.header"> |
---|
306 | <tr valign="top"> |
---|
307 | <th width="80%">Name</th> |
---|
308 | <th>Tests</th> |
---|
309 | <th>Errors</th> |
---|
310 | <th>Failures</th> |
---|
311 | <th nowrap="nowrap">Time(s)</th> |
---|
312 | </tr> |
---|
313 | </xsl:template> |
---|
314 | |
---|
315 | <!-- method header --> |
---|
316 | <xsl:template name="testcase.test.header"> |
---|
317 | <tr valign="top"> |
---|
318 | <th>Name</th> |
---|
319 | <th>Status</th> |
---|
320 | <th width="80%">Type</th> |
---|
321 | <th nowrap="nowrap">Time(s)</th> |
---|
322 | </tr> |
---|
323 | </xsl:template> |
---|
324 | |
---|
325 | |
---|
326 | <!-- class information --> |
---|
327 | <xsl:template match="testsuite" mode="print.test"> |
---|
328 | <tr valign="top"> |
---|
329 | <!-- set a nice color depending if there is an error/failure --> |
---|
330 | <xsl:attribute name="class"> |
---|
331 | <xsl:choose> |
---|
332 | <xsl:when test="@failures[.> 0]">Failure</xsl:when> |
---|
333 | <xsl:when test="@errors[.> 0]">Error</xsl:when> |
---|
334 | </xsl:choose> |
---|
335 | </xsl:attribute> |
---|
336 | |
---|
337 | <!-- print testsuite information --> |
---|
338 | <td><a href="#{@name}"><xsl:value-of select="@name"/></a></td> |
---|
339 | <td><xsl:value-of select="@tests"/></td> |
---|
340 | <td><xsl:value-of select="@errors"/></td> |
---|
341 | <td><xsl:value-of select="@failures"/></td> |
---|
342 | <td> |
---|
343 | <xsl:call-template name="display-time"> |
---|
344 | <xsl:with-param name="value" select="@time"/> |
---|
345 | </xsl:call-template> |
---|
346 | </td> |
---|
347 | </tr> |
---|
348 | </xsl:template> |
---|
349 | |
---|
350 | <xsl:template match="testcase" mode="print.test"> |
---|
351 | <tr valign="top"> |
---|
352 | <xsl:attribute name="class"> |
---|
353 | <xsl:choose> |
---|
354 | <xsl:when test="failure | error">Error</xsl:when> |
---|
355 | </xsl:choose> |
---|
356 | </xsl:attribute> |
---|
357 | <td><xsl:value-of select="@name"/></td> |
---|
358 | <xsl:choose> |
---|
359 | <xsl:when test="failure"> |
---|
360 | <td>Failure</td> |
---|
361 | <td><xsl:apply-templates select="failure"/></td> |
---|
362 | </xsl:when> |
---|
363 | <xsl:when test="error"> |
---|
364 | <td>Error</td> |
---|
365 | <td><xsl:apply-templates select="error"/></td> |
---|
366 | </xsl:when> |
---|
367 | <xsl:otherwise> |
---|
368 | <td>Success</td> |
---|
369 | <td></td> |
---|
370 | </xsl:otherwise> |
---|
371 | </xsl:choose> |
---|
372 | <td> |
---|
373 | <xsl:call-template name="display-time"> |
---|
374 | <xsl:with-param name="value" select="@time"/> |
---|
375 | </xsl:call-template> |
---|
376 | </td> |
---|
377 | </tr> |
---|
378 | </xsl:template> |
---|
379 | |
---|
380 | |
---|
381 | <xsl:template match="failure"> |
---|
382 | <xsl:call-template name="display-failures"/> |
---|
383 | </xsl:template> |
---|
384 | |
---|
385 | <xsl:template match="error"> |
---|
386 | <xsl:call-template name="display-failures"/> |
---|
387 | </xsl:template> |
---|
388 | |
---|
389 | <!-- Style for the error and failure in the tescase template --> |
---|
390 | <xsl:template name="display-failures"> |
---|
391 | <xsl:choose> |
---|
392 | <xsl:when test="not(@message)">N/A</xsl:when> |
---|
393 | <xsl:otherwise> |
---|
394 | <xsl:value-of select="@message"/> |
---|
395 | </xsl:otherwise> |
---|
396 | </xsl:choose> |
---|
397 | <!-- display the stacktrace --> |
---|
398 | <code> |
---|
399 | <br/><br/> |
---|
400 | <xsl:call-template name="br-replace"> |
---|
401 | <xsl:with-param name="word" select="."/> |
---|
402 | </xsl:call-template> |
---|
403 | </code> |
---|
404 | </xsl:template> |
---|
405 | |
---|
406 | <!-- |
---|
407 | template that will convert a carriage return into a br tag |
---|
408 | @param word the text from which to convert CR to BR tag |
---|
409 | --> |
---|
410 | <xsl:template name="br-replace"> |
---|
411 | <xsl:param name="word"/> |
---|
412 | <xsl:choose> |
---|
413 | <xsl:when test="contains($word,'
')"> |
---|
414 | <xsl:value-of select="substring-before($word,'
')"/> |
---|
415 | <br /> |
---|
416 | <xsl:call-template name="br-replace"> |
---|
417 | <xsl:with-param name="word" select="substring-after($word,'
')"/> |
---|
418 | </xsl:call-template> |
---|
419 | </xsl:when> |
---|
420 | <xsl:otherwise> |
---|
421 | <xsl:value-of select="$word"/> |
---|
422 | </xsl:otherwise> |
---|
423 | </xsl:choose> |
---|
424 | </xsl:template> |
---|
425 | |
---|
426 | <xsl:template name="display-time"> |
---|
427 | <xsl:param name="value"/> |
---|
428 | <xsl:value-of select="format-number($value,'0.000')"/> |
---|
429 | </xsl:template> |
---|
430 | |
---|
431 | <xsl:template name="display-percent"> |
---|
432 | <xsl:param name="value"/> |
---|
433 | <xsl:value-of select="format-number($value,'0.00%')"/> |
---|
434 | </xsl:template> |
---|
435 | |
---|
436 | </xsl:stylesheet> |
---|
437 | |
---|