Skip to content

Commit

Permalink
Use global scope for jacoco settings
Browse files Browse the repository at this point in the history
This makes it easier for users to configure as they don't need to scope
using 'jacocoXX in Test'
  • Loading branch information
stringbean committed Oct 23, 2017
1 parent c66bb08 commit d5d68ec
Show file tree
Hide file tree
Showing 8 changed files with 68 additions and 5 deletions.
11 changes: 8 additions & 3 deletions src/main/scala/com/github/sbt/jacoco/BaseJacocoPlugin.scala
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ private[jacoco] abstract class BaseJacocoPlugin extends AutoPlugin with JacocoKe
protected def srcConfig: Configuration

override def projectSettings: Seq[Setting[_]] =
dependencyValues ++ inConfig(srcConfig)(settingValues ++ taskValues)
dependencyValues ++
unscopedSettingValues ++
inConfig(srcConfig)(scopedSettingValues ++ taskValues)

protected def dependencyValues: Seq[Setting[_]] = Seq(
libraryDependencies ++= {
Expand All @@ -40,7 +42,7 @@ private[jacoco] abstract class BaseJacocoPlugin extends AutoPlugin with JacocoKe
}
)

private def settingValues = Seq(
private def unscopedSettingValues = Seq(
jacocoDirectory := crossTarget.value / "jacoco",
jacocoReportDirectory := jacocoDirectory.value / "report",
jacocoSourceSettings := JacocoSourceSettings(),
Expand All @@ -49,7 +51,10 @@ private[jacoco] abstract class BaseJacocoPlugin extends AutoPlugin with JacocoKe
jacocoIncludes := Seq("*"),
jacocoExcludes := Seq(),
jacocoInstrumentedDirectory := jacocoDirectory.value / "instrumented-classes",
jacocoDataFile := jacocoDataDirectory.value / "jacoco.exec",
jacocoDataFile := jacocoDataDirectory.value / "jacoco.exec"
)

private def scopedSettingValues = Seq(
javaOptions ++= {
val dest = jacocoDataFile.value

Expand Down
2 changes: 1 addition & 1 deletion src/main/scala/com/github/sbt/jacoco/JacocoItPlugin.scala
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ object JacocoItPlugin extends BaseJacocoPlugin {
Defaults.itSettings ++
super.projectSettings ++
// move the test reports to a subdirectory to disambiguate
Seq(jacocoReportDirectory in Test := (jacocoDirectory in Test).value / "report" / "test") ++
Seq(jacocoReportDirectory := (jacocoDirectory in Test).value / "report" / "test") ++
inConfig(IntegrationTest) {
Seq(
jacocoReportDirectory := jacocoDirectory.value / "report" / "it",
Expand Down
18 changes: 18 additions & 0 deletions src/sbt-test/sbt-jacoco/simple-scoped/build.sbt
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
name := "jacocoTest"
organization := "com.navetas"

scalaVersion := "2.10.4"
scalacOptions ++= Seq("-deprecation", "-optimize", "-unchecked", "-Xlint", "-language:_")

libraryDependencies += "org.scalatest" %% "scalatest" % "3.0.4" % "test"

jacocoReportSettings in Test := JacocoReportSettings()
.withThresholds(
JacocoThresholds(
instruction = 100,
method = 100,
branch = 100,
complexity = 100,
line = 100,
clazz = 100)
)
8 changes: 8 additions & 0 deletions src/sbt-test/sbt-jacoco/simple-scoped/project/plugins.sbt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
val pluginVersion = System.getProperty("plugin.version")
if (pluginVersion == null)
throw new RuntimeException("""|The system property 'plugin.version' is not defined.
|Specify this property using the parameter -Dplugin.version=<version>""".stripMargin)

else addSbtPlugin("com.github.sbt" % "sbt-jacoco" % pluginVersion)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package jacocotest

case class TestClass( val x : Int )
{
def double() : Int = x * 2

def triple() : Int = x * 3
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package jacocotest

import org.scalatest.FlatSpec

class TestClassTests extends FlatSpec
{
"TestClass" should "double a number correctly" in
{
assert( new TestClass( 2 ).double === 4 )
}
}
13 changes: 13 additions & 0 deletions src/sbt-test/sbt-jacoco/simple-scoped/test
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
> clean

# coverage should fail
-> jacoco

# instrumented classes
$ exists target/scala-2.10/jacoco/instrumented-classes

# results
$ exists target/scala-2.10/jacoco/data/jacoco.exec

# html report
$ exists target/scala-2.10/jacoco/report/html/index.html
2 changes: 1 addition & 1 deletion src/sbt-test/sbt-jacoco/simple/build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ scalacOptions ++= Seq("-deprecation", "-optimize", "-unchecked", "-Xlint", "-lan

libraryDependencies += "org.scalatest" %% "scalatest" % "3.0.4" % "test"

jacocoReportSettings in Test := JacocoReportSettings()
jacocoReportSettings := JacocoReportSettings()
.withThresholds(
JacocoThresholds(
instruction = 100,
Expand Down

0 comments on commit d5d68ec

Please sign in to comment.