mirror of https://github.com/sbt/sbt.git
Add scripted tests for resources
In sbt 1.3.0-RC1, when the dependency layers are used, the dependencies cannot see the project resources. This can be problematic when the library requires certain files like logback.xml to work. This introduces a scripted test for this case. The next commit should fix this test.
This commit is contained in:
parent
a128ddf4a6
commit
2268d91b47
|
|
@ -0,0 +1,5 @@
|
|||
resolvers += "Local Maven" at (baseDirectory.value / "libraries" / "foo" / "ivy").toURI.toURL.toString
|
||||
|
||||
libraryDependencies += "sbt" %% "foo-lib" % "0.1.0"
|
||||
|
||||
libraryDependencies += "org.scalatest" %% "scalatest" % "3.0.5" % "test"
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
package scripted
|
||||
|
||||
import org.scalatest.FlatSpec
|
||||
|
||||
class ResourceTest extends FlatSpec {
|
||||
"test resources" should "load" in {
|
||||
Main.main(Array("bar.txt", "updated-test"))
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1 @@
|
|||
updated-main
|
||||
|
|
@ -0,0 +1 @@
|
|||
updated-test
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
name := "foo-lib"
|
||||
|
||||
organization := "sbt"
|
||||
|
||||
publishTo := Some(Resolver.file("test-resolver", file("").getCanonicalFile / "ivy"))
|
||||
|
||||
version := "0.1.0"
|
||||
|
||||
classLoaderLayeringStrategy := ClassLoaderLayeringStrategy.Dependencies
|
||||
|
||||
Test / classLoaderLayeringStrategy := ClassLoaderLayeringStrategy.Dependencies
|
||||
Binary file not shown.
|
|
@ -0,0 +1 @@
|
|||
9bab3dca3e061fdbbff2419ef0eee90d
|
||||
|
|
@ -0,0 +1 @@
|
|||
11081018ca6824226893b153fe439d3a94e23286
|
||||
Binary file not shown.
|
|
@ -0,0 +1 @@
|
|||
afba811024a110dc47734c6d9ec0eb5b
|
||||
|
|
@ -0,0 +1 @@
|
|||
e4e1b37d77060a77ab20c508df90cdae6125f3bc
|
||||
Binary file not shown.
|
|
@ -0,0 +1 @@
|
|||
6de1cfe8548a007ac08763ab5f051e08
|
||||
|
|
@ -0,0 +1 @@
|
|||
f25267dfe760e734ea4f8a00b8dc6ace477589d6
|
||||
|
|
@ -0,0 +1,20 @@
|
|||
<?xml version='1.0' encoding='UTF-8'?>
|
||||
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>sbt</groupId>
|
||||
<artifactId>foo-lib_2.12</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
<description>foo-lib</description>
|
||||
<version>0.1.0</version>
|
||||
<name>foo-lib</name>
|
||||
<organization>
|
||||
<name>sbt</name>
|
||||
</organization>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.scala-lang</groupId>
|
||||
<artifactId>scala-library</artifactId>
|
||||
<version>2.12.8</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
|
|
@ -0,0 +1 @@
|
|||
b83994a1d5ecfc3d6ff71021649e342d
|
||||
|
|
@ -0,0 +1 @@
|
|||
6b2c0b4d69ed8e10e0221db841e0f1fdeef12780
|
||||
|
|
@ -0,0 +1 @@
|
|||
sbt.version=1.3.0-RC1
|
||||
|
|
@ -0,0 +1,19 @@
|
|||
package resource
|
||||
|
||||
import java.net.URL
|
||||
import java.nio.file._
|
||||
import java.util.Collections
|
||||
|
||||
object Resource {
|
||||
def readFile(url: URL): String = {
|
||||
val uri = url.toURI
|
||||
val fileSystem =
|
||||
if (uri.getScheme != "jar") None
|
||||
else Some(FileSystems.newFileSystem(uri, Collections.emptyMap[String, Object]))
|
||||
try new String(Files.readAllBytes(Paths.get(uri)))
|
||||
finally fileSystem.foreach(_.close())
|
||||
}
|
||||
def getStringResource(name: String): String = {
|
||||
readFile(Resource.getClass.getClassLoader.getResource(name))
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1 @@
|
|||
main
|
||||
|
|
@ -0,0 +1,10 @@
|
|||
package scripted
|
||||
|
||||
import resource.Resource
|
||||
|
||||
object Main {
|
||||
def main(args: Array[String]): Unit = {
|
||||
val Array(resource, expected) = args
|
||||
assert(Resource.getStringResource(resource) == expected)
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1 @@
|
|||
test
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
package scripted
|
||||
|
||||
import org.scalatest.FlatSpec
|
||||
|
||||
class ResourceTest extends FlatSpec {
|
||||
"test resources" should "load" in {
|
||||
Main.main(Array("bar.txt", "test"))
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,15 @@
|
|||
> run foo.txt main
|
||||
|
||||
$ copy-file changes/updated-main.txt src/main/resources/foo.txt
|
||||
|
||||
> run foo.txt updated-main
|
||||
|
||||
> test
|
||||
|
||||
$ copy-file changes/updated-test.txt src/test/resources/bar.txt
|
||||
|
||||
-> test
|
||||
|
||||
$ copy-file changes/UpdatedResourceTest.scala src/test/scala/scripted/ResourceTest.scala
|
||||
|
||||
> test
|
||||
Loading…
Reference in New Issue