Skip to content

Commit 9dc41ff

Browse files
committed
test to verify SCALA_OPTS=@argsfile correctly adds to java.class.path
1 parent 164744c commit 9dc41ff

File tree

1 file changed

+28
-3
lines changed

1 file changed

+28
-3
lines changed

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

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import vulpix.TestConfiguration
1717
*/
1818
class BashScriptsTests:
1919
// classpath tests managed by scripting.ClasspathTests.scala
20-
def testFiles = scripts("/scripting").filter { ! _.getName.startsWith("classpath") }
20+
def testFiles = scripts("/scripting")
2121

2222
lazy val expectedOutput = List(
2323
"arg 0:[a]",
@@ -92,10 +92,35 @@ class BashScriptsTests:
9292
if valid then printf("# valid script.path reported by [%s]\n",scriptFile.getName)
9393
assert(valid, s"script ${scriptFile.absPath} did not report valid script.path value")
9494

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 =
96121
str.reverse.dropWhile(_ != '.').drop(1).reverse
97122

98-
extension(f: File) def absPath =
123+
extension(f: File) def absPath: String =
99124
f.getAbsolutePath.replace('\\', '/')
100125

101126
lazy val osname = Option(sys.props("os.name")).getOrElse("").toLowerCase

0 commit comments

Comments
 (0)