Skip to content

Commit

Permalink
chore: Only resolve jvm when running test
Browse files Browse the repository at this point in the history
We could otherwise get spurious failures even if the test was not run.
  • Loading branch information
tgodzik committed Nov 8, 2024
1 parent 9f6dd6c commit ec0b8ed
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion tests/unit/src/main/scala/tests/JavaHomeChangeTest.scala
Original file line number Diff line number Diff line change
@@ -1,14 +1,23 @@
package tests

import scala.util.control.NonFatal

import scala.meta.internal.metals.Messages

import coursierapi.JvmManager
import munit.Location
import munit.TestOptions

trait JavaHomeChangeTest { self: BaseLspSuite =>
val pathToJava11: String = JvmManager.create().get("11").toString()

def resolvePathToJava11(retries: Int = 3): String = try {
JvmManager.create().get("11").toString()
} catch {
case NonFatal(t) =>
scribe.error("Failed to resolve path to java 11", t)
if (retries > 0) { resolvePathToJava11(retries - 1) }
else throw t
}
def checkJavaHomeUpdate(
name: TestOptions,
makeLayout: String => String,
Expand All @@ -23,6 +32,7 @@ trait JavaHomeChangeTest { self: BaseLspSuite =>
|""".stripMargin,
)(implicit loc: Location): Unit = {
test(name) {
val pathToJava11 = resolvePathToJava11()
val java11Code =
"""|package a
|object O
Expand Down

0 comments on commit ec0b8ed

Please sign in to comment.