@@ -17,7 +17,7 @@ import vulpix.TestConfiguration
17
17
*/
18
18
class BashScriptsTests :
19
19
// classpath tests managed by scripting.ClasspathTests.scala
20
- def testFiles = scripts(" /scripting" ).filter { ! _.getName.startsWith( " classpath " ) }
20
+ def testFiles = scripts(" /scripting" )
21
21
22
22
lazy val expectedOutput = List (
23
23
" arg 0:[a]" ,
@@ -92,10 +92,35 @@ class BashScriptsTests:
92
92
if valid then printf(" # valid script.path reported by [%s]\n " ,scriptFile.getName)
93
93
assert(valid, s " script ${scriptFile.absPath} did not report valid script.path value " )
94
94
95
- extension (str : String ) def dropExtension =
95
+ /*
96
+ * verify SCALA_OPTS can specify an @argsfile when launching a scala script in `dist/bin/scala`.
97
+ */
98
+ @ Test def verifyScalaOpts =
99
+ val scriptFile = testFiles.find(_.getName == " classpathReport.sc" ).get
100
+ printf(" ===> verify valid system property script.path is reported by script [%s]\n " , scriptFile.getName)
101
+ val argsfile = createArgsFile() // avoid problems caused by drive letter
102
+ val envPairs = List ((" SCALA_OPTS" ,s " @ $argsfile" ))
103
+ var cmd = Array (bashExe, " -c" , scriptFile.absPath)
104
+ val output : Seq [String ] = Process (cmd,cwd,envPairs:_* ).lazyLines_!.toList
105
+ val expected = s " ${cwd.toString}"
106
+ val List (line1 : String , line2 : String ) = output.take(2 )
107
+ val valid = line2.dropWhile( _ != ' ' ).trim.startsWith(expected)
108
+ if valid then printf(s " \n ===> success: classpath begins with %s, as reported by [%s] \n " ,cwd, scriptFile.getName)
109
+ assert(valid, s " script ${scriptFile.absPath} did not report valid java.class.path first entry " )
110
+
111
+ lazy val cwd = Paths .get(dotty.tools.dotc.config.Properties .userDir).toFile
112
+
113
+ def createArgsFile (): String =
114
+ val utfCharset = java.nio.charset.StandardCharsets .UTF_8 .name
115
+ val text = s " -classpath ${cwd.absPath}"
116
+ val path = Files .createTempFile(" scriptingTest" ," .args" )
117
+ Files .write(path, text.getBytes(utfCharset))
118
+ path.toFile.getAbsolutePath.replace('\\ ' ,'/' )
119
+
120
+ extension (str : String ) def dropExtension : String =
96
121
str.reverse.dropWhile(_ != '.' ).drop(1 ).reverse
97
122
98
- extension(f : File ) def absPath =
123
+ extension(f : File ) def absPath : String =
99
124
f.getAbsolutePath.replace('\\ ' , '/' )
100
125
101
126
lazy val osname = Option (sys.props(" os.name" )).getOrElse(" " ).toLowerCase
0 commit comments