@@ -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,57 +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 " , " " )
815- else if hasMissingAnnotations then s " \n Warnings found on incorrect row numbers when compiling $testSource\n $showDiagnostics"
816- else if ! map.isEmpty then s " \n Expected warnings(s) have {<warning position>=<unreported warning>}: $map"
816+ else if hasMissingAnnotations then
817+ s """ |Warnings found on incorrect row numbers when compiling $testSource
818+ | ${showLines(" Unfulfilled expectations:" , unfulfilled)}
819+ | ${showLines(" Unexpected warnings:" , unexpected)}
820+ | $showDiagnostics
821+ | """ .stripMargin.trim.linesIterator.mkString(" \n " , " \n " , " " )
822+ else if ! expected.isEmpty then s " \n Expected warnings(s) have {<warning position>=<unreported warning>}: $expected"
817823 else null
818824 end maybeFailureMessage
819825
820826 def getWarnMapAndExpectedCount (files : Seq [JFile ]): (HashMap [String , Integer ], Int ) =
821- val comment = raw " //( *)(nopos-)?warn " .r
822- val map = new HashMap [String , Integer ]()
827+ val comment = raw " //(?: *)(nopos-)?warn " .r
828+ val map = HashMap [String , Integer ]()
823829 var count = 0
824830 def bump (key : String ): Unit =
825831 map.get(key) match
826832 case null => map.put(key, 1 )
827833 case n => map.put(key, n+ 1 )
828834 count += 1
829- files.filter(isSourceFile).foreach { file =>
830- Using (Source .fromFile(file, StandardCharsets .UTF_8 .name)) { source =>
831- source.getLines.zipWithIndex.foreach { case (line, lineNbr) =>
832- comment.findAllMatchIn(line).foreach { m =>
833- m.group(2 ) match
834- case " nopos-" =>
835- bump(" nopos" )
836- case _ => bump(s " ${file.getPath}: ${lineNbr+ 1 }" )
837- }
838- }
839- }.get
840- }
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
841843 (map, count)
842844
843- def getMissingExpectedWarnings (map : HashMap [String , Integer ], reporterWarnings : Iterator [Diagnostic ]): (List [String ], List [String ]) =
844- 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 ]
845848 def relativize (path : String ): String = path.split(JFile .separatorChar).dropWhile(_ != " tests" ).mkString(JFile .separator)
846849 def seenAt (key : String ): Boolean =
847- map .get(key) match
850+ expected .get(key) match
848851 case null => false
849- case 1 => map .remove(key) ; true
850- case n => map .put(key, n - 1 ) ; true
852+ case 1 => expected .remove(key); true
853+ case n => expected .put(key, n - 1 ); true
851854 def sawDiagnostic (d : Diagnostic ): Unit =
852855 val srcpos = d.pos.nonInlined
853856 if srcpos.exists then
854857 val key = s " ${relativize(srcpos.source.file.toString())}: ${srcpos.line + 1 }"
855858 if ! seenAt(key) then unexpected += key
856859 else
857- if ( ! seenAt(" nopos" )) unpositioned += relativize(srcpos.source.file.toString() )
860+ if ! seenAt(" nopos" ) then unexpected += relativize(srcpos.source.file.toString)
858861
859862 reporterWarnings.foreach(sawDiagnostic)
860863
861- (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)
862867 end getMissingExpectedWarnings
863868 end WarnTest
864869
@@ -995,8 +1000,8 @@ trait ParallelTesting extends RunnerOrchestration { self =>
9951000 def seenAt (key : String ): Boolean =
9961001 errorMap.get(key) match
9971002 case null => false
998- case 1 => errorMap.remove(key) ; true
999- case n => errorMap.put(key, n - 1 ) ; true
1003+ case 1 => errorMap.remove(key); true
1004+ case n => errorMap.put(key, n - 1 ); true
10001005 def sawDiagnostic (d : Diagnostic ): Unit =
10011006 d.pos.nonInlined match
10021007 case srcpos if srcpos.exists =>
0 commit comments