Skip to content

Commit 2d70b59

Browse files
authored
Create BashScriptsTests.scala
This sets `javaHome` at the head of the PATH for `bashCommands`.
1 parent 60a5e43 commit 2d70b59

File tree

1 file changed

+7
-8
lines changed

1 file changed

+7
-8
lines changed

compiler/test/dotty/tools/scripting/BashScriptsTests.scala

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,7 @@ class BashScriptsTests:
167167
def exists: Boolean = s.toPath.toFile.exists
168168
def name: String = s.toFile.getName
169169
def dropExtension: String = s.reverse.dropWhile(_ != '.').drop(1).reverse
170+
def parent(up: Int): String = s.norm.split("/").reverse.drop(up).reverse.mkString("/")
170171
}
171172

172173
extension(p: Path) {
@@ -201,22 +202,20 @@ class BashScriptsTests:
201202
if scalacPath.isFile then scalacPath.replaceAll("/bin/scalac", "")
202203
else envOrElse("SCALA_HOME", "").norm
203204

204-
lazy val javaHome = envOrElse("JAVA_HOME", "").norm
205+
lazy val javaHome = whichJava.parent(2)
205206

206207
lazy val testEnvPairs = List(
207208
("JAVA_HOME", javaHome),
208209
("SCALA_HOME", scalaHome),
209210
("PATH", adjustedPath),
210211
).filter { case (name, valu) => valu.nonEmpty }
211212

212-
lazy val whichBash: String =
213-
var whichBash = ""
214-
if osname.startsWith("windows") then
215-
whichBash = which("bash.exe")
216-
else
217-
whichBash = which("bash")
213+
lazy val whichBash: String = whichExe("bash")
214+
lazy val whichJava: String = whichExe("java")
218215

219-
whichBash
216+
def whichExe(basename: String): String =
217+
val exeName = if (osname.toLowerCase.startsWith("windows")) s"$basename.exe" else basename
218+
which(exeName)
220219

221220
def bashCommand(cmdstr: String, additionalEnvPairs: List[(String, String)] = Nil): (Boolean, Int, Seq[String], Seq[String]) = {
222221
var (stdout, stderr) = (List.empty[String], List.empty[String])

0 commit comments

Comments
 (0)