@@ -10,15 +10,14 @@ import org.junit.Test
10
10
import vulpix .TestConfiguration
11
11
12
12
import scala .sys .process ._
13
+ import scala .jdk .CollectionConverters ._
13
14
import dotty .tools .dotc .config .Properties ._
14
15
15
16
/** Runs all tests contained in `compiler/test-resources/scripting/` */
16
17
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" )
22
21
23
22
// only interested in classpath test scripts
24
23
def testFiles = scripts(" /scripting" ).filter { _.getName.matches(" classpath.*[.]sc" ) }
@@ -27,9 +26,24 @@ class ClasspathTests:
27
26
case None => sys.error(s " test script not found: ${testScriptName}" )
28
27
case Some (file) => file
29
28
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
33
47
34
48
/*
35
49
* verify java command line generated by scalac.
@@ -40,8 +54,8 @@ class ClasspathTests:
40
54
printf(" bash is [%s]\n " , bashExe)
41
55
42
56
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"
45
59
46
60
// ask [dist/bin/scalac] to echo generated command line so we can verify some things
47
61
val cmd = Array (bashExe, " -c" , bashCmdline)
@@ -58,7 +72,10 @@ class ClasspathTests:
58
72
def consumeNext = if output.isEmpty then " " else output.dequeue()
59
73
60
74
// 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] " )
62
79
val mainArgs = output.copyToArray(Array .ofDim[String ](output.length))
63
80
64
81
// display command line starting with "dotty.tools.scripting.Main"
@@ -203,3 +220,9 @@ extension(path: String)
203
220
def isAbsolute = path.norm.startsWith(" /" ) || (isWin && path.secondChar == " :" )
204
221
def secondChar : String = path.take(2 ).drop(1 ).mkString(" " )
205
222
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
+
0 commit comments