Skip to content

Commit d02fc05

Browse files
committed
added missing shift in new -classpath* case in dist/bin/scala; fixed various style errors
1 parent 721390d commit d02fc05

File tree

5 files changed

+57
-57
lines changed

5 files changed

+57
-57
lines changed

compiler/src/dotty/tools/scripting/Main.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ object Main:
1010
All arguments afterwards are script arguments.*/
1111
private def distinguishArgs(args: Array[String]): (Array[String], File, Array[String], Boolean, Boolean) =
1212
val (leftArgs, rest) = args.splitAt(args.indexOf("-script"))
13-
assert(rest.size >= 2,s"internal error: rest == Array(${rest.mkString(",")})")
13+
assert(rest.size >= 2, s"internal error: rest == Array(${rest.mkString(",")})")
1414

1515
val file = File(rest(1))
1616
val scriptArgs = rest.drop(2)
@@ -91,7 +91,7 @@ object Main:
9191
// convert to absolute path relative to cwd.
9292
def absPath: String = norm match
9393
case str if str.isAbsolute => norm
94-
case _ => Paths.get(userDir,norm).toString.norm
94+
case _ => Paths.get(userDir, norm).toString.norm
9595

9696
def toUrl: String = Paths.get(absPath).toUri.toURL.toString
9797

compiler/test-resources/scripting/classpathReport.sc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import java.nio.file.Paths
44

55
def main(args: Array[String]): Unit =
6-
val cwd = Paths.get(".").toAbsolutePath.toString.replace('\\','/').replaceAll("/$","")
7-
printf("cwd: %s\n",cwd)
8-
printf("classpath: %s\n",sys.props("java.class.path"))
6+
val cwd = Paths.get(".").toAbsolutePath.toString.replace('\\', '/').replaceAll("/$", "")
7+
printf("cwd: %s\n", cwd)
8+
printf("classpath: %s\n", sys.props("java.class.path"))
99

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

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class ClasspathTests:
1818
str.reverse.dropWhile(_ != '.').drop(1).reverse
1919

2020
extension(f: File) def absPath =
21-
f.getAbsolutePath.replace('\\','/')
21+
f.getAbsolutePath.replace('\\', '/')
2222

2323
// only interested in classpath test scripts
2424
def testFiles = scripts("/scripting").filter { _.getName.matches("classpath.*[.]sc") }
@@ -36,21 +36,21 @@ class ClasspathTests:
3636
*/
3737
@Test def scalacEchoTest =
3838
val relpath = testScript.toPath.relpath.norm
39-
printf("===> scalacEchoTest for script [%s]\n",relpath)
40-
printf("bash is [%s]\n",bashExe)
39+
printf("===> scalacEchoTest for script [%s]\n", relpath)
40+
printf("bash is [%s]\n", bashExe)
4141

4242
if packBinScalaExists then
4343
val echoTest = "SCALAC_ECHO_TEST=1"
4444
val bashCmdline = s"SCALA_OPTS= $echoTest dist/target/pack/bin/scala -classpath '$wildcardEntry' $relpath"
4545

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

49-
//cmd.foreach { printf("[%s]\n",_) }
49+
//cmd.foreach { printf("[%s]\n", _) }
5050

5151
val javaCommandLine = exec(cmd:_*).mkString(" ").split(" ").filter { _.trim.nonEmpty }
52-
printf("\n==================== isWin[%s], cygwin[%s], mingw[%s], msys[%s]\n",isWin,cygwin,mingw,msys)
53-
javaCommandLine.foreach { printf("java-command[%s]\n",_) }
52+
printf("\n==================== isWin[%s], cygwin[%s], mingw[%s], msys[%s]\n", isWin, cygwin, mingw, msys)
53+
javaCommandLine.foreach { printf("java-command[%s]\n", _) }
5454

5555
val output = scala.collection.mutable.Queue(javaCommandLine:_*)
5656
output.dequeueWhile( _ != "dotty.tools.scripting.Main")
@@ -63,54 +63,54 @@ class ClasspathTests:
6363

6464
// display command line starting with "dotty.tools.scripting.Main"
6565
output.foreach { line =>
66-
printf("%s\n",line)
66+
printf("%s\n", line)
6767
}
6868

6969
// expecting -classpath next
70-
assert(consumeNext.replaceAll("'","") == "-classpath")
70+
assert(consumeNext.replaceAll("'", "") == "-classpath")
7171

7272
// 2nd arg to scripting.Main is 'lib/*', with semicolon added if Windows jdk
7373

