Skip to content

Commit

Permalink
test javaHome gets properly passed to Bloop
Browse files Browse the repository at this point in the history
  • Loading branch information
kasiaMarek committed Jun 28, 2024
1 parent 958c57b commit c33a056
Showing 1 changed file with 51 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package scala.cli.integration

import com.eed3si9n.expecty.Expecty.expect
import os.Pipe

import scala.cli.integration.util.BloopUtil
import scala.concurrent.ExecutionContext
Expand Down Expand Up @@ -191,4 +192,54 @@ class BloopTests extends ScalaCliSuite {
runScalaCli("bloop", "exit", "--power").call(cwd = root)
}
}

for {
lang <- List("scala", "java")
useDirective <- List(true, false)
option <- List("java-home", "jvm")
}
test(s"compiles $lang file with correct jdk version for $option ${
if (useDirective) "use directive" else "option"
}") {
def isScala = lang == "scala"
val optionValue =
if (option == "java-home")
os.Path(os.proc(TestUtil.cs, "java-home", "--jvm", "zulu:8").call().out.trim()).toString()
else "8"
val directive =
if (useDirective) s"//> using ${option.replace("-h", "H")} $optionValue\n" else ""
val options = if (useDirective) Nil else List(s"--$option", optionValue)
val content =
if (isScala)
"""|package a
|import java.net.http.HttpClient
|
|trait Simple {
| def httpClient: HttpClient
|}
|""".stripMargin
else """|package a;
|
|import java.net.http.HttpClient;
|
|interface Simple {
| HttpClient httpClient();
|}
|""".stripMargin
val inputs = TestInputs(os.rel / s"Simple.$lang" -> s"$directive$content")

inputs.fromRoot { root =>
val res =
runScalaCli(("compile" :: "." :: options)*).call(root, check = false, stderr = Pipe)
assert(res.exitCode == 1)

val compilationError = res.err.text()
val message =
if (isScala) "value http is not a member of java.net"
else "error: package java.net.http does not exist"

assert(compilationError.contains("Compilation failed"))
assert(compilationError.contains(message))
}
}
}

0 comments on commit c33a056

Please sign in to comment.