@@ -26,29 +26,35 @@ class ClasspathTests:
26
26
/*
27
27
* Call test scripts
28
28
*/
29
- @ Test def scriptingJarTest =
29
+ @ Test def scalacEchoTest =
30
30
for scriptFile <- testFiles do
31
31
val relpath = scriptFile.toPath.relpath.norm
32
32
printf(" ===> test script name [%s]\n " ,relpath)
33
33
printf(" %s\n " ,relpath)
34
- val bashExe = which(" bash" )
35
34
printf(" bash is [%s]\n " ,bashExe)
36
35
36
+ val echoTest = " SCALAC_ECHO_TEST=1"
37
+ val bashCmdline = s " SCALA_OPTS= $echoTest dist/target/pack/bin/scala -classpath 'lib/*' $relpath"
38
+
37
39
// 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
+
40
44
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" )
43
49
44
- def consumeNext = args .dequeue()
50
+ def consumeNext = if output.isEmpty then " " else output .dequeue()
45
51
46
52
// assert that we found "dotty.tools.scripting.Main"
47
53
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))
49
55
50
56
// display command line starting with "dotty.tools.scripting.Main"
51
- args .foreach { line =>
57
+ output .foreach { line =>
52
58
printf(" %s\n " ,line)
53
59
}
54
60
@@ -59,15 +65,17 @@ class ClasspathTests:
59
65
60
66
// PR #10761: verify that [dist/bin/scala] -classpath processing adds $psep to wildcard if Windows
61
67
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) )
63
71
64
72
// expecting -script next
65
73
assert(consumeNext.replaceAll(" '" ," " ) == " -script" )
66
74
67
75
// PR #10761: verify that Windows jdk did not expand single wildcard classpath to multiple file paths
68
76
if javaCommandLine.last != relpath then
69
77
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 " )
71
79
72
80
73
81
lazy val cwd = Paths .get(" ." ).toAbsolutePath
@@ -100,9 +108,18 @@ def which(str:String) =
100
108
out
101
109
102
110
def bashExe = which(" bash" )
111
+ def unameExe = which(" uname" )
103
112
def path = envOrElse(" PATH" ," " ).split(psep).toList
104
113
def psep = sys.props(" path.separator" )
105
114
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
+
106
123
extension(p: Path )
107
124
def relpath : Path = cwd.relativize(p)
108
125
def norm : String = p.toString.replace('\\ ' ,'/' )
0 commit comments