Test for extra properties files

This commit is contained in:
Mark Harrah 2010-04-20 08:41:32 -04:00
parent a5bb434d2a
commit 092a42cf53
5 changed files with 60 additions and 0 deletions

View File

@ -0,0 +1 @@
first.property=set-first

View File

@ -0,0 +1,2 @@
first.property=set-first
second.property=set-second

View File

@ -0,0 +1,2 @@
project.name=test-env
project.version=1.0

View File

@ -0,0 +1,29 @@
import sbt._
class Test(info: ProjectInfo) extends DefaultProject(info)
{
lazy val FirstDefault = "a"
lazy val SecondDefault = "b"
lazy val FirstSet = "set-first"
lazy val SecondSet = "set-second"
lazy val extra = new BasicEnvironment
{
def log = Test.this.log
def envBackingPath = info.builderPath / "extra.properties"
lazy val firstProperty = propertyOptional[String](FirstDefault)
lazy val secondProperty = propertyOptional[String](SecondDefault)
}
import extra.{firstProperty, secondProperty}
lazy val checkFirstUnset = checkTask(firstProperty, FirstDefault, "first.property")
lazy val checkFirstSet = checkTask(firstProperty, FirstSet, "first.property")
lazy val checkSecondUnset = checkTask(secondProperty, SecondDefault, "second.property")
lazy val checkSecondSet = checkTask(secondProperty, SecondSet, "second.property")
def checkTask[T](property: extra.Property[T], expected: T, name: String): Task =
task { if(property.value == expected) None else Some("Expected "+name+" to be '" + expected + "', was: " + property.value) }
}

View File

@ -0,0 +1,26 @@
# check that both properties are unset
> check-first-unset
->check-first-set
> check-second-unset
->check-second-set
# create the extra properties file with only the first property set
$ copy-file changes/first.properties project/extra.properties
> reload
-> check-first-unset
>check-first-set
> check-second-unset
->check-second-set
# create the extra properties file with both properties set
$ copy-file changes/second.properties project/extra.properties
> reload
-> check-first-unset
>check-first-set
-> check-second-unset
>check-second-set