Skip to content

Commit c180945

Browse files
committed
Dockerized Scala port tests. See scala_port/README.md
1 parent d4b2fa2 commit c180945

File tree

4 files changed

+56
-2
lines changed

4 files changed

+56
-2
lines changed

source/ports/scala_port/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ DETOUR_LIBRARY_PATH
1818
PORT_LIBRARY_PATH
1919
```
2020

21-
> Note: You'll find the bindings and the code that runs on `sbt test` in `src/main/scala/MetaCall.scala`.
21+
To run the tests in Docker, run `sbt docker` to build the image, and then `sbt dockerTest` to run it. Note that you should build the `metacall/core:dev` image locally since the published one might not be up to date by running `./docker-compose.sh build` in `metacall/core`'s root. Pay attention to SBT's error messages.
2222

2323
## Debugging
2424

source/ports/scala_port/build.sbt

Lines changed: 50 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,58 @@ lazy val commonSettings = Seq(
2525
)
2626
)
2727

28+
lazy val dockerTest = taskKey[Unit]("Run tests in metacall/core:dev")
29+
dockerTest := {
30+
import scala.sys.process._
31+
import java.nio.file.Paths
32+
import sbt.Keys.streams
33+
34+
val logger = streams.value.log
35+
logger.info(
36+
"NOTE: Run `./docker-compose.sh build` in the root of metacall/core first to get the latest metacall/core:dev image"
37+
)
38+
39+
try s"docker run -v ${Paths.get("").toAbsolutePath().toString()}:/tests metacall-scala-tests" !
40+
catch {
41+
case e: Throwable => {
42+
val msg =
43+
e.getMessage() + "\nTIP: Run `sbt build` if the image `metacall-scala-tests` doesn't exist"
44+
45+
logger.err(msg)
46+
47+
throw new Exception(msg)
48+
}
49+
}
50+
}
51+
2852
lazy val root = (project in file("."))
2953
.settings(commonSettings: _*)
3054
.settings(
3155
name := "metacall",
32-
parallelExecution in Test := false
56+
parallelExecution in Test := false,
57+
dockerfile in docker := new Dockerfile {
58+
from("metacall/core:dev")
59+
60+
// Set up Scala and SBT using Coursier
61+
workDir("/")
62+
run("curl", "-fLo", "cs", "https://git.io/coursier-cli-linux")
63+
run("chmod", "+x", "cs")
64+
run("./cs", "setup", "--env", "--jvm", "11", "--apps", "sbt-launcher")
65+
env(
66+
"JAVA_HOME" -> "/root/.cache/coursier/jvm/[email protected]",
67+
"PATH" -> "/root/.cache/coursier/jvm/[email protected]/bin:/root/.local/share/coursier/bin:$PATH"
68+
)
69+
// To set up dependencies and SBT
70+
import java.nio.file.Paths
71+
copy(Paths.get("").toAbsolutePath().toFile(), new File("/_tests"))
72+
workDir("/_tests")
73+
run("sbt", "compile")
74+
75+
// The SBT project root
76+
volume("/tests")
77+
workDir("/tests/")
78+
entryPoint("sbt", "test")
79+
},
80+
imageNames in docker := Seq(ImageName("metacall-scala-tests"))
3381
)
82+
.enablePlugins(DockerPlugin)
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
addSbtPlugin("se.marcuslonnberg" % "sbt-docker" % "1.8.2")
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
// DO NOT EDIT! This file is auto-generated.
2+
// This file enables sbt-bloop to create bloop config files.
3+
4+
addSbtPlugin("ch.epfl.scala" % "sbt-bloop" % "1.4.6-21-464e4ec4")

0 commit comments

Comments
 (0)