mirror of https://github.com/sbt/sbt.git
Merge pull request #3163 from scalacenter/unique-settings-computation
Add duplicated settings test
This commit is contained in:
commit
da21e26339
|
|
@ -0,0 +1,9 @@
|
|||
lazy val root = project
|
||||
|
||||
val checkComputedOnce = taskKey[Unit]("Check computed once")
|
||||
checkComputedOnce := {
|
||||
val buildValue = (foo in ThisBuild).value
|
||||
assert(buildValue == "build 0", "Setting in ThisBuild was computed twice")
|
||||
val globalValue = (foo in Global).value
|
||||
assert(globalValue == "global 0", "Setting in Global was computed twice")
|
||||
}
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
> checkComputedOnce
|
||||
> setUpScripted
|
||||
> checkComputedOnce
|
||||
|
|
@ -0,0 +1,27 @@
|
|||
import java.util.concurrent.atomic.AtomicInteger
|
||||
import sbt._, Keys._
|
||||
|
||||
object A extends AutoPlugin {
|
||||
object autoImport {
|
||||
lazy val foo = settingKey[String]("Foo.")
|
||||
}
|
||||
import autoImport._
|
||||
override def trigger = allRequirements
|
||||
|
||||
override def buildSettings: Seq[Setting[_]] =
|
||||
(foo := s"build ${buildCount.getAndIncrement}") ::
|
||||
Nil
|
||||
|
||||
override def globalSettings: Seq[Setting[_]] =
|
||||
(foo := s"global ${globalCount.getAndIncrement}") ::
|
||||
(commands += setUpScripted) ::
|
||||
Nil
|
||||
|
||||
def setUpScripted = Command.command("setUpScripted") { (state0: State) =>
|
||||
Project.extract(state0).append(name := "foo", state0)
|
||||
}
|
||||
|
||||
// used to ensure the build-level and global settings are only added once
|
||||
private[this] val buildCount = new AtomicInteger(0)
|
||||
private[this] val globalCount = new AtomicInteger(0)
|
||||
}
|
||||
Loading…
Reference in New Issue