@@ -7,6 +7,7 @@ import java.nio.file.{Path, Paths, Files}
77import scala .sys .process ._
88
99import org .junit .Test
10+ import org .junit .Assert .assertEquals
1011
1112import vulpix .TestConfiguration
1213
@@ -28,13 +29,13 @@ class BashScriptsTests:
2829 printf(" scalac path: [%s]\n " , scalacPath)
2930
3031 lazy val expectedOutput = List (
31- " arg 0:[a]" ,
32- " arg 1:[b]" ,
33- " arg 2:[c]" ,
34- " arg 3:[-repl]" ,
35- " arg 4:[-run]" ,
36- " arg 5:[-script]" ,
37- " arg 6:[-debug]" ,
32+ " arg 0:[a]" ,
33+ " arg 1:[b]" ,
34+ " arg 2:[c]" ,
35+ " arg 3:[-repl]" ,
36+ " arg 4:[-run]" ,
37+ " arg 5:[-script]" ,
38+ " arg 6:[-debug]" ,
3839 )
3940 lazy val testScriptArgs = Seq (
4041 " a" , " b" , " c" , " -repl" , " -run" , " -script" , " -debug"
@@ -56,6 +57,38 @@ class BashScriptsTests:
5657 if fail then
5758 assert(stdout == expectedOutput)
5859
60+ /* verify `dist/bin/scala` with -J setting */
61+ @ Test def verifyScJProperty =
62+ val commandline = Seq (scalaPath, " -J-Dkey=World" , testFiles.find(_.getName == " envtest.sc" ).get.absPath).mkString(" " )
63+ val (validTest, exitCode, stdout, stderr) = bashCommand(commandline)
64+ assertEquals(stdout.mkString(" /n" ), " Hello World" )
65+
66+ /* verify `dist/bin/scala` with -J setting */
67+ @ Test def verifyScalaJProperty =
68+ val commandline = Seq (scalaPath, " -J-Dkey=World3" , testFiles.find(_.getName == " envtest.scala" ).get.absPath).mkString(" " )
69+ val (validTest, exitCode, stdout, stderr) = bashCommand(commandline)
70+ assertEquals(stdout.mkString(" /n" ), " Hello World3" )
71+
72+ /* verify `dist/bin/scala` with -D setting */
73+ @ Test def verifyScDProperty =
74+ val commandline = Seq (scalaPath, " -Dkey=World3" , testFiles.find(_.getName == " envtest.sc" ).get.absPath).mkString(" " )
75+ val (validTest, exitCode, stdout, stderr) = bashCommand(commandline)
76+ assertEquals(stdout.mkString(" /n" ), " Hello World3" )
77+
78+ /* verify `dist/bin/scala` with -D setting */
79+ @ Test def verifyScalaDProperty =
80+ val commandline = Seq (scalaPath, " -Dkey=World4" , testFiles.find(_.getName == " envtest.scala" ).get.absPath).mkString(" " )
81+ val (validTest, exitCode, stdout, stderr) = bashCommand(commandline)
82+ assertEquals(stdout.mkString(" /n" ), " Hello World4" )
83+
84+ /* verify `dist/bin/scala` with -D setting */
85+ @ Test def saveAndRunWithDProperty =
86+ val commandline = Seq (scalaPath, " -save" , testFiles.find(_.getName == " envtest.scala" ).get.absPath).mkString(" " )
87+ val (_, _, _, _) = bashCommand(commandline)
88+ val commandline2 = Seq (scalaPath, " -Dkey=World5" , testFiles.find(_.getName == " envtest.jar" ).get.absPath).mkString(" " )
89+ val (validTest, exitCode, stdout, stderr) = bashCommand(commandline2)
90+ assertEquals(stdout.mkString(" /n" ), " Hello World5" )
91+
5992 /* verify `dist/bin/scala` non-interference with command line args following script name */
6093 @ Test def verifyScalaArgs =
6194 val commandline = (Seq (" SCALA_OPTS= " , scalaPath, showArgsScript) ++ testScriptArgs).mkString(" " )
@@ -73,7 +106,7 @@ class BashScriptsTests:
73106 assert(stdout == expectedOutput)
74107
75108 /*
76- * verify that scriptPath.sc sees a valid script.path property,
109+ * verify that scriptPath.sc sees a valid script.path property,
77110 * and that it's value is the path to "scriptPath.sc".
78111 */
79112 @ Test def verifyScriptPathProperty =
@@ -134,6 +167,7 @@ class BashScriptsTests:
134167 def exists : Boolean = s.toPath.toFile.exists
135168 def name : String = s.toFile.getName
136169 def dropExtension : String = s.reverse.dropWhile(_ != '.' ).drop(1 ).reverse
170+ def parent (up : Int ): String = s.norm.split(" /" ).reverse.drop(up).reverse.mkString(" /" )
137171 }
138172
139173 extension(p : Path ) {
@@ -168,22 +202,20 @@ class BashScriptsTests:
168202 if scalacPath.isFile then scalacPath.replaceAll(" /bin/scalac" , " " )
169203 else envOrElse(" SCALA_HOME" , " " ).norm
170204
171- lazy val javaHome = envOrElse( " JAVA_HOME " , " " ).norm
205+ lazy val javaHome = whichJava.parent( 2 )
172206
173207 lazy val testEnvPairs = List (
174208 (" JAVA_HOME" , javaHome),
175209 (" SCALA_HOME" , scalaHome),
176210 (" PATH" , adjustedPath),
177211 ).filter { case (name, valu) => valu.nonEmpty }
178212
179- lazy val whichBash : String =
180- var whichBash = " "
181- if osname.startsWith(" windows" ) then
182- whichBash = which(" bash.exe" )
183- else
184- whichBash = which(" bash" )
213+ lazy val whichBash : String = whichExe(" bash" )
214+ lazy val whichJava : String = whichExe(" java" )
185215
186- whichBash
216+ def whichExe (basename : String ): String =
217+ val exeName = if (osname.toLowerCase.startsWith(" windows" )) s " $basename.exe " else basename
218+ which(exeName)
187219
188220 def bashCommand (cmdstr : String , additionalEnvPairs : List [(String , String )] = Nil ): (Boolean , Int , Seq [String ], Seq [String ]) = {
189221 var (stdout, stderr) = (List .empty[String ], List .empty[String ])
@@ -192,7 +224,7 @@ class BashScriptsTests:
192224 val envPairs = testEnvPairs ++ additionalEnvPairs
193225 val proc = Process (cmd, None , envPairs * )
194226 val exitVal = proc ! ProcessLogger (
195- (out : String ) => stdout ::= out,
227+ (out : String ) => stdout ::= out,
196228 (err : String ) => stderr ::= err
197229 )
198230 val validTest = exitVal == 0 && ! stderr.exists(_.contains(" Permission denied" ))
0 commit comments