Skip to content

Ensure reporting and aggregation still works when disabling modules. #377

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 1 commit into from
Oct 11, 2021
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: 6 additions & 3 deletions src/main/scala/scoverage/ScoverageSbtPlugin.scala
Original file line number Diff line number Diff line change
Expand Up @@ -170,9 +170,12 @@ object ScoverageSbtPlugin extends AutoPlugin {
implicit val log = streams.value.log
log.info(s"Aggregating coverage from subprojects...")

val dataDirs = coverageDataDir
.all(aggregateFilter)
.value map (_ / Constants.DataDir) filter (_.isDirectory)
val dataDirs = coverageDataDir.?.all(aggregateFilter).value
.collect {
case Some(file) if (file / Constants.DataDir).isDirectory =>
file / Constants.DataDir
}

CoverageAggregator.aggregate(dataDirs) match {
case Some(cov) =>
writeReports(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package a

object AdderScala {

def add(x: Int, y: Int) = x + y

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import munit.FunSuite
import a.AdderScala

class AdderTestSuite extends FunSuite {
test("Adder should sum two numbers") {
assertEquals(AdderScala.add(1, 2), 3)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package b

object AdderScala {

def add(x: Int, y: Int) = x + y

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import munit.FunSuite
import b.AdderScala

class AdderTestSuite extends FunSuite {
test("Adder should sum two numbers") {
assertEquals(AdderScala.add(1, 2), 3)
}
}
17 changes: 17 additions & 0 deletions src/sbt-test/scoverage/aggregate-disabled-module/build.sbt
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
inThisBuild(
List(
organization := "org.scoverage",
scalaVersion := "2.13.6",
libraryDependencies += "org.scalameta" %% "munit" % "0.7.25" % Test
)
)

lazy val a = project
lazy val b = project
lazy val c = project.disablePlugins(ScoverageSbtPlugin)

ThisBuild / resolvers ++= {
if (sys.props.get("plugin.version").exists(_.endsWith("-SNAPSHOT")))
Seq(Resolver.sonatypeRepo("snapshots"))
else Seq.empty
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package c

object AdderScala {

def add(x: Int, y: Int) = x + y

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import munit.FunSuite
import c.AdderScala

class AdderTestSuite extends FunSuite {
test("Adder should sum two numbers") {
assertEquals(AdderScala.add(1, 2), 3)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
sbt.version=1.5.5
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
val pluginVersion = sys.props.getOrElse(
"plugin.version",
throw new RuntimeException(
"""|The system property 'plugin.version' is not defined.
|Specify this property using the scriptedLaunchOpts -D.""".stripMargin
)
)

addSbtPlugin("org.scoverage" % "sbt-scoverage" % pluginVersion)

resolvers ++= {
if (pluginVersion.endsWith("-SNAPSHOT"))
Seq(Resolver.sonatypeRepo("snapshots"))
else
Seq.empty
}
16 changes: 16 additions & 0 deletions src/sbt-test/scoverage/aggregate-disabled-module/test
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# run scoverage using the coverage task
> clean
> coverage
> test
# There should be scoverage-data directory
$ exists a/target/scala-2.13/scoverage-data
$ exists b/target/scala-2.13/scoverage-data
$ absent c/target/scala-2.13/scoverage-data
> coverageReport
# There should be scoverage-report directory
$ exists a/target/scala-2.13/scoverage-report
$ exists b/target/scala-2.13/scoverage-report
$ absent c/target/scala-2.13/scoverage-report
> coverageAggregate
# There should be a root scoverage-report directory
$ exists target/scala-2.13/scoverage-report