Skip to content

Commit

Permalink
Add MILL_TEST_RESOURCE_FOLDER to Scala Native tests (#3495)
Browse files Browse the repository at this point in the history
We previously added it to JVM and forgot about native. This adds it and
adds a test

Noticed when porting OS-Lib's tests to 0.12.0-RC1
  • Loading branch information
lihaoyi authored Sep 9, 2024
1 parent 3b42cd2 commit 4ed83d9
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import mill.scalanativelib.api._
import mill.scalanativelib.worker.{ScalaNativeWorkerExternalModule, api => workerApi}
import mill.T
import mill.api.PathRef
import mill.main.client.EnvVars

trait ScalaNativeModule extends ScalaModule { outer =>
def scalaNativeVersion: T[String]
Expand Down Expand Up @@ -352,7 +353,7 @@ trait TestScalaNativeModule extends ScalaNativeModule with TestModule {

val (close, framework) = scalaNativeBridge().getFramework(
nativeLink().toIO,
forkEnv(),
forkEnv() ++ Map(EnvVars.MILL_TEST_RESOURCE_FOLDER -> resources().map(_.path).mkString(";")),
toWorkerApi(logLevel()),
testFramework()
)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
hello world resource text
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ package hellotest

import hello._
import utest._

import java.nio.file._
import java.util.stream.Collectors
object MainTests extends TestSuite {

val tests: Tests = Tests {
Expand All @@ -17,6 +18,16 @@ object MainTests extends TestSuite {
Main.vmName.contains("Scala")
)
}
test("resource") {
val expected = new java.util.ArrayList[Path]()
expected.add(Paths.get(sys.env("MILL_TEST_RESOURCE_FOLDER") + "/hello-resource.txt"))
val listed = Files.list(Paths.get(sys.env("MILL_TEST_RESOURCE_FOLDER"))).collect(Collectors.toList())
assert(listed == expected)
assert(
Files.readString(Paths.get(sys.env("MILL_TEST_RESOURCE_FOLDER") + "/hello-resource.txt")) ==
"hello world resource text"
)
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ object HelloNativeWorldTests extends TestSuite {
val argParserTests = resultMap("hellotest.ArgsParserTests")

assert(
mainTests.size == 2,
mainTests.size == 3,
mainTests("hellotest.MainTests.vmName.containNative").status == "Success",
mainTests("hellotest.MainTests.vmName.containScala").status == "Success",
argParserTests.size == 2,
Expand Down

0 comments on commit 4ed83d9

Please sign in to comment.