Skip to content

Commit 918bb8e

Browse files
mathieutmtrampont-ama
mathieut
authored andcommitted
Avoid removing settings overrides done during the session when executing toggleCoverage scoverage#146
1 parent 654054b commit 918bb8e

File tree

6 files changed

+60
-1
lines changed

6 files changed

+60
-1
lines changed

src/main/scala/scoverage/ScoverageSbtPlugin.scala

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ object ScoverageSbtPlugin extends AutoPlugin {
4949
*/
5050
private def toggleCoverage(status: Boolean): State => State = { state =>
5151
val extracted = Project.extract(state)
52+
val currentProjRef = extracted.currentRef
5253
val newSettings = extracted.structure.allProjectRefs flatMap { proj =>
5354
Seq(
5455
coverageEnabled in proj := status,
@@ -60,7 +61,9 @@ object ScoverageSbtPlugin extends AutoPlugin {
6061
}
6162
)
6263
}
63-
extracted.append(newSettings, state)
64+
val appendSettings = Load.transformSettings(Load.projectScope(currentProjRef), currentProjRef.build, extracted.rootProject, newSettings)
65+
val newSessionSettings = extracted.session.appendRaw(appendSettings)
66+
SessionSettings.reapply(newSessionSettings, state)
6467
}
6568

6669
private lazy val coverageReport0 = Def.task {
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import sbt.complete.DefaultParsers._
2+
3+
version := "0.1"
4+
5+
scalaVersion := "2.10.4"
6+
7+
libraryDependencies += "org.specs2" %% "specs2" % "2.3.13" % "test"
8+
9+
val checkScalaVersion = inputKey[Unit]("Input task to compare the value of scalaVersion setting with a given input.")
10+
checkScalaVersion := {
11+
val arg: String = (Space ~> StringBasic).parsed
12+
if (scalaVersion.value != arg) error(s"scalaVersion [${scalaVersion.value}] not equal to expected [$arg]")
13+
()
14+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// The Typesafe repository
2+
resolvers += "Typesafe repository" at "http://repo.typesafe.com/typesafe/releases/"
3+
4+
//scoverage needs this
5+
resolvers += Classpaths.sbtPluginReleases
6+
7+
{
8+
val pluginVersion = System.getProperty("plugin.version")
9+
if(pluginVersion == null)
10+
throw new RuntimeException("""|The system property 'plugin.version' is not defined.
11+
|Specify this property using the scriptedLaunchOpts -D.""".stripMargin)
12+
else addSbtPlugin("org.scoverage" %% "sbt-scoverage" % pluginVersion)
13+
}
14+
15+
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
object PreserveSet {
2+
3+
def sum(num1: Int, num2: Int) = {
4+
num1 + num2
5+
}
6+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import org.specs2.mutable._
2+
3+
class PreserveSetSpec extends Specification {
4+
5+
"PreserveSet" should {
6+
"sum two numbers" in {
7+
PreserveSet.sum(1, 2) mustEqual 3
8+
}
9+
}
10+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# check scalaVersion setting
2+
> checkScalaVersion "2.10.4"
3+
# override scalaVersion setting
4+
> set scalaVersion := {"2.10.5"}
5+
> checkScalaVersion "2.10.5"
6+
# activate coverage - override should still be present
7+
> coverage
8+
> checkScalaVersion "2.10.5"
9+
# turn off coverage - override should still be present
10+
> coverageOff
11+
> checkScalaVersion "2.10.5"

0 commit comments

Comments
 (0)