[2.x] test: Add regression test for resource reading (#9552)

This commit is contained in:
eugene yokota 2026-08-04 15:03:25 -04:00 committed by GitHub
parent 25445191d7
commit 380ff6b569
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 30 additions and 14 deletions

View File

@ -1,3 +1,3 @@
scalaVersion := "2.12.21" scalaVersion := "3.8.4"
val specs = "org.specs2" %% "specs2-core" % "4.3.4" val munit = "org.scalameta" %% "munit" % "1.0.4"
libraryDependencies += specs % Test libraryDependencies += munit % Test

View File

@ -1,11 +0,0 @@
import org.specs2.mutable._
object BasicTest extends Specification
{
"Test resource on test classpath" in {
getClass.getResource("TestResource.txt") must not beNull
}
"Main resource on test classpath" in {
getClass.getResource("MainResource.txt") must not beNull
}
}

View File

@ -0,0 +1,27 @@
import munit.FunSuite
class ResourceTest extends FunSuite:
test("Test resource on test classpath"):
assert(getClass.getResource("TestResource.txt") != null)
test("Test resource with slash on test classpath"):
assert(getClass.getResource("/TestResource.txt") != null)
test("Test resource contents"):
val str = new String(
getClass.getResourceAsStream("/TestResource.txt").readAllBytes()
)
assert(str == "Success")
test("Main resource on test classpath"):
assert(getClass.getResource("MainResource.txt") != null)
test("Main resource with slash on test classpath"):
assert(getClass.getResource("/MainResource.txt") != null)
test("Main resource contents"):
val str = new String(
getClass.getResourceAsStream("/MainResource.txt").readAllBytes()
)
assert(str == "Main")
end ResourceTest