Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 0 additions & 51 deletions compiler/test/dotty/tools/vulpix/ChildJVMMain.java

This file was deleted.

52 changes: 52 additions & 0 deletions compiler/test/dotty/tools/vulpix/ChildJVMMain.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package dotty.tools.vulpix

import java.io.{BufferedReader, File, InputStreamReader}
import java.net.{URL, URLClassLoader}
import java.util.ArrayList

object ChildJVMMain:
val MessageStart = "##THIS IS THE START FOR ME, HELLO##"
val MessageEnd = "##THIS IS THE END FOR ME, GOODBYE##"

def runMain(dir: String): Unit =
def meth =
val jcp = System.getProperty("java.class.path")
val sep = File.pathSeparator
System.setProperty("java.class.path", if jcp == null then dir else dir + sep + jcp)

val loader =
val cp = ArrayList[URL]()
val paths = dir.split(sep)
for path <- paths do
cp.add(File(path).toURI().toURL())
val urls = cp.toArray(Array.ofDim[URL](cp.size))
URLClassLoader(urls)

val cls = loader.loadClass("Test")
cls.getMethod("main", classOf[Array[String]])
end meth
val m =
try meth
catch t =>
// Include the failure stack trace to the test output
System.out.println(MessageStart)
t.printStackTrace()
throw t
System.out.println(MessageStart);
m.invoke(null, null)

def main(args: Array[String]): Unit =
inline def savingSystem[T](inline body: => T): T =
val savedIn = System.in
val savedOut = System.out
val savedErr = System.err
try body
finally
System.setIn(savedIn)
System.setOut(savedOut)
System.setErr(savedErr)
val stdin = BufferedReader(InputStreamReader(System.in))
while true do
savingSystem:
runMain(stdin.readLine())
println(MessageEnd)
28 changes: 13 additions & 15 deletions compiler/test/dotty/tools/vulpix/ParallelTesting.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1292,21 +1292,19 @@ trait ParallelTesting extends RunnerOrchestration:
this
}

/** Extract `Failure` set and render from `Test` */
private def reasonsForFailure(test: Test): String = {
val failureReport =
if test.failureCount == 0 then ""
else s"encountered ${test.failureCount} test failure(s):\n"

failureReport + test.failureReasons.collect {
case test.TimeoutFailure(title) =>
s" - test '$title' timed out"
case test.JavaCompilationFailure(msg) =>
s" - java compilation failed with:\n${ msg.linesIterator.map(" " + _).mkString("\n") }"
case test.Generic =>
" - generic failure (see test output)"
}.mkString("\n")
}
/** Extracts `Failure` set and renders from `Test`. */
private def reasonsForFailure(test: Test): String =
if test.failureCount == 0 then ""
else
test.failureReasons.collect {
case test.TimeoutFailure(title) =>
s" - test '$title' timed out"
case test.JavaCompilationFailure(msg) =>
val header = " - java compilation failed with:\n"
msg.linesIterator.map(" " + _).mkString(header, "\n", "")
case test.Generic =>
" - generic failure (see test output)"
}.mkString(s"encountered ${test.failureCount} test failure(s):\n", "\n", "")

/** Copies `file` to `dir` - taking into account if `file` is a directory,
* and if so copying recursively
Expand Down
41 changes: 18 additions & 23 deletions compiler/test/dotty/tools/vulpix/RunnerOrchestration.scala
Original file line number Diff line number Diff line change
Expand Up @@ -98,40 +98,35 @@ trait RunnerOrchestration {

def readLine(): String =
stdout.readLine() match
case s"Listening for transport dt_socket at address: $port" =>
throw new IOException(
s"Unexpected transport dt_socket message." +
" The port is going to be lost and no debugger will be able to connect."
)
case line => line
case s"Listening for transport dt_socket at address: $port" =>
throw IOException(
"Unexpected transport dt_socket message." +
" The port is going to be lost and no debugger will be able to connect."
)
case line => line

def printLine(line: String): Unit = stdin.println(line)

def getJdiPort(): Int =
stdout.readLine() match
case s"Listening for transport dt_socket at address: $port" => port.toInt
case line => throw new IOException(s"Failed getting JDI port of child JVM: got $line")
case s"Listening for transport dt_socket at address: $port" => port.toInt
case line => throw IOException(s"Failed getting JDI port of child JVM: got $line")

export p.{exitValue, isAlive, destroy}
def isAlive: Boolean = p.isAlive // export p.isAlive sans parens

export p.{exitValue, destroy}
end RunnerProcess

private class Runner(private var process: RunnerProcess):
/** Checks if `process` is still alive
*
* When `process.exitValue()` is called on an active process the caught
* exception is thrown. As such we can know if the subprocess exited or
* not.
*/
def isAlive: Boolean =
try { process.exitValue(); false }
catch case _: IllegalThreadStateException => true

