Skip to content

#132 clarify when reports are generated and when minimums are applied #133

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 4 commits into from
Dec 2, 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
9 changes: 8 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,11 @@ Next, the keys have been renamed slightly. The new names begin with coverageXXX,

## Multi project reports

By default, scoverage will generate reports for each project seperately. You can merge them into an aggregated report by invoking `sbt coverageAggregate`. Note, you must do this after all the coverage data is complete as a separate command, so you cannot do `sbt coverage test coverageAggregate` (at least until a way around this is found).
By default, scoverage will generate reports for each project seperately. You can merge them into an aggregated report by invoking `sbt coverageAggregate`.

(Note, you must do this after all the coverage data is complete as a separate command, so you cannot do `sbt coverage test coverageAggregate` (at least until a way around this is found).)

(You must have first run `sbt coverageReport` for `coverageAggregate` to work. It aggregates over the sub-projects' report xml rather than over the coverage data directly.)

## Exclude classes and packages

Expand Down Expand Up @@ -94,6 +98,9 @@ coverageMinimum := 80
coverageFailOnMinimum := true
```

These settings will be enforced when the reports are generated.
If you generate an aggregate report using `coverageAggregate` then these settings will apply to that report.

## Highlighting

If you are using Scala 2.11.1 or less, then highlighting will not work (due to this bug which was fixed in 2.11.2 https://github.com/scala/scala/pull/3799). In that case you must disable highlighting by adding the following to your build:
Expand Down
53 changes: 17 additions & 36 deletions src/main/scala/scoverage/ScoverageSbtPlugin.scala
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@ object ScoverageSbtPlugin extends AutoPlugin {
commands += Command.command("coverage", "enable compiled code with instrumentation", "")(toggleCoverage(true)),
commands += Command.command("coverageOff", "disable compiled code with instrumentation", "")(toggleCoverage(false)),
coverageReport <<= coverageReport0,
testOptions in Test += postTestReport.value,
testOptions in IntegrationTest += postTestReport.value,
coverageAggregate <<= coverageAggregate0,
libraryDependencies ++= Seq(
OrgScoverage % (ScalacRuntimeArtifact + "_" + scalaBinaryVersion.value) % ScoverageVersion % "provided" intransitive(),
Expand Down Expand Up @@ -67,15 +65,19 @@ object ScoverageSbtPlugin extends AutoPlugin {
Thread.sleep(1000) // have noticed some delay in writing on windows, hacky but works

loadCoverage(target, log) match {
case Some(cov) => writeReports(target,
(sourceDirectories in Compile).value,
cov,
coverageOutputCobertura.value,
coverageOutputXML.value,
coverageOutputHTML.value,
coverageOutputDebug.value,
coverageOutputTeamCity.value,
log)
case Some(cov) =>
writeReports(
target,
(sourceDirectories in Compile).value,
cov,
coverageOutputCobertura.value,
coverageOutputXML.value,
coverageOutputHTML.value,
coverageOutputDebug.value,
coverageOutputTeamCity.value,
log)

checkCoverage(cov, log, coverageMinimum.value, coverageFailOnMinimum.value)
case None => log.warn("No coverage data, skipping reports")
}
}
Expand All @@ -87,7 +89,8 @@ object ScoverageSbtPlugin extends AutoPlugin {
val xmlReportFiles = crossTarget.all(aggregateFilter).value map (_ / "scoverage-report" / Constants.XMLReportFilename) filter (_.isFile())
CoverageAggregator.aggregate(xmlReportFiles, coverageCleanSubprojectFiles.value) match {
case Some(cov) =>
writeReports(crossTarget.value,
writeReports(
crossTarget.value,
sourceDirectories.all(aggregateFilter).value.flatten,
cov,
coverageOutputCobertura.value,
Expand All @@ -98,6 +101,8 @@ object ScoverageSbtPlugin extends AutoPlugin {
log)
val cfmt = cov.statementCoverageFormatted
log.info(s"Aggregation complete. Coverage was [$cfmt]")

checkCoverage(cov, log, coverageMinimum.value, coverageFailOnMinimum.value)
case None =>
log.info("No subproject data to aggregate, skipping reports")
}
Expand All @@ -117,30 +122,6 @@ object ScoverageSbtPlugin extends AutoPlugin {
}
}

private lazy val postTestReport = Def.task {
val log = streams.value.log
val target = crossTarget.value
Tests.Cleanup {
() => if (coverageEnabled.value) {
loadCoverage(target, log) foreach { c =>
writeReports(
target,
(sourceDirectories in Compile).value,
c,
coverageOutputCobertura.value,
coverageOutputXML.value,
coverageOutputHTML.value,
coverageOutputDebug.value,
coverageOutputTeamCity.value,
log
)
checkCoverage(c, log, coverageMinimum.value, coverageFailOnMinimum.value)
}
()
}
}
}

private def scalaArgs(coverageEnabled: Boolean,
pluginPath: File,
target: File,
Expand Down
3 changes: 2 additions & 1 deletion src/sbt-test/scoverage/bad-coverage/test
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# run scoverage
> clean
> coverage
-> test
> test
-> coverageReport
2 changes: 1 addition & 1 deletion version.sbt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
version in ThisBuild := "1.3.3"
version in ThisBuild := "1.3.4"