From ec0b8edc604d7dd4efe928b1c4754469d93bf241 Mon Sep 17 00:00:00 2001 From: Tomasz Godzik Date: Fri, 8 Nov 2024 10:59:22 +0100 Subject: [PATCH] chore: Only resolve jvm when running test We could otherwise get spurious failures even if the test was not run. --- .../src/main/scala/tests/JavaHomeChangeTest.scala | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/tests/unit/src/main/scala/tests/JavaHomeChangeTest.scala b/tests/unit/src/main/scala/tests/JavaHomeChangeTest.scala index 53974295554..9a4183618f3 100644 --- a/tests/unit/src/main/scala/tests/JavaHomeChangeTest.scala +++ b/tests/unit/src/main/scala/tests/JavaHomeChangeTest.scala @@ -1,5 +1,7 @@ package tests +import scala.util.control.NonFatal + import scala.meta.internal.metals.Messages import coursierapi.JvmManager @@ -7,8 +9,15 @@ 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, @@ -23,6 +32,7 @@ trait JavaHomeChangeTest { self: BaseLspSuite => |""".stripMargin, )(implicit loc: Location): Unit = { test(name) { + val pathToJava11 = resolvePathToJava11() val java11Code = """|package a |object O