Skip to content

Commit fb58f46

Browse files
smarterfelixmulder
authored andcommitted
partest: put more stuff on javac classpath
Some java tests require the scala-library to be present on the classpath, this fixes tests/pos/java-interop/{t1186, t1235, t1254, t1642}. Also correctly redirect the output of javac so that it will be displayed by partest --verbose
1 parent 59569f7 commit fb58f46

File tree

1 file changed

+56
-0
lines changed

1 file changed

+56
-0
lines changed

test/dotty/partest/DPConsoleRunner.scala

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,62 @@ class DPTestRunner(testFile: File, suiteRunner: DPSuiteRunner) extends nest.Runn
134134
// override to provide DottyCompiler
135135
override def newCompiler = new dotty.partest.DPDirectCompiler(this)
136136

137+
// Adapted from nest.Runner#javac because:
138+
// - Our classpath handling is different and we need to pass extraClassPath
139+
// to java to get the scala-library which is required for some java tests
140+
// - The compiler output should be redirected to cLogFile, like the output of
141+
// dotty itself
142+
override def javac(files: List[File]): TestState = {
143+
import fileManager._
144+
import suiteRunner._
145+
import FileManager.joinPaths
146+
// compile using command-line javac compiler
147+
val args = Seq(
148+
javacCmdPath,
149+
"-d",
150+
outDir.getAbsolutePath,
151+
"-classpath",
152+
joinPaths(outDir :: extraClasspath ++ testClassPath)
153+
) ++ files.map(_.getAbsolutePath)
154+
155+
pushTranscript(args mkString " ")
156+
157+
val captured = StreamCapture(runCommand(args, cLogFile))
158+
if (captured.result) genPass() else {
159+
cLogFile appendAll captured.stderr
160+
cLogFile appendAll captured.stdout
161+
genFail("java compilation failed")
162+
}
163+
}
164+
165+
// FIXME: This is copy-pasted from nest.Runner where it is private
166+
// Remove this once https://github.com/scala/scala-partest/pull/61 is merged
167+
/** Runs command redirecting standard out and
168+
* error out to output file.
169+
*/
170+
def runCommand(args: Seq[String], outFile: File): Boolean = {
171+
import scala.sys.process.{ Process, ProcessLogger }
172+
//(Process(args) #> outFile !) == 0 or (Process(args) ! pl) == 0
173+
val pl = ProcessLogger(outFile)
174+
val nonzero = 17 // rounding down from 17.3
175+
def run: Int = {
176+
val p = Process(args) run pl
177+
try p.exitValue
178+
catch {
179+
case e: InterruptedException =>
180+
NestUI verbose s"Interrupted waiting for command to finish (${args mkString " "})"
181+
p.destroy
182+
nonzero
183+
case t: Throwable =>
184+
NestUI verbose s"Exception waiting for command to finish: $t (${args mkString " "})"
185+
p.destroy
186+
throw t
187+
}
188+
finally pl.close()
189+
}
190+
(pl buffer run) == 0
191+
}
192+
137193
// override to provide default dotty flags from file in directory
138194
override def flagsForCompilation(sources: List[File]): List[String] = {
139195
val specificFlags = super.flagsForCompilation(sources)

0 commit comments

Comments
 (0)