Skip to content

Commit

Permalink
Fail build if coverage falls below threshhold.
Browse files Browse the repository at this point in the history
  • Loading branch information
Jasper Blues committed May 30, 2014
1 parent c8e42e4 commit 54af40e
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
9 changes: 5 additions & 4 deletions Scripts/CoverageChecker.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

class CoverageReportSummaryParser {

BigDecimal lineCoveragePercent;
Double lineCoveragePercent;
String lineCoverageDetail;

// ================================================================================================================================== //
Expand Down Expand Up @@ -32,7 +32,7 @@ class CoverageReportSummaryParser {
summary.eachLine {
if (it.startsWith(" lines......:")) {
def lineSummary = it.split("%")
lineCoveragePercent = new BigDecimal(lineSummary[0].substring(15))
lineCoveragePercent = new Double(lineSummary[0].substring(15))
lineCoverageDetail = lineSummary[1].trim()
linesFound = true
}
Expand All @@ -53,11 +53,11 @@ try {
c(longOpt: 'line-coverage', 'Required line coverage', args: 1, type: String, required: true)
}
def opt = cli.parse(args)
if (!opt) return
if (!opt) System.exit(-1)
if (opt.h) cli.usage()

String inputFile = opt.getProperty("f")
BigDecimal requiredCoverage = new BigDecimal(opt.getProperty("c"))
Double requiredCoverage = new Double(opt.getProperty("c"))

println "\nReading coverage file: " + inputFile
OutputStream os = new ByteArrayOutputStream()
Expand All @@ -75,6 +75,7 @@ try {
}
catch (RuntimeException e) {
println "\nError: " + e.getMessage();
System.exit(-1)
}


Expand Down
4 changes: 4 additions & 0 deletions build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
<property name="reports.dir" value="${target.dir}/reports"/>
<property name="tools.paths" value="/bin:/opt/local/bin:/opt/local/sbin:/usr/local/bin:/usr/bin"/>
<property name="scripts.dir" value="${basedir}/Scripts"/>
<property name="required.coverage" value="87.0"/>


<path id="headers">
Expand Down Expand Up @@ -152,6 +153,9 @@

<target name="--build.evaluate" unless="no-fail-tests">
<fail if="tests.failed" message="Tests failed. Report is at ${reports.dir}/test-results"/>
<exec executable="${scripts.dir}/CoverageChecker.groovy" failifexecutionfails="true" failonerror="true">
<arg line="-f ${temp.dir}/${module.name}.info -c ${required.coverage}"/>
</exec>
</target>

<target name="--assemble.coverage.data">
Expand Down

0 comments on commit 54af40e

Please sign in to comment.