@@ -37,7 +37,7 @@ class CoursierScalaTests:
37
37
val testScriptArgs = Seq (" a" , " b" , " c" , " -repl" , " -run" , " -script" , " -debug" )
38
38
39
39
val args = scriptPath +: testScriptArgs
40
- val output = CoursierScalaTests .csCmd (args* )
40
+ val output = CoursierScalaTests .csScalaCmd (args* )
41
41
val expectedOutput = List (
42
42
" arg 0:[a]" ,
43
43
" arg 1:[b]" ,
@@ -55,49 +55,68 @@ class CoursierScalaTests:
55
55
def scriptPath () =
56
56
val scriptPath = scripts(" /scripting" ).find(_.getName == " scriptPath.sc" ).get.absPath
57
57
val args = scriptPath
58
- val output = CoursierScalaTests .csCmd (args)
58
+ val output = CoursierScalaTests .csScalaCmd (args)
59
59
assertTrue(output.mkString(" \n " ).startsWith(" script.path:" ))
60
60
assertTrue(output.mkString(" \n " ).endsWith(" scriptPath.sc" ))
61
61
scriptPath()
62
62
63
63
def version () =
64
- val output = CoursierScalaTests .csCmd (" -version" )
64
+ val output = CoursierScalaTests .csScalaCmd (" -version" )
65
65
assertTrue(output.mkString(" \n " ).contains(sys.env(" DOTTY_BOOTSTRAPPED_VERSION" )))
66
66
version()
67
67
68
68
def emptyArgsEqualsRepl () =
69
- val output = CoursierScalaTests .csCmd ()
69
+ val output = CoursierScalaTests .csScalaCmd ()
70
70
assertTrue(output.mkString(" \n " ).contains(" Unable to create a system terminal" )) // Scala attempted to create REPL so we can assume it is working
71
71
emptyArgsEqualsRepl()
72
72
73
73
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" )
75
75
assertEquals(output.mkString(" \n " ), " Hello" )
76
76
run()
77
77
78
78
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" )
80
80
assertEquals(output.mkString(" \n " ), " Hello" )
81
81
notOnlyOptionsEqualsRun()
82
82
83
83
def help () =
84
- val output = CoursierScalaTests .csCmd (" -help" )
84
+ val output = CoursierScalaTests .csScalaCmd (" -help" )
85
85
assertTrue(output.mkString(" \n " ).contains(" Usage: scala <options> <source files>" ))
86
86
help()
87
87
88
88
def jar () =
89
89
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)
91
91
assertEquals(output.mkString(" \n " ), " Hello" )
92
92
assertTrue(source.getParentFile.listFiles.find(_.getName == " myfile.jar" ).isDefined)
93
93
jar()
94
94
95
95
def runThatJar () =
96
96
val source = new File (getClass.getResource(" /run/myfile.jar" ).getPath)
97
- val output = CoursierScalaTests .csCmd (source.absPath)
97
+ val output = CoursierScalaTests .csScalaCmd (source.absPath)
98
98
assertEquals(output.mkString(" \n " ), " Hello" )
99
99
runThatJar()
100
100
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
+
101
120
object CoursierScalaTests :
102
121
103
122
def execCmd (command : String , options : String * ): List [String ] =
@@ -106,11 +125,17 @@ object CoursierScalaTests:
106
125
cmd.! (ProcessLogger (out += _, out += _))
107
126
out.toList
108
127
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 ] =
110
135
val newOptions = options match
111
136
case Nil => options
112
137
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)* )
114
139
115
140
/** Get coursier script */
116
141
@ BeforeClass def setup (): Unit =
0 commit comments