Skip to content

Commit eba2a55

Browse files
committed
Added generating Clover xml reports
1 parent 1377a4d commit eba2a55

File tree

2 files changed

+106
-1
lines changed

2 files changed

+106
-1
lines changed

getcov

+17-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
# Copyright 2015 Jonathan M. Reid. See LICENSE.txt
44

55
usage() {
6-
echo "usage: getcov [[-s] [-x] [-o output_dir] [-i info_file] [-v]] | [-h]]"
6+
echo "usage: getcov [[-s] [-x] [-c] [-o output_dir] [-i info_file] [-v]] | [-h]]"
77
}
88

99
main() {
@@ -22,6 +22,11 @@ main() {
2222
generate_xml=1
2323
echo "Generate Cobertura XML"
2424
;;
25+
-xc|--xmlclover)
26+
generate_xml=1
27+
generate_xml_clover=1
28+
echo "Generate Clover XML"
29+
;;
2530
-o)
2631
shift
2732
output_dir=$1
@@ -61,6 +66,10 @@ main() {
6166
generate_cobertura_xml
6267
fi
6368

69+
if [ "$generate_xml_clover" = "1" ]; then
70+
generate_clover_xml
71+
fi
72+
6473
generate_html_report
6574

6675
if [ "$show_html" = "1" ]; then
@@ -131,6 +140,13 @@ generate_html_report() {
131140
"${LCOV_PATH}/genhtml" --output-directory . "${LCOV_INFO}"
132141
}
133142

143+
generate_clover_xml () {
144+
if [ "$verbose" = "1" ]; then
145+
echo "XcodeCoverage: Generating Clover XML"
146+
fi
147+
xsltproc "${scripts}/transform.xslt" "coverage.xml" > "clover.xml"
148+
}
149+
134150
show_html_report() {
135151
if [ "$verbose" = "1" ]; then
136152
echo "XcodeCoverage: Opening HTML report"

transform.xslt

+89
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
<?xml version="1.0"?>
2+
<xsl:stylesheet version="1.0"
3+
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
4+
<xsl:output method="xml"/>
5+
<!-- This template processes the root node ("/") -->
6+
<xsl:template match="/">
7+
<coverage>
8+
<xsl:attribute name='generated'>
9+
<xsl:value-of select='/coverage/@timestamp'/>
10+
</xsl:attribute>
11+
<project>
12+
<xsl:attribute name='timestamp'>
13+
<xsl:value-of select='/coverage/@timestamp'/>
14+
</xsl:attribute>
15+
<xsl:apply-templates
16+
select='//classes'/>
17+
<xsl:variable name='ncloc' select='count(current()//line)'/>
18+
<xsl:call-template name='metrics'>
19+
<xsl:with-param name='ncloc'
20+
select="$ncloc"
21+
/>
22+
<xsl:with-param name='files'
23+
select="count(current()//classes)"
24+
/>
25+
<xsl:with-param name='elements'
26+
select='$ncloc'/>
27+
<xsl:with-param name='coveredelements'
28+
select='number($ncloc) - count(current()//line[number(@hits) = 0])'/>
29+
</xsl:call-template>
30+
</project>
31+
</coverage>
32+
</xsl:template>
33+
<xsl:template match="class">
34+
<file>
35+
<xsl:attribute name='name'>
36+
<xsl:value-of select='current()/@filename'/>
37+
</xsl:attribute>
38+
<xsl:for-each select='lines/line'>
39+
<line type='stmt'>
40+
<xsl:attribute name='num'>
41+
<xsl:value-of select='current()/@number'/>
42+
</xsl:attribute>
43+
<xsl:attribute name='count'>
44+
<xsl:value-of select='current()/@hits'/>
45+
</xsl:attribute>
46+
</line>
47+
</xsl:for-each>
48+
<xsl:variable name='ncloc' select='count(current()//line)'/>
49+
<xsl:call-template name='metrics'>
50+
<xsl:with-param name='ncloc'
51+
select="$ncloc"
52+
/>
53+
<xsl:with-param name='files'
54+
select="count(current()//classes)"
55+
/>
56+
<xsl:with-param name='elements'
57+
select='$ncloc'/>
58+
<xsl:with-param name='coveredelements'
59+
select='number($ncloc) - count(current()//line[number(@hits) = 0])'/>
60+
</xsl:call-template>
61+
</file>
62+
</xsl:template>
63+
<xsl:template name='metrics'>
64+
<xsl:param name='elements' select='number(0)'/>
65+
<xsl:param name='coveredelements' select='number(0)'/>
66+
<xsl:param name='files'/>
67+
<xsl:param name='ncloc' select='number(0)'/>
68+
<metrics>
69+
<xsl:attribute name='ncloc'>
70+
<xsl:value-of select='$ncloc'/>
71+
</xsl:attribute>
72+
<xsl:if test='number(coveredelements) != 0'>
73+
<xsl:attribute name='coveredelements'>
74+
<xsl:value-of select='$coveredelements'/>
75+
</xsl:attribute>
76+
</xsl:if>
77+
<xsl:if test='number(elements) != 0'>
78+
<xsl:attribute name='elements'>
79+
<xsl:value-of select='$elements'/>
80+
</xsl:attribute>
81+
</xsl:if>
82+
<xsl:if test='files != 0'>
83+
<xsl:attribute name='files'>
84+
<xsl:value-of select='$files'/>
85+
</xsl:attribute>
86+
</xsl:if>
87+
</metrics>
88+
</xsl:template>
89+
</xsl:stylesheet>

0 commit comments

Comments
 (0)