7474
// PR #10761: verify that [dist/bin/scala] -classpath processing adds $psep to wildcard if Windows
7575
val classpathValue = consumeNext
76-
printf("classpath value [%s]\n",classpathValue)
76+
printf("classpath value [%s]\n", classpathValue)
7777
assert( !winshell || classpathValue.contains(psep) )
7878

7979
// expecting -script next
80-
assert(consumeNext.replaceAll("'","") == "-script")
80+
assert(consumeNext.replaceAll("'", "") == "-script")
8181

8282
// PR #10761: verify that Windows jdk did not expand single wildcard classpath to multiple file paths
8383
if javaCommandLine.last != relpath then
84-
printf("last: %s\nrelp: %s\n",javaCommandLine.last,relpath)
85-
assert(javaCommandLine.last == relpath,s"unexpected output passed to scripting.Main")
84+
printf("last: %s\nrelp: %s\n", javaCommandLine.last, relpath)
85+
assert(javaCommandLine.last == relpath, s"unexpected output passed to scripting.Main")
8686

8787
/*
8888
* verify classpath reported by called script.
8989
*/
9090
@Test def hashbangClasspathVerifyTest =
9191
val relpath = testScript.toPath.relpath.norm
92-
printf("===> hashbangClasspathVerifyTest for script [%s]\n",relpath)
93-
printf("bash is [%s]\n",bashExe)
92+
printf("===> hashbangClasspathVerifyTest for script [%s]\n", relpath)
93+
printf("bash is [%s]\n", bashExe)
9494

9595
if false && packBinScalaExists then
9696
val bashCmdline = s"SCALA_OPTS= $relpath"
97-
val cmd = Array(bashExe,"-c",bashCmdline)
97+
val cmd = Array(bashExe, "-c", bashCmdline)
9898

99-
cmd.foreach { printf("[%s]\n",_) }
99+
cmd.foreach { printf("[%s]\n", _) }
100100

101101
// test script reports the classpath it sees
102102
val scriptOutput = exec(cmd:_*)
103-
val scriptCwd = findTaggedLine("cwd",scriptOutput)
104-
printf("script ran in directory [%s]\n",scriptCwd)
105-
val scriptCp = findTaggedLine("classpath",scriptOutput)
103+
val scriptCwd = findTaggedLine("cwd", scriptOutput)
104+
printf("script ran in directory [%s]\n", scriptCwd)
105+
val scriptCp = findTaggedLine("classpath", scriptOutput)
106106

107107
val hashbangClasspathJars = scriptCp.split(psep).map { _.getName }.sorted.distinct
108108
val packlibJars = listJars(s"$scriptCwd/dist/target/pack/lib").sorted.distinct
109109

110110
// verify that the classpath set in the hashbang line is effective
111111
if hashbangClasspathJars.size != packlibJars.size then
112-
printf("%d test script jars in classpath\n",hashbangClasspathJars.size)
113-
printf("%d jar files in dist/target/pack/lib\n",packlibJars.size)
112+
printf("%d test script jars in classpath\n", hashbangClasspathJars.size)
113+
printf("%d jar files in dist/target/pack/lib\n", packlibJars.size)
114114

115115
assert(hashbangClasspathJars.size == packlibJars.size)
116116

@@ -127,7 +127,7 @@ def listJars(dir: String) =
127127
Nil
128128

129129
import scala.jdk.CollectionConverters._
130-
lazy val env:Map[String,String] = System.getenv.asScala.toMap
130+
lazy val env:Map[String, String] = System.getenv.asScala.toMap
131131

132132
// script output expected as "<tag>: <value>"
133133
def findTaggedLine(tag: String, lines: Seq[String]): String =
@@ -161,7 +161,7 @@ def which(str:String) =
161161

162162
def bashExe = which("bash")
163163
def unameExe = which("uname")
164-
def path = envOrElse("PATH","").split(psep).toList
164+
def path = envOrElse("PATH", "").split(psep).toList
165165
def psep = sys.props("path.separator")
166166

167167
def cygwin = ostype == "cygwin"
@@ -174,10 +174,10 @@ def ostype = ostypeFull.toLowerCase.takeWhile{ cc => cc >= 'a' && cc <='z' || cc
174174

175175
extension(p:Path)
176176
def relpath: Path = cwd.relativize(p)
177-
def norm: String = p.toString.replace('\\','/')
177+
def norm: String = p.toString.replace('\\', '/')
178178

179179
extension(path: String)
180-
def getName: String = norm.replaceAll(".*/","")
180+
def getName: String = norm.replaceAll(".*/", "")
181181

182182
// Normalize path separator, convert relative path to absolute
183183
def norm: String =
@@ -187,12 +187,12 @@ extension(path: String)
187187
case s => s
188188
}
189189

