Skip to content

Commit 164744c

Browse files
committed
test added to BashScriptsTests to verify script.path property
1 parent 6011847 commit 164744c

File tree

2 files changed

+20
-6
lines changed

2 files changed

+20
-6
lines changed

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

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,10 @@ import org.junit.Test
1111
import vulpix.TestConfiguration
1212

1313

14-
/** Runs all tests contained in `compiler/test-resources/scripting/` */
14+
/** Verifies correct handling of command line arguments by `dist/bin/scala` and `dist/bin/scalac`.
15+
* +. arguments following a script path must be treated as script arguments
16+
* +. preserve script command line arguments.
17+
*/
1518
class BashScriptsTests:
1619
// classpath tests managed by scripting.ClasspathTests.scala
1720
def testFiles = scripts("/scripting").filter { ! _.getName.startsWith("classpath") }
@@ -45,9 +48,7 @@ class BashScriptsTests:
4548
val commandline = (Seq(scalacPath, "-script", showArgsScript) ++ testScriptArgs).mkString(" ")
4649
if bashPath.toFile.exists then
4750
var cmd = Array(bashExe, "-c", commandline)
48-
val output = for {
49-
line <- Process(cmd).lazyLines_!
50-
} yield line
51+
val output = Process(cmd).lazyLines_!
5152
var fail = false
5253
printf("\n")
5354
for (line, expect) <- output zip expectedOutput do
@@ -77,6 +78,20 @@ class BashScriptsTests:
7778
if fail then
7879
assert(output == expectedOutput)
7980

81+
/*
82+
* verify that scriptPath.sc sees a valid script.path property.
83+
*/
84+
@Test def verifyScriptPathProperty =
85+
val scriptFile = testFiles.find(_.getName == "scriptPath.sc").get
86+
val expected = s"/${scriptFile.getName}"
87+
printf("===> verify valid system property script.path is reported by script [%s]\n", scriptFile.getName)
88+
var cmd = Array(bashExe, "-c", scriptFile.absPath)
89+
val output = Process(cmd).lazyLines_!
90+
output.foreach { printf("[%s]\n",_) }
91+
val valid = output.exists { _.endsWith(expected) }
92+
if valid then printf("# valid script.path reported by [%s]\n",scriptFile.getName)
93+
assert(valid, s"script ${scriptFile.absPath} did not report valid script.path value")
94+
8095
extension (str: String) def dropExtension =
8196
str.reverse.dropWhile(_ != '.').drop(1).reverse
8297

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,7 @@ class ClasspathTests:
5656
printf("bash is [%s]\n", bashExe)
5757

5858
if packBinScalaExists then
59-
val echoTest = "" // "SCALAC_ECHO_TEST=1"
60-
val bashCmdline = s"SCALA_OPTS= $echoTest ${scalaCopy.norm} -classpath '$wildcardEntry' $relpath"
59+
val bashCmdline = s"SCALA_OPTS= ${scalaCopy.norm} -classpath '$wildcardEntry' $relpath"
6160

6261
// ask [dist/bin/scalac] to echo generated command line so we can verify some things
6362
val cmd = Array(bashExe, "-c", bashCmdline)

0 commit comments

Comments
 (0)