Skip to content

Commit 212706f

Browse files
committed
Sort unfulfilled expectations
1 parent 5ef12f7 commit 212706f

File tree

1 file changed

+32
-32
lines changed

1 file changed

+32
-32
lines changed

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

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -793,13 +793,14 @@ trait ParallelTesting extends RunnerOrchestration { self =>
793793
diffCheckfile(testSource, reporters, logger)
794794

795795
override def maybeFailureMessage(testSource: TestSource, reporters: Seq[TestReporter]): Option[String] =
796-
lazy val (map, expCount) = getWarnMapAndExpectedCount(testSource.sourceFiles.toIndexedSeq)
796+
lazy val (expected, expCount) = getWarnMapAndExpectedCount(testSource.sourceFiles.toIndexedSeq)
797797
lazy val obtCount = reporters.foldLeft(0)(_ + _.warningCount)
798-
lazy val (expected, unexpected) = getMissingExpectedWarnings(map, reporters.iterator.flatMap(_.diagnostics))
799-
lazy val diagnostics = reporters.flatMap(_.diagnostics.toSeq.sortBy(_.pos.line).map(e => s" at ${e.pos.line + 1}: ${e.message}"))
800-
def showLines(title: String, lines: Seq[String]) = if lines.isEmpty then "" else title + lines.mkString("\n", "\n", "")
801-
def hasMissingAnnotations = expected.nonEmpty || unexpected.nonEmpty
802-
def showDiagnostics = showLines("-> following the diagnostics:", diagnostics)
798+
lazy val (unfulfilled, unexpected) = getMissingExpectedWarnings(expected, diagnostics.iterator)
799+
lazy val diagnostics = reporters.flatMap(_.diagnostics.toSeq.sortBy(_.pos.line))
800+
lazy val messages = diagnostics.map(d => s" at ${d.pos.line + 1}: ${d.message}")
801+
def showLines(title: String, lines: Seq[String]) = if lines.isEmpty then "" else lines.mkString(s"$title\n", "\n", "")
802+
def hasMissingAnnotations = unfulfilled.nonEmpty || unexpected.nonEmpty
803+
def showDiagnostics = showLines("-> following the diagnostics:", messages)
803804
Option:
804805
if reporters.exists(_.errorCount > 0) then
805806
s"""Compilation failed for: ${testSource.title}
@@ -808,62 +809,61 @@ trait ParallelTesting extends RunnerOrchestration { self =>
808809
else if expCount != obtCount then
809810
s"""|Wrong number of warnings encountered when compiling $testSource
810811
|expected: $expCount, actual: $obtCount
811-
|${showLines("Unfulfilled expectations:", expected)}
812+
|${showLines("Unfulfilled expectations:", unfulfilled)}
812813
|${showLines("Unexpected warnings:", unexpected)}
813814
|$showDiagnostics
814815
|""".stripMargin.trim.linesIterator.mkString("\n", "\n", "")
815816
else if hasMissingAnnotations then
816817
s"""|Warnings found on incorrect row numbers when compiling $testSource
817-
|${showLines("Unfulfilled expectations:", expected)}
818+
|${showLines("Unfulfilled expectations:", unfulfilled)}
818819
|${showLines("Unexpected warnings:", unexpected)}
819820
|$showDiagnostics
820821
|""".stripMargin.trim.linesIterator.mkString("\n", "\n", "")
821-
else if !map.isEmpty then s"\nExpected warnings(s) have {<warning position>=<unreported warning>}: $map"
822+
else if !expected.isEmpty then s"\nExpected warnings(s) have {<warning position>=<unreported warning>}: $expected"
822823
else null
823824
end maybeFailureMessage
824825

825826
def getWarnMapAndExpectedCount(files: Seq[JFile]): (HashMap[String, Integer], Int) =
826-
val comment = raw"//( *)(nopos-)?warn".r
827-
val map = new HashMap[String, Integer]()
827+
val comment = raw"//(?: *)(nopos-)?warn".r
828+
val map = HashMap[String, Integer]()
828829
var count = 0
829830
def bump(key: String): Unit =
830831
map.get(key) match
831832
case null => map.put(key, 1)
832833
case n => map.put(key, n+1)
833834
count += 1
834-
files.filter(isSourceFile).foreach { file =>
835-
Using(Source.fromFile(file, StandardCharsets.UTF_8.name)) { source =>
836-
source.getLines.zipWithIndex.foreach { case (line, lineNbr) =>
837-
comment.findAllMatchIn(line).foreach { m =>
838-
m.group(2) match
839-
case "nopos-" =>
840-
bump("nopos")
841-
case _ => bump(s"${file.getPath}:${lineNbr+1}")
842-
}
843-
}
844-
}.get
845-
}
835+
for file <- files if isSourceFile(file) do
836+
Using.resource(Source.fromFile(file, StandardCharsets.UTF_8.name)) { source =>
837+
source.getLines.zipWithIndex.foreach: (line, lineNbr) =>
838+
comment.findAllMatchIn(line).foreach:
839+
case comment("nopos-") => bump("nopos")
840+
case _ => bump(s"${file.getPath}:${lineNbr+1}")
841+
}
842+
end for
846843
(map, count)
847844

848-
def getMissingExpectedWarnings(map: HashMap[String, Integer], reporterWarnings: Iterator[Diagnostic]): (List[String], List[String]) =
849-
val unexpected, unpositioned = ListBuffer.empty[String]
845+
// return unfulfilled expected warnings and unexpected diagnostics
846+
def getMissingExpectedWarnings(expected: HashMap[String, Integer], reporterWarnings: Iterator[Diagnostic]): (List[String], List[String]) =
847+
val unexpected = ListBuffer.empty[String]
850848
def relativize(path: String): String = path.split(JFile.separatorChar).dropWhile(_ != "tests").mkString(JFile.separator)
851849
def seenAt(key: String): Boolean =
852-
map.get(key) match
850+
expected.get(key) match
853851
case null => false
854-
case 1 => map.remove(key) ; true
855-
case n => map.put(key, n - 1) ; true
852+
case 1 => expected.remove(key); true
853+
case n => expected.put(key, n - 1); true
856854
def sawDiagnostic(d: Diagnostic): Unit =
857855
val srcpos = d.pos.nonInlined
858856
if srcpos.exists then
859857
val key = s"${relativize(srcpos.source.file.toString())}:${srcpos.line + 1}"
860858
if !seenAt(key) then unexpected += key
861859
else
862-
if(!seenAt("nopos")) unpositioned += relativize(srcpos.source.file.toString())
860+
if !seenAt("nopos") then unexpected += relativize(srcpos.source.file.toString)
863861

864862
reporterWarnings.foreach(sawDiagnostic)
865863

866-
(map.asScala.keys.toList, (unexpected ++ unpositioned).toList)
864+
val splitter = raw"(?:[^:]*):(\d+)".r
865+
val unfulfilled = expected.asScala.keys.toList.sortBy { case splitter(n) => n.toInt case _ => -1 }
866+
(unfulfilled, unexpected.toList)
867867
end getMissingExpectedWarnings
868868
end WarnTest
869869

@@ -1000,8 +1000,8 @@ trait ParallelTesting extends RunnerOrchestration { self =>
10001000
def seenAt(key: String): Boolean =
10011001
errorMap.get(key) match
10021002
case null => false
1003-
case 1 => errorMap.remove(key) ; true
1004-
case n => errorMap.put(key, n - 1) ; true
1003+
case 1 => errorMap.remove(key); true
1004+
case n => errorMap.put(key, n - 1); true
10051005
def sawDiagnostic(d: Diagnostic): Unit =
10061006
d.pos.nonInlined match
10071007
case srcpos if srcpos.exists =>

0 commit comments

Comments
 (0)