Skip to content

Commit

Permalink
Add integration test for nativeResources
Browse files Browse the repository at this point in the history
  • Loading branch information
jchyb committed Mar 25, 2022
1 parent 5ba600d commit 3957588
Showing 1 changed file with 38 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,44 @@ abstract class RunTestDefinitions(val scalaVersionOpt: Option[String])
}
}

test("Resource embedding in Scala Native") {
val projectDir = "nativeres"
val resourceContent = "resource contents"
val resourceFileName = "embeddedfile.txt"
val inputs = TestInputs(
Seq(
os.rel / projectDir / "main.scala" ->
s"""|//> using platform "scala-native"
|//> using nativeResources "true"
|//> using resourceDir "resources"
|
|import java.nio.charset.StandardCharsets
|import java.io.{BufferedReader, InputStreamReader}
|import java.io.FileInputStream
|
|object Main {
| def main(args: Array[String]): Unit = {
| val inputStream = getClass().getResourceAsStream("/$resourceFileName")
| val nativeResourceText = new BufferedReader(
| new InputStreamReader(inputStream, StandardCharsets.UTF_8)
| ).readLine()
| println(nativeResourceText)
| }
|}
|""".stripMargin,
os.rel / projectDir / "resources" / resourceFileName -> resourceContent
)
)
inputs.fromRoot { root =>
val output =
os.proc(TestUtil.cli, extraOptions, projectDir, "-q")
.call(cwd = root)
.out.text().trim
println(output)
expect(output == resourceContent)
}
}

if (actualScalaVersion.startsWith("3.1"))
test("Scala 3 in Scala Native") {
val message = "using Scala 3 Native"
Expand Down

0 comments on commit 3957588

Please sign in to comment.