@@ -26,29 +26,35 @@ class ClasspathTests:
2626 /*
2727 * Call test scripts
2828 */
29- @ Test def scriptingJarTest =
29+ @ Test def scalacEchoTest =
3030 for scriptFile <- testFiles do
3131 val relpath = scriptFile.toPath.relpath.norm
3232 printf(" ===> test script name [%s]\n " ,relpath)
3333 printf(" %s\n " ,relpath)
34- val bashExe = which(" bash" )
3534 printf(" bash is [%s]\n " ,bashExe)
3635
36+ val echoTest = " SCALAC_ECHO_TEST=1"
37+ val bashCmdline = s " SCALA_OPTS= $echoTest dist/target/pack/bin/scala -classpath 'lib/*' $relpath"
38+
3739 // ask [dist/bin/scalac] to echo generated command line so we can verify some things
38- val cmd = Array (bashExe," -c" ,s " SCALAC_ECHO_TEST=1 dist/target/pack/bin/scala -classpath '*/lib' $relpath" )
39- cmd.foreach { printf(" cmd[%s]\n " ,_) }
40+ val cmd = Array (bashExe," -c" ,bashCmdline)
41+
42+ cmd.foreach { printf(" [%s]\n " ,_) }
43+
4044 val javaCommandLine = exec(cmd:_* ).mkString(" " ).split(" " ).filter { _.trim.nonEmpty }
41- val args = scala.collection.mutable.Queue (javaCommandLine:_* )
42- args.dequeueWhile( _ != " dotty.tools.scripting.Main" )
45+ javaCommandLine.foreach { printf(" scalac-java-command[%s]\n " ,_) }
46+
47+ val output = scala.collection.mutable.Queue (javaCommandLine:_* )
48+ output.dequeueWhile( _ != " dotty.tools.scripting.Main" )
4349
44- def consumeNext = args .dequeue()
50+ def consumeNext = if output.isEmpty then " " else output .dequeue()
4551
4652 // assert that we found "dotty.tools.scripting.Main"
4753 assert(consumeNext == " dotty.tools.scripting.Main" )
48- val mainArgs = args .copyToArray(Array .ofDim[String ](args .length))
54+ val mainArgs = output .copyToArray(Array .ofDim[String ](output .length))
4955
5056 // display command line starting with "dotty.tools.scripting.Main"
51- args .foreach { line =>
57+ output .foreach { line =>
5258 printf(" %s\n " ,line)
5359 }
5460
@@ -59,15 +65,17 @@ class ClasspathTests:
5965
6066 // PR #10761: verify that [dist/bin/scala] -classpath processing adds $psep to wildcard if Windows
6167 val classpathValue = consumeNext
62- assert( ! isWin || classpathValue.contains(psep) )
68+ printf(" classpath value [%s]\n " ,classpathValue)
69+ if isWin then printf(" cygwin[%s], mingw[%s], msys[%s]\n " ,cygwin,mingw,msys)
70+ assert( ! winshell || classpathValue.contains(psep) )
6371
6472 // expecting -script next
6573 assert(consumeNext.replaceAll(" '" ," " ) == " -script" )
6674
6775 // PR #10761: verify that Windows jdk did not expand single wildcard classpath to multiple file paths
6876 if javaCommandLine.last != relpath then
6977 printf(" last: %s\n relp: %s\n " ,javaCommandLine.last,relpath)
70- assert(javaCommandLine.last == relpath,s " unexpected args passed to scripting.Main " )
78+ assert(javaCommandLine.last == relpath,s " unexpected output passed to scripting.Main " )
7179
7280
7381lazy val cwd = Paths .get(" ." ).toAbsolutePath
@@ -100,9 +108,18 @@ def which(str:String) =
100108 out
101109
102110def bashExe = which(" bash" )
111+ def unameExe = which(" uname" )
103112def path = envOrElse(" PATH" ," " ).split(psep).toList
104113def psep = sys.props(" path.separator" )
105114
115+ def cygwin = ostype == " cygwin"
116+ def mingw = ostype == " mingw"
117+ def msys = ostype == " msys"
118+ def winshell = cygwin || mingw || msys
119+
120+ def ostypeFull = if unameExe.nonEmpty then exec(unameExe).mkString else " "
121+ def ostype = ostypeFull.toLowerCase.takeWhile{ cc => cc >= 'a' && cc <= 'z' || cc >= 'A' && cc <= 'Z' }
122+
106123extension(p: Path )
107124 def relpath : Path = cwd.relativize(p)
108125 def norm : String = p.toString.replace('\\ ' ,'/' )
0 commit comments