@@ -37,7 +37,7 @@ class CoursierScalaTests:
3737 val testScriptArgs = Seq (" a" , " b" , " c" , " -repl" , " -run" , " -script" , " -debug" )
3838
3939 val args = scriptPath +: testScriptArgs
40- val output = CoursierScalaTests .csCmd (args* )
40+ val output = CoursierScalaTests .csScalaCmd (args* )
4141 val expectedOutput = List (
4242 " arg 0:[a]" ,
4343 " arg 1:[b]" ,
@@ -55,49 +55,68 @@ class CoursierScalaTests:
5555 def scriptPath () =
5656 val scriptPath = scripts(" /scripting" ).find(_.getName == " scriptPath.sc" ).get.absPath
5757 val args = scriptPath
58- val output = CoursierScalaTests .csCmd (args)
58+ val output = CoursierScalaTests .csScalaCmd (args)
5959 assertTrue(output.mkString(" \n " ).startsWith(" script.path:" ))
6060 assertTrue(output.mkString(" \n " ).endsWith(" scriptPath.sc" ))
6161 scriptPath()
6262
6363 def version () =
64- val output = CoursierScalaTests .csCmd (" -version" )
64+ val output = CoursierScalaTests .csScalaCmd (" -version" )
6565 assertTrue(output.mkString(" \n " ).contains(sys.env(" DOTTY_BOOTSTRAPPED_VERSION" )))
6666 version()
6767
6868 def emptyArgsEqualsRepl () =
69- val output = CoursierScalaTests .csCmd ()
69+ val output = CoursierScalaTests .csScalaCmd ()
7070 assertTrue(output.mkString(" \n " ).contains(" Unable to create a system terminal" )) // Scala attempted to create REPL so we can assume it is working
7171 emptyArgsEqualsRepl()
7272
7373 def run () =
74- val output = CoursierScalaTests .csCmd (" -run" , " -classpath" , scripts(" /run" ).head.getParentFile.getParent, " run.myfile" )
74+ val output = CoursierScalaTests .csScalaCmd (" -run" , " -classpath" , scripts(" /run" ).head.getParentFile.getParent, " run.myfile" )
7575 assertEquals(output.mkString(" \n " ), " Hello" )
7676 run()
7777
7878 def notOnlyOptionsEqualsRun () =
79- val output = CoursierScalaTests .csCmd (" -classpath" , scripts(" /run" ).head.getParentFile.getParent, " run.myfile" )
79+ val output = CoursierScalaTests .csScalaCmd (" -classpath" , scripts(" /run" ).head.getParentFile.getParent, " run.myfile" )
8080 assertEquals(output.mkString(" \n " ), " Hello" )
8181 notOnlyOptionsEqualsRun()
8282
8383 def help () =
84- val output = CoursierScalaTests .csCmd (" -help" )
84+ val output = CoursierScalaTests .csScalaCmd (" -help" )
8585 assertTrue(output.mkString(" \n " ).contains(" Usage: scala <options> <source files>" ))
8686 help()
8787
8888 def jar () =
8989 val source = new File (getClass.getResource(" /run/myfile.scala" ).getPath)
90- val output = CoursierScalaTests .csCmd (" -save" , source.absPath)
90+ val output = CoursierScalaTests .csScalaCmd (" -save" , source.absPath)
9191 assertEquals(output.mkString(" \n " ), " Hello" )
9292 assertTrue(source.getParentFile.listFiles.find(_.getName == " myfile.jar" ).isDefined)
9393 jar()
9494
9595 def runThatJar () =
9696 val source = new File (getClass.getResource(" /run/myfile.jar" ).getPath)
97- val output = CoursierScalaTests .csCmd (source.absPath)
97+ val output = CoursierScalaTests .csScalaCmd (source.absPath)
9898 assertEquals(output.mkString(" \n " ), " Hello" )
9999 runThatJar()
100100
101+ def compileFilesToJarAndRun () =
102+ val source = new File (getClass.getResource(" /run/myfile.scala" ).getPath)
103+ val prefix = source.getParent
104+
105+ val o1source = Paths .get(prefix, " automain.jar" ).toAbsolutePath.toString
106+ val output1 = CoursierScalaTests .csScalaCompilerCmd(" -d" , o1source, source.absPath)
107+ assertEquals(output1.mkString(" \n " ), " " )
108+
109+ val o2source = Paths .get(prefix, " custommain.jar" ).toAbsolutePath.toString
110+ val output2 = CoursierScalaTests .csScalaCompilerCmd(" -d" , o2source, " -Xmain-class" , " run.myfile" , source.absPath)
111+ assertEquals(output2.mkString(" \n " ), " " )
112+
113+ val output3 = CoursierScalaTests .csScalaCmd(o1source)
114+ assertEquals(output3.mkString(" \n " ), " Hello" )
115+
116+ val output4 = CoursierScalaTests .csScalaCmd(o2source)
117+ assertEquals(output4.mkString(" \n " ), " Hello" )
118+ compileFilesToJarAndRun()
119+
101120object CoursierScalaTests :
102121
103122 def execCmd (command : String , options : String * ): List [String ] =
@@ -106,11 +125,17 @@ object CoursierScalaTests:
106125 cmd.! (ProcessLogger (out += _, out += _))
107126 out.toList
108127
109- def csCmd (options : String * ): List [String ] =
128+ def csScalaCmd (options : String * ): List [String ] =
129+ csCmd(" dotty.tools.MainGenericRunner" , options* )
130+
131+ def csScalaCompilerCmd (options : String * ): List [String ] =
132+ csCmd(" dotty.tools.dotc.Main" , options* )
133+
134+ private def csCmd (entry : String , options : String * ): List [String ] =
110135 val newOptions = options match
111136 case Nil => options
112137 case _ => " --" +: options
113- execCmd(" ./cs" , (s """ launch "org.scala-lang:scala3-compiler_3: ${sys.env(" DOTTY_BOOTSTRAPPED_VERSION" )}" --main-class "dotty.tools.MainGenericRunner " --property "scala.usejavacp=true" """ +: newOptions)* )
138+ execCmd(" ./cs" , (s """ launch "org.scala-lang:scala3-compiler_3: ${sys.env(" DOTTY_BOOTSTRAPPED_VERSION" )}" --main-class " $entry " --property "scala.usejavacp=true" """ +: newOptions)* )
114139
115140 /** Get coursier script */
116141 @ BeforeClass def setup (): Unit =
0 commit comments