Skip to content

Commit af4bb48

Browse files
committed
Make run tests run even if there isn't a check file
1 parent 7d8303d commit af4bb48

File tree

1 file changed

+46
-38
lines changed

1 file changed

+46
-38
lines changed

compiler/test/dotty/tools/dotc/ParallelTesting.scala

Lines changed: 46 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -406,56 +406,63 @@ trait ParallelTesting {
406406

407407
private final class RunTest(testSources: List[TestSource], times: Int, threadLimit: Option[Int], suppressAllOutput: Boolean)
408408
extends Test(testSources, times, threadLimit, suppressAllOutput) {
409-
private def verifyOutput(checkFile: JFile, dir: JFile, testSource: TestSource, warnings: Int) = try {
409+
410+
private def runMain(dir: JFile, testSource: TestSource): Array[String] = {
411+
import java.io.ByteArrayOutputStream
412+
import java.net.{ URL, URLClassLoader }
413+
414+
val printStream = new ByteArrayOutputStream
415+
try {
410416
// Do classloading magic and running here:
411-
import java.net.{ URL, URLClassLoader }
412-
import java.io.ByteArrayOutputStream
413417
val ucl = new URLClassLoader(Array(dir.toURI.toURL))
414418
val cls = ucl.loadClass("Test")
415419
val meth = cls.getMethod("main", classOf[Array[String]])
416420

417-
val printStream = new ByteArrayOutputStream
418421
Console.withOut(printStream) {
419422
meth.invoke(null, Array("jvm")) // partest passes at least "jvm" as an arg
420423
}
424+
}
425+
catch {
426+
case ex: NoSuchMethodException =>
427+
echo(s"test in '$dir' did not contain method: ${ex.getMessage} ")
428+
failTestSource(testSource)
421429

422-
val outputLines = printStream.toString("utf-8").lines.toArray
423-
val checkLines = Source.fromFile(checkFile).getLines.toArray
424-
425-
def linesMatch =
426-
outputLines
427-
.zip(checkLines)
428-
.forall { case (x, y) => x == y }
429-
430-
if (outputLines.length != checkLines.length || !linesMatch) {
431-
// Print diff to files and summary:
432-
val diff = outputLines.zip(checkLines).map { case (act, exp) =>
433-
DiffUtil.mkColoredCodeDiff(exp, act, true)
434-
}.mkString("\n")
435-
val msg = s"\nOutput from run test '$checkFile' did not match expected, output:\n$diff\n"
436-
echo(msg)
437-
addFailureInstruction(msg)
438-
439-
// Print build instructions to file and summary:
440-
val buildInstr = testSource.buildInstructions(0, warnings)
441-
addFailureInstruction(buildInstr)
430+
case ex: ClassNotFoundException =>
431+
echo(s"test in '$dir' did not contain class: ${ex.getMessage} ")
432+
failTestSource(testSource)
442433

443-
// Fail target:
434+
case ex: InvocationTargetException =>
435+
echo(s"An exception ocurred when running main: ${ex.getCause} ")
444436
failTestSource(testSource)
445-
}
437+
}
438+
printStream.toString("utf-8").lines.toArray
446439
}
447-
catch {
448-
case ex: NoSuchMethodException =>
449-
echo(s"\ntest in '$dir' did not contain method: ${ex.getMessage}")
450-
fail()
451-
452-
case ex: ClassNotFoundException =>
453-
echo(s"\ntest in '$dir' did not contain class: ${ex.getMessage}")
454-
fail()
455-
456-
case ex: InvocationTargetException =>
457-
echo(s"\nInvocationTargetException ocurred. Test in '$dir' might be using args(X) where X > 0")
458-
fail()
440+
441+
private def verifyOutput(checkFile: JFile, dir: JFile, testSource: TestSource, warnings: Int) = {
442+
val outputLines = runMain(dir, testSource)
443+
val checkLines = Source.fromFile(checkFile).getLines.toArray
444+
445+
def linesMatch =
446+
outputLines
447+
.zip(checkLines)
448+
.forall { case (x, y) => x == y }
449+
450+
if (outputLines.length != checkLines.length || !linesMatch) {
451+
// Print diff to files and summary:
452+
val diff = outputLines.zip(checkLines).map { case (act, exp) =>
453+
DiffUtil.mkColoredCodeDiff(exp, act, true)
454+
}.mkString("\n")
455+
val msg = s"\nOutput from run test '$checkFile' did not match expected, output:\n$diff\n"
456+
echo(msg)
457+
addFailureInstruction(msg)
458+
459+
// Print build instructions to file and summary:
460+
val buildInstr = testSource.buildInstructions(0, warnings)
461+
addFailureInstruction(buildInstr)
462+
463+
// Fail target:
464+
failTestSource(testSource)
465+
}
459466
}
460467

461468
protected def compilationRunnable(testSource: TestSource): Runnable = new Runnable {
@@ -501,6 +508,7 @@ trait ParallelTesting {
501508
}
502509

503510
if (errorCount == 0 && hasCheckFile) verifier()
511+
else if (errorCount == 0) runMain(testSource.outDir, testSource)
504512
else if (errorCount > 0) {
505513
echo(s"\nCompilation failed for: '$testSource'")
506514
val buildInstr = testSource.buildInstructions(errorCount, warningCount)

0 commit comments

Comments
 (0)