Skip to content

Commit bb99b2c

Browse files
committed
Ensure reporting and aggregation still works when disabling modules.
In the past reporting and aggregation would fail when you tried to disable Scoverage for a specific module. This now will only take into account the modules that have the keys defined rather than defaulting to all of them. Closes #376
1 parent c190f3d commit bb99b2c

File tree

11 files changed

+101
-3
lines changed

11 files changed

+101
-3
lines changed

src/main/scala/scoverage/ScoverageSbtPlugin.scala

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -170,9 +170,12 @@ object ScoverageSbtPlugin extends AutoPlugin {
170170
implicit val log = streams.value.log
171171
log.info(s"Aggregating coverage from subprojects...")
172172

173-
val dataDirs = coverageDataDir
174-
.all(aggregateFilter)
175-
.value map (_ / Constants.DataDir) filter (_.isDirectory)
173+
val dataDirs = coverageDataDir.?.all(aggregateFilter).value
174+
.collect {
175+
case Some(file) if (file / Constants.DataDir).isDirectory =>
176+
file / Constants.DataDir
177+
}
178+
176179
CoverageAggregator.aggregate(dataDirs) match {
177180
case Some(cov) =>
178181
writeReports(
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package a
2+
3+
object AdderScala {
4+
5+
def add(x: Int, y: Int) = x + y
6+
7+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import munit.FunSuite
2+
import a.AdderScala
3+
4+
class AdderTestSuite extends FunSuite {
5+
test("Adder should sum two numbers") {
6+
assertEquals(AdderScala.add(1, 2), 3)
7+
}
8+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package b
2+
3+
object AdderScala {
4+
5+
def add(x: Int, y: Int) = x + y
6+
7+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import munit.FunSuite
2+
import b.AdderScala
3+
4+
class AdderTestSuite extends FunSuite {
5+
test("Adder should sum two numbers") {
6+
assertEquals(AdderScala.add(1, 2), 3)
7+
}
8+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
inThisBuild(
2+
List(
3+
organization := "org.scoverage",
4+
scalaVersion := "2.13.6",
5+
libraryDependencies += "org.scalameta" %% "munit" % "0.7.25" % Test
6+
)
7+
)
8+
9+
lazy val a = project
10+
lazy val b = project
11+
lazy val c = project.disablePlugins(ScoverageSbtPlugin)
12+
13+
ThisBuild / resolvers ++= {
14+
if (sys.props.get("plugin.version").exists(_.endsWith("-SNAPSHOT")))
15+
Seq(Resolver.sonatypeRepo("snapshots"))
16+
else Seq.empty
17+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package c
2+
3+
object AdderScala {
4+
5+
def add(x: Int, y: Int) = x + y
6+
7+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import munit.FunSuite
2+
import c.AdderScala
3+
4+
class AdderTestSuite extends FunSuite {
5+
test("Adder should sum two numbers") {
6+
assertEquals(AdderScala.add(1, 2), 3)
7+
}
8+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
sbt.version=1.5.5
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
val pluginVersion = sys.props.getOrElse(
2+
"plugin.version",
3+
throw new RuntimeException(
4+
"""|The system property 'plugin.version' is not defined.
5+
|Specify this property using the scriptedLaunchOpts -D.""".stripMargin
6+
)
7+
)
8+
9+
addSbtPlugin("org.scoverage" % "sbt-scoverage" % pluginVersion)
10+
11+
resolvers ++= {
12+
if (pluginVersion.endsWith("-SNAPSHOT"))
13+
Seq(Resolver.sonatypeRepo("snapshots"))
14+
else
15+
Seq.empty
16+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# run scoverage using the coverage task
2+
> clean
3+
> coverage
4+
> test
5+
# There should be scoverage-data directory
6+
$ exists a/target/scala-2.13/scoverage-data
7+
$ exists b/target/scala-2.13/scoverage-data
8+
$ absent c/target/scala-2.13/scoverage-data
9+
> coverageReport
10+
# There should be scoverage-report directory
11+
$ exists a/target/scala-2.13/scoverage-report
12+
$ exists b/target/scala-2.13/scoverage-report
13+
$ absent c/target/scala-2.13/scoverage-report
14+
> coverageAggregate
15+
# There should be a root scoverage-report directory
16+
$ exists target/scala-2.13/scoverage-report

0 commit comments

Comments
 (0)