@@ -5,7 +5,7 @@ package scripting
5
5
import scala .language .unsafeNulls
6
6
7
7
import java .nio .file .Paths
8
- import org .junit .{Test , AfterClass }
8
+ import org .junit .{Test , Ignore , AfterClass }
9
9
import org .junit .Assert .assertEquals
10
10
import org .junit .Assume .assumeFalse
11
11
import org .junit .experimental .categories .Category
@@ -50,7 +50,9 @@ object BashScriptsTests:
50
50
val testScriptArgs = Seq (
51
51
" a" , " b" , " c" , " -repl" , " -run" , " -script" , " -debug"
52
52
)
53
- val showArgsScript = testFiles.find(_.getName == " showArgs.sc" ).get.absPath
53
+ val Seq (showArgsScript, showArgsScalaCli) = Seq (" showArgs.sc" , " showArgsNu.sc" ).map { name =>
54
+ testFiles.find(_.getName == name).get.absPath
55
+ }
54
56
55
57
def testFile (name : String ): String =
56
58
val file = testFiles.find(_.getName == name) match {
@@ -64,13 +66,13 @@ object BashScriptsTests:
64
66
}
65
67
file
66
68
67
- val Seq (envtestSc , envtestScala) = Seq (" envtest .sc" , " envtest.scala" ).map { testFile(_) }
69
+ val Seq (envtestNuSc , envtestScala) = Seq (" envtestNu .sc" , " envtest.scala" ).map { testFile(_) }
68
70
69
71
// create command line with given options, execute specified script, return stdout
70
72
def callScript (tag : String , script : String , keyPre : String ): String =
71
73
val keyArg = s " $keyPre= $tag"
72
74
printf(" pass tag [%s] via [%s] to script [%s]\n " , tag, keyArg, script)
73
- val cmd : String = Seq (" SCALA_OPTS= " , scalaPath, keyArg, script).mkString(" " )
75
+ val cmd : String = Seq (" SCALA_OPTS= " , scalaPath, " run " , keyArg, " --offline " , " --server=false " , script).mkString(" " )
74
76
printf(" cmd: [%s]\n " , cmd)
75
77
val (validTest, exitCode, stdout, stderr) = bashCommand(cmd)
76
78
stderr.filter { ! _.contains(" Inappropriate ioctl" ) }.foreach { System .err.printf(" stderr [%s]\n " , _) }
@@ -84,13 +86,15 @@ class BashScriptsTests:
84
86
// //////////////////////// begin tests //////////////////////
85
87
86
88
/* verify that `dist/bin/scala` correctly passes args to the jvm via -J-D for script envtest.sc */
89
+ @ Ignore // SCALA CLI does not support `-J` to pass java properties, only things like -Xmx5g
87
90
@ Test def verifyScJProperty =
88
91
assumeFalse(" Scripts do not yet support Scala 2 library TASTy" , Properties .usingScalaLibraryTasty)
89
92
val tag = " World1"
90
- val stdout = callScript(tag, envtestSc , s " -J-Dkey " )
93
+ val stdout = callScript(tag, envtestNuSc , s " -J-Dkey " )
91
94
assertEquals( s " Hello $tag" , stdout)
92
95
93
96
/* verify that `dist/bin/scala` correctly passes args to the jvm via -J-D for script envtest.scala */
97
+ @ Ignore // SCALA CLI does not support `-J` to pass java properties, only things like -Xmx5g
94
98
@ Test def verifyScalaJProperty =
95
99
assumeFalse(" Scripts do not yet support Scala 2 library TASTy" , Properties .usingScalaLibraryTasty)
96
100
val tag = " World2"
@@ -101,7 +105,7 @@ class BashScriptsTests:
101
105
@ Test def verifyScDProperty =
102
106
assumeFalse(" Scripts do not yet support Scala 2 library TASTy" , Properties .usingScalaLibraryTasty)
103
107
val tag = " World3"
104
- val stdout = callScript(tag, envtestSc , s " -Dkey " )
108
+ val stdout = callScript(tag, envtestNuSc , s " -Dkey " )
105
109
assertEquals(s " Hello $tag" , stdout)
106
110
107
111
/* verify that `dist/bin/scala` can set system properties via -D for envtest.scala */
@@ -114,7 +118,9 @@ class BashScriptsTests:
114
118
/* verify that `dist/bin/scala` can set system properties via -D when executing compiled script via -jar envtest.jar */
115
119
@ Test def saveAndRunWithDProperty =
116
120
assumeFalse(" Scripts do not yet support Scala 2 library TASTy" , Properties .usingScalaLibraryTasty)
117
- val commandline = Seq (" SCALA_OPTS= " , scalaPath.relpath, " -save" , envtestScala.relpath).mkString(" " )
121
+ val libOut = envtestScala.relpath.stripSuffix(" .scala" ) + " .jar"
122
+ val commandline = Seq (
123
+ " SCALA_OPTS= " , scalaPath.relpath, " --power" , " package" , envtestScala.relpath, " -o" , libOut, " --library" , " --offline" , " --server=false" ).mkString(" " )
118
124
val (_, _, _, _) = bashCommand(commandline) // compile jar, discard output
119
125
val testJar = testFile(" envtest.jar" ) // jar is created by the previous bashCommand()
120
126
if (testJar.isFile){
@@ -124,7 +130,8 @@ class BashScriptsTests:
124
130
}
125
131
126
132
val tag = " World5"
127
- val commandline2 = Seq (" SCALA_OPTS= " , scalaPath.relpath, s " -Dkey= $tag" , testJar.relpath)
133
+ val commandline2 = Seq (
134
+ " SCALA_OPTS= " , scalaPath.relpath, " run" , s " -Dkey= $tag" , " -classpath" , testJar.relpath, " --offline" , " --server=false" )
128
135
printf(" cmd[%s]\n " , commandline2.mkString(" " ))
129
136
val (validTest, exitCode, stdout, stderr) = bashCommand(commandline2.mkString(" " ))
130
137
assertEquals(s " Hello $tag" , stdout.mkString(" /n" ))
@@ -148,7 +155,11 @@ class BashScriptsTests:
148
155
/* verify `dist/bin/scala` non-interference with command line args following script name */
149
156
@ Test def verifyScalaArgs =
150
157
assumeFalse(" Scripts do not yet support Scala 2 library TASTy" , Properties .usingScalaLibraryTasty)
151
- val commandline = (Seq (" SCALA_OPTS= " , scalaPath, showArgsScript) ++ testScriptArgs).mkString(" " )
158
+ val commandline = (
159
+ Seq (" SCALA_OPTS= " , scalaPath, showArgsScalaCli)
160
+ ++ Seq (" --offline" , " --server=false" )
161
+ ++ (" --" +: testScriptArgs)
162
+ ).mkString(" " )
152
163
val (validTest, exitCode, stdout, stderr) = bashCommand(commandline)
153
164
if verifyValid(validTest) then
154
165
var fail = false
@@ -162,13 +173,13 @@ class BashScriptsTests:
162
173
assert(stdout == expectedOutput)
163
174
164
175
/*
165
- * verify that scriptPath .sc sees a valid script.path property,
166
- * and that it's value is the path to "scriptPath .sc".
176
+ * verify that scriptPathNu .sc sees a valid script.path property,
177
+ * and that it's value is the path to "scriptPathNu .sc".
167
178
*/
168
179
@ Category (Array (classOf [BootstrappedOnlyTests ]))
169
180
@ Test def verifyScriptPathProperty =
170
181
assumeFalse(" Scripts do not yet support Scala 2 library TASTy" , Properties .usingScalaLibraryTasty)
171
- val scriptFile = testFiles.find(_.getName == " scriptPath .sc" ).get
182
+ val scriptFile = testFiles.find(_.getName == " scriptPathNu .sc" ).get
172
183
val expected = s " ${scriptFile.getName}"
173
184
printf(" ===> verify valid system property script.path is reported by script [%s]\n " , scriptFile.getName)
174
185
printf(" calling scriptFile: %s\n " , scriptFile)
@@ -177,8 +188,8 @@ class BashScriptsTests:
177
188
stdout.foreach { printf(" stdout: [%s]\n " , _) }
178
189
stderr.foreach { printf(" stderr: [%s]\n " , _) }
179
190
val valid = stdout.exists { _.endsWith(expected) }
180
- if valid then printf(" # valid script.path reported by [%s]\n " , scriptFile.getName)
181
- assert(valid, s " script ${scriptFile.absPath} did not report valid script.path value " )
191
+ if valid then printf(" # valid scriptPath reported by [%s]\n " , scriptFile.getName)
192
+ assert(valid, s " script ${scriptFile.absPath} did not report valid scriptPath value " )
182
193
183
194
/*
184
195
* verify SCALA_OPTS can specify an @argsfile when launching a scala script in `dist/bin/scala`.
@@ -208,7 +219,7 @@ class BashScriptsTests:
208
219
*/
209
220
@ Test def sqlDateTest =
210
221
assumeFalse(" Scripts do not yet support Scala 2 library TASTy" , Properties .usingScalaLibraryTasty)
211
- val scriptBase = " sqlDateError "
222
+ val scriptBase = " sqlDateErrorNu "
212
223
val scriptFile = testFiles.find(_.getName == s " $scriptBase.sc " ).get
213
224
val testJar = testFile(s " $scriptBase.jar " ) // jar should not be created when scriptFile runs
214
225
val tj = Paths .get(testJar).toFile
@@ -236,7 +247,6 @@ class BashScriptsTests:
236
247
printf(" ===> verify -e <expression> is properly handled by `dist/bin/scala`\n " )
237
248
val expected = " 9"
238
249
val expression = s " println(3*3) "
239
- val cmd = s " bin/scala -e $expression"
240
250
val (validTest, exitCode, stdout, stderr) = bashCommand(s """ bin/scala -e ' $expression' """ )
241
251
val result = stdout.filter(_.nonEmpty).mkString(" " )
242
252
printf(" stdout: %s\n " , result)
0 commit comments