Skip to content

Added generating Clover xml reports #35

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Dec 25, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion getcov
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# Copyright 2015 Jonathan M. Reid. See LICENSE.txt

usage() {
echo "usage: getcov [[-s] [-x] [-o output_dir] [-i info_file] [-v]] | [-h]]"
echo "usage: getcov [[-s] [-x] [-xc] [-o output_dir] [-i info_file] [-v]] | [-h]]"
}

main() {
Expand All @@ -22,6 +22,11 @@ main() {
generate_xml=1
echo "Generate Cobertura XML"
;;
-xc|--xmlclover)
generate_xml=1
generate_xml_clover=1
echo "Generate Clover XML"
;;
-o)
shift
output_dir=$1
Expand Down Expand Up @@ -61,6 +66,10 @@ main() {
generate_cobertura_xml
fi

if [ "$generate_xml_clover" = "1" ]; then
generate_clover_xml
fi

generate_html_report

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

generate_clover_xml () {
if [ "$verbose" = "1" ]; then
echo "XcodeCoverage: Generating Clover XML"
fi
xsltproc "${scripts}/transform.xslt" "coverage.xml" > "clover.xml"
}

show_html_report() {
if [ "$verbose" = "1" ]; then
echo "XcodeCoverage: Opening HTML report"
Expand Down
89 changes: 89 additions & 0 deletions transform.xslt
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
<?xml version="1.0"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml"/>
<!-- This template processes the root node ("/") -->
<xsl:template match="/">
<coverage>
<xsl:attribute name='generated'>
<xsl:value-of select='/coverage/@timestamp'/>
</xsl:attribute>
<project>
<xsl:attribute name='timestamp'>
<xsl:value-of select='/coverage/@timestamp'/>
</xsl:attribute>
<xsl:apply-templates
select='//classes'/>
<xsl:variable name='ncloc' select='count(current()//line)'/>
<xsl:call-template name='metrics'>
<xsl:with-param name='ncloc'
select="$ncloc"
/>
<xsl:with-param name='files'
select="count(current()//classes)"
/>
<xsl:with-param name='elements'
select='$ncloc'/>
<xsl:with-param name='coveredelements'
select='number($ncloc) - count(current()//line[number(@hits) = 0])'/>
</xsl:call-template>
</project>
</coverage>
</xsl:template>
<xsl:template match="class">
<file>
<xsl:attribute name='name'>
<xsl:value-of select='current()/@filename'/>
</xsl:attribute>
<xsl:for-each select='lines/line'>
<line type='stmt'>
<xsl:attribute name='num'>
<xsl:value-of select='current()/@number'/>
</xsl:attribute>
<xsl:attribute name='count'>
<xsl:value-of select='current()/@hits'/>
</xsl:attribute>
</line>
</xsl:for-each>
<xsl:variable name='ncloc' select='count(current()//line)'/>
<xsl:call-template name='metrics'>
<xsl:with-param name='ncloc'
select="$ncloc"
/>
<xsl:with-param name='files'
select="count(current()//classes)"
/>
<xsl:with-param name='elements'
select='$ncloc'/>
<xsl:with-param name='coveredelements'
select='number($ncloc) - count(current()//line[number(@hits) = 0])'/>
</xsl:call-template>
</file>
</xsl:template>
<xsl:template name='metrics'>
<xsl:param name='elements' select='number(0)'/>
<xsl:param name='coveredelements' select='number(0)'/>
<xsl:param name='files'/>
<xsl:param name='ncloc' select='number(0)'/>
<metrics>
<xsl:attribute name='ncloc'>
<xsl:value-of select='$ncloc'/>
</xsl:attribute>
<xsl:if test='number(coveredelements) != 0'>
<xsl:attribute name='coveredelements'>
<xsl:value-of select='$coveredelements'/>
</xsl:attribute>
</xsl:if>
<xsl:if test='number(elements) != 0'>
<xsl:attribute name='elements'>
<xsl:value-of select='$elements'/>
</xsl:attribute>
</xsl:if>
<xsl:if test='files != 0'>
<xsl:attribute name='files'>
<xsl:value-of select='$files'/>
</xsl:attribute>
</xsl:if>
</metrics>
</xsl:template>
</xsl:stylesheet>