190-
def parent: String = norm.replaceAll("/[^/]*$","")
190+
def parent: String = norm.replaceAll("/[^/]*$", "")
191191

192192
// convert to absolute path relative to cwd.
193193
def absPath: String = norm match
194194
case str if str.isAbsolute => norm
195-
case _ => Paths.get(userDir,norm).toString.norm
195+
case _ => Paths.get(userDir, norm).toString.norm
196196

197197
def isDir: Boolean = Files.isDirectory(Paths.get(path))
198198

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

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,17 @@ class ScriptingTests:
1616
str.reverse.dropWhile(_ != '.').drop(1).reverse
1717

1818
extension(f: File) def absPath =
19-
f.getAbsolutePath.replace('\\','/')
19+
f.getAbsolutePath.replace('\\', '/')
2020

2121
// classpath tests managed by scripting.ClasspathTests.scala
2222
def testFiles = scripts("/scripting").filter { ! _.getName.startsWith("classpath") }
2323

2424
def script2jar(scriptFile: File) =
2525
val jarName = s"${scriptFile.getName.dropExtension}.jar"
26-
File(scriptFile.getParent,jarName)
26+
File(scriptFile.getParent, jarName)
2727

2828
def showScriptUnderTest(scriptFile: File): Unit =
29-
printf("===> test script name [%s]\n",scriptFile.getName)
29+
printf("===> test script name [%s]\n", scriptFile.getName)
3030

3131
val argss: Map[String, Array[String]] = (
3232
for
@@ -42,11 +42,11 @@ class ScriptingTests:
4242
if scriptFile.getName.endsWith(extension)
4343
name = scriptFile.getName.dropExtension
4444
scriptArgs = argss.getOrElse(name, Array.empty[String])
45-
yield scriptFile -> scriptArgs).toList.sortBy { (file,args) => file.getName }
45+
yield scriptFile -> scriptArgs).toList.sortBy { (file, args) => file.getName }
4646

47-
def callExecutableJar(script: File,jar: File, scriptArgs: Array[String] = Array.empty[String]) = {
47+
def callExecutableJar(script: File, jar: File, scriptArgs: Array[String] = Array.empty[String]) = {
4848
import scala.sys.process._
49-
val cmd = Array("java",s"-Dscript.path=${script.getName}","-jar",jar.absPath)
49+
val cmd = Array("java", s"-Dscript.path=${script.getName}", "-jar", jar.absPath)
5050
++ scriptArgs
5151
Process(cmd).lazyLines_!.foreach { println }
5252
}
@@ -55,7 +55,7 @@ class ScriptingTests:
5555
* Call .scala scripts without -save option, verify no jar created
5656
*/
5757
@Test def scriptingDriverTests =
58-
for (scriptFile,scriptArgs) <- scalaFilesWithArgs(".scala") do
58+
for (scriptFile, scriptArgs) <- scalaFilesWithArgs(".scala") do
5959
showScriptUnderTest(scriptFile)
6060
val unexpectedJar = script2jar(scriptFile)
6161
unexpectedJar.delete
@@ -67,8 +67,8 @@ class ScriptingTests:
6767
),
6868
scriptFile = scriptFile,
6969
scriptArgs = scriptArgs
70-
).compileAndRun { (path:java.nio.file.Path,classpathEntries:Seq[Path], mainClass:String) =>
71-
printf("mainClass from ScriptingDriver: %s\n",mainClass)
70+
).compileAndRun { (path:java.nio.file.Path, classpathEntries:Seq[Path], mainClass:String) =>
71+
printf("mainClass from ScriptingDriver: %s\n", mainClass)
7272
true // call compiled script main method
7373
}
7474
assert(! unexpectedJar.exists, s"not expecting jar file: ${unexpectedJar.absPath}")
@@ -77,7 +77,7 @@ class ScriptingTests:
7777
* Call .sc scripts without -save option, verify no jar created
7878
*/
7979
@Test def scriptingMainTests =
80-
for (scriptFile,scriptArgs) <- scalaFilesWithArgs(".sc") do
80+
for (scriptFile, scriptArgs) <- scalaFilesWithArgs(".sc") do
8181
showScriptUnderTest(scriptFile)
8282
val unexpectedJar = script2jar(scriptFile)
8383
unexpectedJar.delete
@@ -95,7 +95,7 @@ class ScriptingTests:
9595
* Call .sc scripts with -save option, verify jar is created.
9696
*/
9797
@Test def scriptingJarTest =
98-
for (scriptFile,scriptArgs) <- scalaFilesWithArgs(".sc") do
98+
for (scriptFile, scriptArgs) <- scalaFilesWithArgs(".sc") do
9999
showScriptUnderTest(scriptFile)
100100
val expectedJar = script2jar(scriptFile)
101101
expectedJar.delete
@@ -109,7 +109,7 @@ class ScriptingTests:
109109

