Skip to content

Commit fdc2541

Browse files
#132 clarify when reports are generated and when minimums are applied
1 parent de3830e commit fdc2541

File tree

3 files changed

+26
-37
lines changed

3 files changed

+26
-37
lines changed

README.md

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ discussion on scoverage.
1414

1515
Add the plugin to your build with the following in project/plugins.sbt:
1616
```scala
17-
addSbtPlugin("org.scoverage" % "sbt-scoverage" % "1.3.1")
17+
addSbtPlugin("org.scoverage" % "sbt-scoverage" % "1.3.2")
1818
```
1919

2020
Then run the your tests with coverage enabled by entering:
@@ -58,7 +58,11 @@ Next, the keys have been renamed slightly. The new names begin with coverageXXX,
5858

5959
## Multi project reports
6060

61-
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).
61+
By default, scoverage will generate reports for each project seperately. You can merge them into an aggregated report by invoking `sbt coverageAggregate`.
62+
63+
(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).)
64+
65+
(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.)
6266

6367
## Exclude classes and packages
6468

@@ -94,6 +98,9 @@ coverageMinimum := 80
9498
coverageFailOnMinimum := true
9599
```
96100

101+
These settings will be enforced when the reports are generated.
102+
If you generate an aggregate report using `coverageAggregate` then these settings will apply to that report.
103+
97104
## Highlighting
98105

99106
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:

src/main/scala/scoverage/ScoverageSbtPlugin.scala

Lines changed: 16 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,6 @@ object ScoverageSbtPlugin extends AutoPlugin {
2424
commands += Command.command("coverage", "enable compiled code with instrumentation", "")(toggleCoverage(true)),
2525
commands += Command.command("coverageOff", "disable compiled code with instrumentation", "")(toggleCoverage(false)),
2626
coverageReport <<= coverageReport0,
27-
testOptions in Test += postTestReport.value,
28-
testOptions in IntegrationTest += postTestReport.value,
2927
coverageAggregate <<= coverageAggregate0,
3028
libraryDependencies ++= Seq(
3129
OrgScoverage % (ScalacRuntimeArtifact + "_" + scalaBinaryVersion.value) % ScoverageVersion % "provided" intransitive(),
@@ -65,14 +63,18 @@ object ScoverageSbtPlugin extends AutoPlugin {
6563
Thread.sleep(1000) // have noticed some delay in writing on windows, hacky but works
6664

6765
loadCoverage(target, log) match {
68-
case Some(cov) => writeReports(target,
69-
(sourceDirectories in Compile).value,
70-
cov,
71-
coverageOutputCobertura.value,
72-
coverageOutputXML.value,
73-
coverageOutputHTML.value,
74-
coverageOutputDebug.value,
75-
log)
66+
case Some(cov) =>
67+
writeReports(
68+
target,
69+
(sourceDirectories in Compile).value,
70+
cov,
71+
coverageOutputCobertura.value,
72+
coverageOutputXML.value,
73+
coverageOutputHTML.value,
74+
coverageOutputDebug.value,
75+
log)
76+
77+
checkCoverage(cov, log, coverageMinimum.value, coverageFailOnMinimum.value)
7678
case None => log.warn("No coverage data, skipping reports")
7779
}
7880
}
@@ -84,7 +86,8 @@ object ScoverageSbtPlugin extends AutoPlugin {
8486
val xmlReportFiles = crossTarget.all(aggregateFilter).value map (_ / "scoverage-report" / Constants.XMLReportFilename) filter (_.isFile())
8587
CoverageAggregator.aggregate(xmlReportFiles, coverageCleanSubprojectFiles.value) match {
8688
case Some(cov) =>
87-
writeReports(crossTarget.value,
89+
writeReports(
90+
crossTarget.value,
8891
sourceDirectories.all(aggregateFilter).value.flatten,
8992
cov,
9093
coverageOutputCobertura.value,
@@ -94,6 +97,8 @@ object ScoverageSbtPlugin extends AutoPlugin {
9497
log)
9598
val cfmt = cov.statementCoverageFormatted
9699
log.info(s"Aggregation complete. Coverage was [$cfmt]")
100+
101+
checkCoverage(cov, log, coverageMinimum.value, coverageFailOnMinimum.value)
97102
case None =>
98103
log.info("No subproject data to aggregate, skipping reports")
99104
}
@@ -113,29 +118,6 @@ object ScoverageSbtPlugin extends AutoPlugin {
113118
}
114119
}
115120

116-
private lazy val postTestReport = Def.task {
117-
val log = streams.value.log
118-
val target = crossTarget.value
119-
Tests.Cleanup {
120-
() => if (coverageEnabled.value) {
121-
loadCoverage(target, log) foreach { c =>
122-
writeReports(
123-
target,
124-
(sourceDirectories in Compile).value,
125-
c,
126-
coverageOutputCobertura.value,
127-
coverageOutputXML.value,
128-
coverageOutputHTML.value,
129-
coverageOutputDebug.value,
130-
log
131-
)
132-
checkCoverage(c, log, coverageMinimum.value, coverageFailOnMinimum.value)
133-
}
134-
()
135-
}
136-
}
137-
}
138-
139121
private def scalaArgs(coverageEnabled: Boolean,
140122
pluginPath: File,
141123
target: File,

version.sbt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
version in ThisBuild := "1.3.1"
1+
version in ThisBuild := "1.3.2"

0 commit comments

Comments
 (0)