Skip to content

Commit 0c87244

Browse files
committed
Collect error comments
Prefer a regex for collecting magic error comments. Allow arbitrary space after line comment but warn that no space `//error` disables that error, which is useful for testing and development.
1 parent 07d809f commit 0c87244

File tree

1 file changed

+16
-27
lines changed

1 file changed

+16
-27
lines changed

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

Lines changed: 16 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -785,43 +785,32 @@ trait ParallelTesting extends RunnerOrchestration { self =>
785785
//
786786
// We collect these in a map `"file:row" -> numberOfErrors`, for
787787
// nopos errors we save them in `"file" -> numberOfNoPosErrors`
788-
def getErrorMapAndExpectedCount(files: Seq[JFile]): (HashMap[String, Integer], Int) = {
788+
def getErrorMapAndExpectedCount(files: Seq[JFile]): (HashMap[String, Integer], Int) =
789+
val comment = raw"//( *)(nopos-|anypos-)?error".r
789790
val errorMap = new HashMap[String, Integer]()
790791
var expectedErrors = 0
792+
def bump(key: String): Unit =
793+
errorMap.get(key) match
794+
case null => errorMap.put(key, 1)
795+
case n => errorMap.put(key, n+1)
796+
expectedErrors += 1
791797
files.filter(isSourceFile).foreach { file =>
792798
Using(Source.fromFile(file, StandardCharsets.UTF_8.name)) { source =>
793799
source.getLines.zipWithIndex.foreach { case (line, lineNbr) =>
794-
val errors = line.toSeq.sliding("// error".length).count(_.unwrap == "// error")
795-
if (errors > 0)
796-
errorMap.put(s"${file.getPath}:${lineNbr+1}", errors)
797-
798-
val noposErrors = line.toSeq.sliding("// nopos-error".length).count(_.unwrap == "// nopos-error")
799-
if (noposErrors > 0) {
800-
val nopos = errorMap.get("nopos")
801-
val existing: Integer = if (nopos eq null) 0 else nopos
802-
errorMap.put("nopos", noposErrors + existing)
803-
}
804-
805-
val anyposErrors = line.toSeq.sliding("// anypos-error".length).count(_.unwrap == "// anypos-error")
806-
if (anyposErrors > 0) {
807-
val anypos = errorMap.get("anypos")
808-
val existing: Integer = if (anypos eq null) 0 else anypos
809-
errorMap.put("anypos", anyposErrors + existing)
810-
}
811-
812-
val possibleTypos = List("//error" -> "// error", "//nopos-error" -> "// nopos-error", "//anypos-error" -> "// anypos-error")
813-
for ((possibleTypo, expected) <- possibleTypos) {
814-
if (line.contains(possibleTypo))
815-
echo(s"Warning: Possible typo in error tag in file ${file.getCanonicalPath}:$lineNbr: found `$possibleTypo` but expected `$expected`")
800+
comment.findAllMatchIn(line).foreach { m =>
801+
m.group(2) match
802+
case prefix if m.group(1).isEmpty =>
803+
val what = Option(prefix).getOrElse("")
804+
echo(s"Warning: ${file.getCanonicalPath}:${lineNbr}: found `//${what}error` but expected `// ${what}error`, skipping comment")
805+
case "nopos-" => bump("nopos")
806+
case "anypos-" => bump("anypos")
807+
case _ => bump(s"${file.getPath}:${lineNbr+1}")
816808
}
817-
818-
expectedErrors += anyposErrors + noposErrors + errors
819809
}
820810
}.get
821811
}
822-
823812
(errorMap, expectedErrors)
824-
}
813+
end getErrorMapAndExpectedCount
825814

826815
// return unfulfilled expected errors and unexpected diagnostics
827816
def getMissingExpectedErrors(errorMap: HashMap[String, Integer], reporterErrors: Iterator[Diagnostic]): (List[String], List[String]) =

0 commit comments

Comments
 (0)