Skip to content

Commit

Permalink
Merge pull request #366 from livongo/beplat-72-rebase
Browse files Browse the repository at this point in the history
provide possibility to set up data dir(Rebased to newest version)
  • Loading branch information
ckipp01 authored Sep 13, 2021
2 parents 99ba2c1 + 58ae1b3 commit 8d88e71
Show file tree
Hide file tree
Showing 9 changed files with 82 additions and 5 deletions.
15 changes: 15 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,21 @@ 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.

### Override Location for Coverage Data And Report

If desired, one could override the default location for generating the sbt report and data through setting `coverageDataDir`:

Example in data-dir test:
```scala
coverageDataDir := target.value / "custom-test"
```

Can also be set through the sbt set directive
```scala
set coverageDataDir := file("/tmp")
```


## Trouble-shooting failing tests

scoverage does a lot of file writing behind the scenes in order to track which
Expand Down
1 change: 1 addition & 0 deletions src/main/scala/scoverage/ScoverageKeys.scala
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ object ScoverageKeys {
lazy val coverageOutputDebug = settingKey[Boolean]("turn on the debug report")
lazy val coverageOutputTeamCity = settingKey[Boolean]("turn on teamcity reporting")
lazy val coverageScalacPluginVersion = settingKey[String]("version of scalac-scoverage-plugin to use")
lazy val coverageDataDir = settingKey[File]("directory where the measurements and report files will be stored")
// format: on

@deprecated("Use coverageMinimumStmtTotal instead", "v1.8.0")
Expand Down
11 changes: 6 additions & 5 deletions src/main/scala/scoverage/ScoverageSbtPlugin.scala
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ object ScoverageSbtPlugin extends AutoPlugin {
ivyConfigurations += ScoveragePluginConfig,
coverageReport := coverageReport0.value,
coverageAggregate := coverageAggregate0.value,
coverageAggregate / aggregate := false
coverageAggregate / aggregate := false,
coverageDataDir := crossTarget.value
) ++ coverageSettings ++ scalacSettings

private lazy val coverageSettings = Seq(
Expand Down Expand Up @@ -99,7 +100,7 @@ object ScoverageSbtPlugin extends AutoPlugin {
Seq(
Some(s"-Xplugin:${pluginPath.getAbsolutePath}"),
Some(
s"-P:scoverage:dataDir:${crossTarget.value.getAbsolutePath}/scoverage-data"
s"-P:scoverage:dataDir:${coverageDataDir.value.getAbsolutePath}/scoverage-data"
),
Option(coverageExcludedPackages.value.trim)
.filter(_.nonEmpty)
Expand Down Expand Up @@ -136,7 +137,7 @@ object ScoverageSbtPlugin extends AutoPlugin {
}

private lazy val coverageReport0 = Def.task {
val target = crossTarget.value
val target = coverageDataDir.value
implicit val log = streams.value.log

log.info(s"Waiting for measurement data to sync...")
Expand Down Expand Up @@ -169,13 +170,13 @@ object ScoverageSbtPlugin extends AutoPlugin {
implicit val log = streams.value.log
log.info(s"Aggregating coverage from subprojects...")

val dataDirs = crossTarget
val dataDirs = coverageDataDir
.all(aggregateFilter)
.value map (_ / Constants.DataDir) filter (_.isDirectory)
CoverageAggregator.aggregate(dataDirs) match {
case Some(cov) =>
writeReports(
crossTarget.value,
coverageDataDir.value,
sourceDirectories.all(aggregateFilter).value.flatten,
cov,
coverageOutputCobertura.value,
Expand Down
17 changes: 17 additions & 0 deletions src/sbt-test/scoverage/data-dir/build.sbt
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
version := "0.1"

scalaVersion := "2.13.6"

libraryDependencies += "org.specs2" %% "specs2-core" % "4.12.10" % "test"

coverageDataDir := target.value / "custom-test"

coverageMinimum := 80

coverageFailOnMinimum := true

resolvers ++= {
if (sys.props.get("plugin.version").exists(_.endsWith("-SNAPSHOT")))
Seq(Resolver.sonatypeRepo("snapshots"))
else Seq.empty
}
1 change: 1 addition & 0 deletions src/sbt-test/scoverage/data-dir/project/build.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
sbt.version=1.5.3
16 changes: 16 additions & 0 deletions src/sbt-test/scoverage/data-dir/project/plugins.sbt
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
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
object GoodCoverage {

def sum(num1: Int, num2: Int) = {
num1 + num2
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import org.specs2.mutable._

/**
* Created by tbarke001c on 7/8/14.
*/
class GoodCoverageSpec extends Specification {

"GoodCoverage" should {
"sum two numbers" in {
GoodCoverage.sum(1, 2) mustEqual 3
}
}
}
7 changes: 7 additions & 0 deletions src/sbt-test/scoverage/data-dir/test
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# run scoverage
> clean
> coverage
> test
> coverageReport
$ exists target/custom-test/scoverage-data
$ exists target/custom-test/scoverage-report

0 comments on commit 8d88e71

Please sign in to comment.