From 7e22880cd010f6be6ea4073e015dbdf6b8497dcb Mon Sep 17 00:00:00 2001 From: Havoc Pennington Date: Sat, 26 Nov 2011 20:33:27 -0500 Subject: [PATCH] add a test-lib and use it to test resource loading behavior --- .../com/typesafe/config/impl/PublicApiTest.scala | 16 ++++++++++++++++ project/Build.scala | 7 +++++-- test-lib/build.sbt | 9 +++++++++ test-lib/src/test/resources/test-lib.conf | 7 +++++++ test-lib/src/test/resources/test01.conf | 11 +++++++++++ 5 files changed, 48 insertions(+), 2 deletions(-) create mode 100644 test-lib/build.sbt create mode 100644 test-lib/src/test/resources/test-lib.conf create mode 100644 test-lib/src/test/resources/test01.conf diff --git a/config/src/test/scala/com/typesafe/config/impl/PublicApiTest.scala b/config/src/test/scala/com/typesafe/config/impl/PublicApiTest.scala index 9a38a997..423147c3 100644 --- a/config/src/test/scala/com/typesafe/config/impl/PublicApiTest.scala +++ b/config/src/test/scala/com/typesafe/config/impl/PublicApiTest.scala @@ -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")) + } } diff --git a/project/Build.scala b/project/Build.scala index 3c6c9fb2..a4a8e2d6 100644 --- a/project/Build.scala +++ b/project/Build.scala @@ -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")) } diff --git a/test-lib/build.sbt b/test-lib/build.sbt new file mode 100644 index 00000000..c1d4c631 --- /dev/null +++ b/test-lib/build.sbt @@ -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 diff --git a/test-lib/src/test/resources/test-lib.conf b/test-lib/src/test/resources/test-lib.conf new file mode 100644 index 00000000..07405e06 --- /dev/null +++ b/test-lib/src/test/resources/test-lib.conf @@ -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. +} diff --git a/test-lib/src/test/resources/test01.conf b/test-lib/src/test/resources/test01.conf new file mode 100644 index 00000000..72e16c36 --- /dev/null +++ b/test-lib/src/test/resources/test01.conf @@ -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 +} +