Skip to content

Commit a5465fc

Browse files
committed
Allow compilation of async's partest suite in Junit
This lets us use IntelliJ's code coverage analysis.
1 parent 8526bf2 commit a5465fc

File tree

1 file changed

+22
-9
lines changed

1 file changed

+22
-9
lines changed

test/junit/scala/tools/nsc/async/AnnotationDrivenAsync.scala

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -442,13 +442,19 @@ class AnnotationDrivenAsync {
442442
assertEquals(100, run(code))
443443
}
444444

445-
446-
447-
// Handy to debug the compiler
448-
@Test @Ignore
445+
// Handy to debug the compiler or to collect code coverage statistics in IntelliJ.
446+
@Test
447+
@Ignore
449448
def testManualRunPartestUnderJUnit(): Unit = {
450-
val code = new String(Files.readAllBytes(Paths.get("../async/run/concurrent_ArrayIndexOutOfBoundIssue.scala")))
451-
assertEquals(("a", "b"), run(code))
449+
import scala.collection.JavaConverters._
450+
for (path <- List(Paths.get("../async/run"), Paths.get("../async/neg"))) {
451+
for (file <- Files.list(path).iterator.asScala) {
452+
if (file.getFileName.toString.endsWith(".scala")) {
453+
val code = new String(Files.readAllBytes(file))
454+
run(code, compileOnly = true)
455+
}
456+
}
457+
}
452458
}
453459

454460
private def createTempDir(): File = {
@@ -458,7 +464,7 @@ class AnnotationDrivenAsync {
458464
f
459465
}
460466

461-
def run(code: String): Any = {
467+
def run(code: String, compileOnly: Boolean = false): Any = {
462468
val out = createTempDir()
463469
try {
464470
val reporter = new StoreReporter {
@@ -495,11 +501,18 @@ class AnnotationDrivenAsync {
495501
val run = new Run
496502
val source = newSourceFile(code)
497503
run.compileSources(source :: Nil)
498-
Assert.assertTrue(reporter.infos.mkString("\n"), !reporter.hasWarnings)
504+
if (compileOnly) return null
499505
Assert.assertTrue(reporter.infos.mkString("\n"), !reporter.hasErrors)
506+
Assert.assertTrue(reporter.infos.mkString("\n"), !reporter.hasWarnings)
500507
val loader = new URLClassLoader(Seq(new File(settings.outdir.value).toURI.toURL), global.getClass.getClassLoader)
501508
val cls = loader.loadClass("Test")
502-
cls.getMethod("test").invoke(null) match {
509+
val result = try {
510+
cls.getMethod("test").invoke(null)
511+
} catch {
512+
case _: NoSuchMethodException =>
513+
cls.getMethod("main", classOf[Array[String]]).invoke(null, null)
514+
}
515+
result match {
503516
case t: scala.concurrent.Future[_] =>
504517
scala.concurrent.Await.result(t, Duration.Inf)
505518
case cf: CustomFuture[_] =>

0 commit comments

Comments
 (0)