Skip to content

Avoid removing settings overrides done during the session when executing toggleCoverage #186

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
Sep 20, 2016
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
8 changes: 6 additions & 2 deletions src/main/scala/scoverage/ScoverageSbtPlugin.scala
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,13 @@ object ScoverageSbtPlugin extends AutoPlugin {
*/
private def toggleCoverage(status: Boolean): State => State = { state =>
val extracted = Project.extract(state)
val currentProjRef = extracted.currentRef
val newSettings = extracted.structure.allProjectRefs.flatMap(proj =>
Seq(coverageEnabled in proj := status))
extracted.append(newSettings, state)
Seq(coverageEnabled in proj := status)
)
val appendSettings = Load.transformSettings(Load.projectScope(currentProjRef), currentProjRef.build, extracted.rootProject, newSettings)
val newSessionSettings = extracted.session.appendRaw(appendSettings)
SessionSettings.reapply(newSessionSettings, state)
}

// returns "_sjs$sjsVersion" for Scala.js projects or "" otherwise
Expand Down
19 changes: 19 additions & 0 deletions src/sbt-test/scoverage/preserve-set/build.sbt
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import sbt.complete.DefaultParsers._

version := "0.1"

scalaVersion := "2.10.4"

libraryDependencies += "org.specs2" %% "specs2" % "2.3.13" % "test"

val checkScalaVersion = inputKey[Unit]("Input task to compare the value of scalaVersion setting with a given input.")
checkScalaVersion := {
val arg: String = (Space ~> StringBasic).parsed
if (scalaVersion.value != arg) error(s"scalaVersion [${scalaVersion.value}] not equal to expected [$arg]")
()
}

resolvers ++= {
if (sys.props.get("plugin.version").map(_.endsWith("-SNAPSHOT")).getOrElse(false)) Seq(Resolver.sonatypeRepo("snapshots"))
else Seq.empty
}
20 changes: 20 additions & 0 deletions src/sbt-test/scoverage/preserve-set/project/plugins.sbt
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// The Typesafe repository
resolvers += "Typesafe repository" at "http://repo.typesafe.com/typesafe/releases/"

//scoverage needs this
resolvers += Classpaths.sbtPluginReleases

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 PreserveSet {

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

class PreserveSetSpec extends Specification {

"PreserveSet" should {
"sum two numbers" in {
PreserveSet.sum(1, 2) mustEqual 3
}
}
}
11 changes: 11 additions & 0 deletions src/sbt-test/scoverage/preserve-set/test
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# check scalaVersion setting
> checkScalaVersion "2.10.4"
# override scalaVersion setting
> set scalaVersion := {"2.10.5"}
> checkScalaVersion "2.10.5"
# activate coverage - override should still be present
> coverage
> checkScalaVersion "2.10.5"
# turn off coverage - override should still be present
> coverageOff
> checkScalaVersion "2.10.5"