add a test-lib and use it to test resource loading behavior

This commit is contained in:
Havoc Pennington 2011-11-26 20:33:27 -05:00
parent 70fad92b50
commit 7e22880cd0
5 changed files with 48 additions and 2 deletions

View File

@ -386,4 +386,20 @@ class PublicApiTest extends TestUtils {
assertEquals("A", fromResources.getString("fromJsonA"))
assertEquals("true", fromResources.getString("fromProps.bool"))
}
@Test
def resourceFromAnotherClasspath() {
val conf = ConfigFactory.parseResource(classOf[PublicApiTest], "/test-lib.conf", ConfigParseOptions.defaults())
assertEquals("This is to test classpath searches.", conf.getString("test-lib.description"))
}
@Test
def onlyFirstResourceUsed() {
val conf = ConfigFactory.parseResource(classOf[PublicApiTest], "/test01.conf", ConfigParseOptions.defaults())
assertEquals(42, conf.getInt("ints.fortyTwo"))
assertFalse(conf.hasPath("test-lib"))
assertFalse(conf.hasPath("test-lib.fromTestLib"))
}
}

View File

@ -3,8 +3,11 @@ import Keys._
object ConfigBuild extends Build {
lazy val root = Project(id = "root",
base = file(".")) aggregate(configLib)
base = file(".")) aggregate(testLib, configLib)
lazy val configLib = Project(id = "config",
base = file("config"))
base = file("config")) dependsOn(testLib % "test->test")
lazy val testLib = Project(id = "test-lib",
base = file("test-lib"))
}

9
test-lib/build.sbt Normal file
View File

@ -0,0 +1,9 @@
// no binary
publishArtifact in (Compile, packageBin) := false
// no javadoc
publishArtifact in (Compile, packageDoc) := false
// no source
publishArtifact in (Compile, packageSrc) := false

View File

@ -0,0 +1,7 @@
# don't copy anything about how this is done; look at the
# examples/ directory and the docs for things that should be
# copied. this is weird test suite stuff.
test-lib {
description = This is to test classpath searches.
}

View File

@ -0,0 +1,11 @@
# don't copy anything about how this is done; look at the
# examples/ directory and the docs for things that should be
# copied. this is weird test suite stuff.
## Here we are testing that this file test01.conf is NOT seen
## since there's another resource with that name earlier in
## classpath
test-lib {
fromTestLib = true
}