@@ -7,6 +7,7 @@ import java.nio.file.{Path, Paths, Files}
7
7
import scala .sys .process ._
8
8
9
9
import org .junit .Test
10
+ import org .junit .Assert .assertEquals
10
11
11
12
import vulpix .TestConfiguration
12
13
@@ -28,13 +29,13 @@ class BashScriptsTests:
28
29
printf(" scalac path: [%s]\n " , scalacPath)
29
30
30
31
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]" ,
38
39
)
39
40
lazy val testScriptArgs = Seq (
40
41
" a" , " b" , " c" , " -repl" , " -run" , " -script" , " -debug"
@@ -56,6 +57,38 @@ class BashScriptsTests:
56
57
if fail then
57
58
assert(stdout == expectedOutput)
58
59
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
+
59
92
/* verify `dist/bin/scala` non-interference with command line args following script name */
60
93
@ Test def verifyScalaArgs =
61
94
val commandline = (Seq (" SCALA_OPTS= " , scalaPath, showArgsScript) ++ testScriptArgs).mkString(" " )
@@ -73,7 +106,7 @@ class BashScriptsTests:
73
106
assert(stdout == expectedOutput)
74
107
75
108
/*
76
- * verify that scriptPath.sc sees a valid script.path property,
109
+ * verify that scriptPath.sc sees a valid script.path property,
77
110
* and that it's value is the path to "scriptPath.sc".
78
111
*/
79
112
@ Test def verifyScriptPathProperty =
@@ -134,6 +167,7 @@ class BashScriptsTests:
134
167
def exists : Boolean = s.toPath.toFile.exists
135
168
def name : String = s.toFile.getName
136
169
def dropExtension : String = s.reverse.dropWhile(_ != '.' ).drop(1 ).reverse
170
+ def parent (up : Int ): String = s.norm.split(" /" ).reverse.drop(up).reverse.mkString(" /" )
137
171
}
138
172
139
173
extension(p : Path ) {
@@ -168,22 +202,20 @@ class BashScriptsTests:
168
202
if scalacPath.isFile then scalacPath.replaceAll(" /bin/scalac" , " " )
169
203
else envOrElse(" SCALA_HOME" , " " ).norm
170
204
171
- lazy val javaHome = envOrElse( " JAVA_HOME " , " " ).norm
205
+ lazy val javaHome = whichJava.parent( 2 )
172
206
173
207
lazy val testEnvPairs = List (
174
208
(" JAVA_HOME" , javaHome),
175
209
(" SCALA_HOME" , scalaHome),
176
210
(" PATH" , adjustedPath),
177
211
).filter { case (name, valu) => valu.nonEmpty }
178
212
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" )
185
215
186
- whichBash
216
+ def whichExe (basename : String ): String =
217
+ val exeName = if (osname.toLowerCase.startsWith(" windows" )) s " $basename.exe " else basename
218
+ which(exeName)
187
219
188
220
def bashCommand (cmdstr : String , additionalEnvPairs : List [(String , String )] = Nil ): (Boolean , Int , Seq [String ], Seq [String ]) = {
189
221
var (stdout, stderr) = (List .empty[String ], List .empty[String ])
@@ -192,7 +224,7 @@ class BashScriptsTests:
192
224
val envPairs = testEnvPairs ++ additionalEnvPairs
193
225
val proc = Process (cmd, None , envPairs * )
194
226
val exitVal = proc ! ProcessLogger (
195
- (out : String ) => stdout ::= out,
227
+ (out : String ) => stdout ::= out,
196
228
(err : String ) => stderr ::= err
197
229
)
198
230
val validTest = exitVal == 0 && ! stderr.exists(_.contains(" Permission denied" ))
0 commit comments