Skip to content

Commit cb64423

Browse files
committed
replace SCALAC_ECHO_TEST scalac modification; test modified copy of scalac
1 parent 0dc35d8 commit cb64423

File tree

2 files changed

+35
-13
lines changed

2 files changed

+35
-13
lines changed

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

+34-11
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,14 @@ import org.junit.Test
1010
import vulpix.TestConfiguration
1111

1212
import scala.sys.process._
13+
import scala.jdk.CollectionConverters._
1314
import dotty.tools.dotc.config.Properties._
1415

1516
/** Runs all tests contained in `compiler/test-resources/scripting/` */
1617
class ClasspathTests:
17-
extension (str: String) def dropExtension =
18-
str.reverse.dropWhile(_ != '.').drop(1).reverse
19-
20-
extension(f: File) def absPath =
21-
f.getAbsolutePath.replace('\\', '/')
18+
val packBinDir = "dist/target/pack/bin"
19+
val scalaCopy = makeTestableScriptCopy("scala")
20+
val scalacCopy = makeTestableScriptCopy("scalac")
2221

2322
// only interested in classpath test scripts
2423
def testFiles = scripts("/scripting").filter { _.getName.matches("classpath.*[.]sc") }
@@ -27,9 +26,24 @@ class ClasspathTests:
2726
case None => sys.error(s"test script not found: ${testScriptName}")
2827
case Some(file) => file
2928

30-
def packBinScalaExists:Boolean =
31-
val scalaScriptPath = Paths.get("dist/target/pack/bin/scala")
32-
scalaScriptPath.toFile.exists
29+
def getScriptPath(scriptName: String): Path = Paths.get(s"$packBinDir/$scriptName")
30+
31+
def exists(scriptPath: Path): Boolean = Files.exists(scriptPath)
32+
def packBinScalaExists:Boolean = exists(Paths.get(s"$packBinDir/scala"))
33+
34+
// create edited copy of [dist/bin/scala] and [dist/bin/scalac] for scalacEchoTest
35+
def makeTestableScriptCopy(scriptName: String): Path =
36+
val scriptPath: Path = getScriptPath(scriptName)
37+
val scriptCopy: Path = getScriptPath(s"$scriptName-copy")
38+
if Files.exists(scriptPath) then
39+
val lines = Files.readAllLines(scriptPath).asScala.map {
40+
_.replaceAll("/scalac", "/scalac-copy").
41+
replaceFirst("^eval(.*JAVACMD.*)", "echo $1")
42+
}
43+
val bytes = (lines.mkString("\n")+"\n").getBytes
44+
Files.write(scriptCopy, bytes)
45+
46+
scriptCopy
3347

3448
/*
3549
* verify java command line generated by scalac.
@@ -40,8 +54,8 @@ class ClasspathTests:
4054
printf("bash is [%s]\n", bashExe)
4155

4256
if packBinScalaExists then
43-
val echoTest = "SCALAC_ECHO_TEST=1"
44-
val bashCmdline = s"SCALA_OPTS= $echoTest dist/target/pack/bin/scala -classpath '$wildcardEntry' $relpath"
57+
val echoTest = "" // "SCALAC_ECHO_TEST=1"
58+
val bashCmdline = s"SCALA_OPTS= $echoTest ${scalaCopy.norm} -classpath '$wildcardEntry' $relpath"
4559

4660
// ask [dist/bin/scalac] to echo generated command line so we can verify some things
4761
val cmd = Array(bashExe, "-c", bashCmdline)
@@ -58,7 +72,10 @@ class ClasspathTests:
5872
def consumeNext = if output.isEmpty then "" else output.dequeue()
5973

6074
// assert that we found "dotty.tools.scripting.Main"
61-
assert(consumeNext == "dotty.tools.scripting.Main")
75+
val str = consumeNext
76+
if str != "dotty.tools.scripting.Main" then
77+
78+
assert(str == "dotty.tools.scripting.Main", s"found [$str]")
6279
val mainArgs = output.copyToArray(Array.ofDim[String](output.length))
6380

6481
// display command line starting with "dotty.tools.scripting.Main"
@@ -203,3 +220,9 @@ extension(path: String)
203220
def isAbsolute = path.norm.startsWith("/") || (isWin && path.secondChar == ":")
204221
def secondChar: String = path.take(2).drop(1).mkString("")
205222

223+
extension (str: String) def dropExtension =
224+
str.reverse.dropWhile(_ != '.').drop(1).reverse
225+
226+
//extension(f: File) def absPath =
227+
//f.getAbsolutePath.replace('\\', '/')
228+

dist/bin/scalac

+1-2
Original file line numberDiff line numberDiff line change
@@ -120,8 +120,7 @@ if [ "$PROG_NAME" == "$ScriptingMain" ]; then
120120
scripting_string="-script $target_script ${scripting_args[@]}"
121121
fi
122122

123-
EVAL=eval ; [ -n "$SCALAC_ECHO_TEST" ] && EVAL=echo
124-
$EVAL "\"$JAVACMD\"" \
123+
eval "\"$JAVACMD\"" \
125124
${JAVA_OPTS:-$default_java_opts} \
126125
"${DEBUG-}" \
127126
"${java_args[@]}" \

0 commit comments

Comments
 (0)