@@ -75,8 +75,8 @@ class CoursierScalaTests:
75
75
version()
76
76
77
77
def emptyArgsEqualsRepl () =
78
- val output = CoursierScalaTests .csScalaCmd( )
79
- assertTrue(output.mkString(" \n " ).contains(" Unable to create a terminal " )) // Scala attempted to create REPL so we can assume it is working
78
+ val output = CoursierScalaTests .csScalaCmdWithStdin( Seq .empty, Some ( " println( \" Hello World \" ) \n :quit " ) )
79
+ assertTrue(output.mkString(" \n " ).contains(" Hello World " ))
80
80
emptyArgsEqualsRepl()
81
81
82
82
def run () =
@@ -132,8 +132,8 @@ class CoursierScalaTests:
132
132
compileFilesToJarAndRun()
133
133
134
134
def replWithArgs () =
135
- val output = CoursierScalaTests .csScalaCmd( " -source" , " 3.0-migration" )
136
- assertTrue(output.mkString(" \n " ).contains(" Unable to create a terminal " )) // Scala attempted to create REPL so we can assume it is working
135
+ val output = CoursierScalaTests .csScalaCmdWithStdin( Seq ( " -source" , " 3.0-migration" ), Some ( " println( \" Hello World \" ) \n :quit " ) )
136
+ assertTrue(output.mkString(" \n " ).contains(" Hello World " ))
137
137
replWithArgs()
138
138
139
139
def argumentFile () =
@@ -148,25 +148,31 @@ class CoursierScalaTests:
148
148
149
149
object CoursierScalaTests :
150
150
151
- def execCmd (command : String , options : String * ): (Int , List [String ]) =
151
+ private def execCmd (command : String , options : Seq [ String ] = Seq .empty, stdin : Option [ String ] = None ): (Int , List [String ]) =
152
152
val cmd = (command :: options.toList).toSeq.mkString(" " )
153
153
val out = new ListBuffer [String ]
154
- val code = cmd.! (ProcessLogger (out += _, out += _))
154
+ val process = stdin match
155
+ case Some (input) => Process (cmd) #< new java.io.ByteArrayInputStream (input.getBytes)
156
+ case None => Process (cmd)
157
+ val code = process.! (ProcessLogger (out += _, out += _))
155
158
(code, out.toList)
156
159
157
160
def csScalaCmd (options : String * ): List [String ] =
158
- csCmd(" dotty.tools.MainGenericRunner" , options* )
161
+ csScalaCmdWithStdin(options, None )
162
+
163
+ def csScalaCmdWithStdin (options : Seq [String ], stdin : Option [String ]): List [String ] =
164
+ csCmd(" dotty.tools.MainGenericRunner" , options, stdin)
159
165
160
166
def csScalaCompilerCmd (options : String * ): List [String ] =
161
- csCmd(" dotty.tools.dotc.Main" , options* )
167
+ csCmd(" dotty.tools.dotc.Main" , options)
162
168
163
- private def csCmd (entry : String , options : String * ): List [String ] =
169
+ private def csCmd (entry : String , options : Seq [ String ], stdin : Option [ String ] = None ): List [String ] =
164
170
val (jOpts, args) = options.partition(_.startsWith(" -J" ))
165
171
val newOptions = args match
166
172
case Nil => args
167
173
case _ => " --" +: args
168
174
val newJOpts = jOpts.map(s => s " --java-opt ${s.stripPrefix(" -J" )}" ).mkString(" " )
169
- execCmd(" ./cs" , (s """ launch "org.scala-lang:scala3-compiler_3: ${sys.env(" DOTTY_BOOTSTRAPPED_VERSION" )}" $newJOpts --main-class " $entry" --property "scala.usejavacp=true" """ +: newOptions)* )._2
175
+ execCmd(" ./cs" , (s """ launch "org.scala-lang:scala3-compiler_3: ${sys.env(" DOTTY_BOOTSTRAPPED_VERSION" )}" $newJOpts --main-class " $entry" --property "scala.usejavacp=true" --property "scala.use_legacy_launcher=true" """ +: newOptions), stdin )._2
170
176
171
177
/** Get coursier script */
172
178
@ BeforeClass def setup (): Unit =
@@ -177,7 +183,7 @@ object CoursierScalaTests:
177
183
case other => fail(s " Unsupported OS for coursier launcher: $other" )
178
184
179
185
def runAndCheckCmd (cmd : String , options : String * ): Unit =
180
- val (code, out) = execCmd(cmd, options* )
186
+ val (code, out) = execCmd(cmd, options)
181
187
if code != 0 then
182
188
fail(s " Failed to run $cmd ${options.mkString(" " )}, exit code: $code, output: ${out.mkString(" \n " )}" )
183
189
0 commit comments