110110
Main.main(mainArgs)
111111

112-
printf("===> test script jar name [%s]\n",expectedJar.getName)
112+
printf("===> test script jar name [%s]\n", expectedJar.getName)
113113
assert(expectedJar.exists)
114114

115115
callExecutableJar(scriptFile, expectedJar, scriptArgs)
@@ -130,8 +130,8 @@ class ScriptingTests:
130130
compilerArgs = Array("-classpath", TestConfiguration.basicClasspath),
131131
scriptFile = scriptFile,
132132
scriptArgs = Array.empty[String]
133-
).compileAndRun { (path:java.nio.file.Path,classpathEntries:Seq[Path], mainClass:String) =>
134-
printf("success: no call to main method in mainClass: %s\n",mainClass)
133+
).compileAndRun { (path:java.nio.file.Path, classpathEntries:Seq[Path], mainClass:String) =>
134+
printf("success: no call to main method in mainClass: %s\n", mainClass)
135135
false // no call to compiled script main method
136136
}
137137
touchedFile.delete
@@ -143,14 +143,14 @@ class ScriptingTests:
143143
compilerArgs = Array("-classpath", TestConfiguration.basicClasspath),
144144
scriptFile = scriptFile,
145145
scriptArgs = Array.empty[String]
146-
).compileAndRun { (path:java.nio.file.Path,classpathEntries:Seq[Path], mainClass:String) =>
147-
printf("call main method in mainClass: %s\n",mainClass)
146+
).compileAndRun { (path:java.nio.file.Path, classpathEntries:Seq[Path], mainClass:String) =>
147+
printf("call main method in mainClass: %s\n", mainClass)
148148
true // call compiled script main method, create touchedFile
149149
}
150150

151151
if touchedFile.exists then
152-
printf("success: script created file %s\n",touchedFile)
153-
if touchedFile.exists then printf("success: created file %s\n",touchedFile)
152+
printf("success: script created file %s\n", touchedFile)
153+
if touchedFile.exists then printf("success: created file %s\n", touchedFile)
154154
assert( touchedFile.exists, s"expected to find file ${touchedFile}" )
155155

156156
/*
@@ -170,15 +170,15 @@ class ScriptingTests:
170170

171171
expectedJar.delete
172172
Main.main(mainArgs) // create executable jar
173-
printf("===> test script jar name [%s]\n",expectedJar.getName)
174-
assert(expectedJar.exists,s"unable to create executable jar [$expectedJar]")
173+
printf("===> test script jar name [%s]\n", expectedJar.getName)
174+
assert(expectedJar.exists, s"unable to create executable jar [$expectedJar]")
175175

176176
touchedFile.delete
177-
assert(!touchedFile.exists,s"unable to delete ${touchedFile}")
178-
printf("calling executable jar %s\n",expectedJar)
177+
assert(!touchedFile.exists, s"unable to delete ${touchedFile}")
178+
printf("calling executable jar %s\n", expectedJar)
179179
callExecutableJar(scriptFile, expectedJar)
180180
if touchedFile.exists then
181-
printf("success: executable jar created file %s\n",touchedFile)
181+
printf("success: executable jar created file %s\n", touchedFile)
182182
assert( touchedFile.exists, s"expected to find file ${touchedFile}" )
183183

184184
def touchFileScript = testFiles.find(_.getName == "touchFile.sc").get

dist/bin/scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,8 @@ while [[ $# -gt 0 ]]; do
7474
-cp*|-classpath*)
7575
# hashbang can combine args, e.g. "-classpath 'lib/*'"
7676
CLASS_PATH="${1#* *}${PSEP}"
77-
echo "CLASS_PATH[$CLASS_PATH]" 1>&2
7877
class_path_count+=1
78+
shift
7979
;;
8080
-with-compiler)
8181
with_compiler=true

0 commit comments

Comments
 (0)