/** Destroys the underlying process and kills IO streams */
/** Checks whether the underlying process is still alive. */
def isAlive: Boolean = process.isAlive

/** Destroys the underlying process and kills IO streams. */
def kill(): Unit =
if (process ne null) process.destroy()
process = null

/** Blocks less than `maxDuration` while running `Test.main` from `dir` */
/** Blocks less than `maxDuration` while running `Test.main` from `dir`. */
def runMain(classPath: String): Status =
assert(process ne null, "Runner was killed and then reused without setting a new process")
awaitStatusOrRespawn(startMain(classPath))
Expand Down Expand Up @@ -172,7 +167,7 @@ trait RunnerOrchestration {
sb.append(childOutput).append(System.lineSeparator)
childOutput = process.readLine()

if process.isAlive() && childOutput != null then Success(sb.toString)
if isAlive && childOutput != null then Success(sb.toString)
else Failure(sb.toString)
end startMain

Expand All @@ -198,7 +193,7 @@ trait RunnerOrchestration {
* scala library.
*/
private def createProcess(): RunnerProcess =
val url = classOf[ChildJVMMain].getProtectionDomain.getCodeSource.getLocation
val url = classOf[ChildJVMMain.type].getProtectionDomain.getCodeSource.getLocation
val cp = Paths.get(url.toURI).toString + JFile.pathSeparator + Properties.scalaLibrary
val javaBin = Paths.get(sys.props("java.home"), "bin", "java").toString
val args = Seq("-Dfile.encoding=UTF-8", "-Duser.language=en", "-Duser.country=US", "-Xmx1g", "-cp", cp) ++
Expand Down
6 changes: 0 additions & 6 deletions tests/disabled/i23245a/test_2.scala

This file was deleted.

File renamed without changes.
4 changes: 4 additions & 0 deletions tests/run/i23245a/test_2.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
object Test extends logadapter.Api.SelfLogging:
def main(args: Array[String]): Unit =
try summon[logadapter.LogAdapter].info("Hello")
catch t => t.printStackTrace(System.out)
13 changes: 13 additions & 0 deletions tests/run/i23245d/BaseTest_1.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
abstract class BaseTest {
def genName(): String = "outerAccess"
trait Fixture {
lazy val service: Service = new Service {
val a = genName()
def doIt(a: String): Int = 0
}
}
}

trait Service {
def doIt(a: String): Int
}
4 changes: 4 additions & 0 deletions tests/run/i23245d/Test_2.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
object Test extends BaseTest {
def main(args: Array[String]): Unit =
new Fixture { service.doIt("test") }
}
1 change: 1 addition & 0 deletions tests/run/2772.scala → tests/run/i2772.scala
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import java.io.OutputStream

// System.err is ostensibly final but cannot be inlined
object Test {
def main(args: Array[String]): Unit = {
val oldErr = System.err
Expand Down
6 changes: 1 addition & 5 deletions tests/vulpix-tests/unit/timeout.scala
Original file line number Diff line number Diff line change
@@ -1,5 +1 @@
object Test {
def main(args: Array[String]): Unit = {
Thread.sleep(10 * 1000)
}
}
@main def Test = Thread.sleep(1000 * 1000)
Loading