@@ -631,7 +631,10 @@ trait ParallelTesting extends RunnerOrchestration { self =>
631
631
632
632
if (compilerCrashed) Some (s " Compiler crashed when compiling: ${testSource.title}" )
633
633
else if (actualErrors == 0 ) Some (s " \n No errors found when compiling neg test $testSource" )
634
- else if (expectedErrors != actualErrors) Some (s " \n Wrong number of errors encountered when compiling $testSource, expected: $expectedErrors, actual: $actualErrors" )
634
+ else if (expectedErrors != actualErrors) {
635
+ getWarnings(testSource.sourceFiles) foreach echo
636
+ Some (s " \n Wrong number of errors encountered when compiling $testSource, expected: $expectedErrors, actual: $actualErrors" )
637
+ }
635
638
else if (hasMissingAnnotations) Some (s " \n Errors found on incorrect row numbers when compiling $testSource" )
636
639
else if (! errorMap.isEmpty) Some (s " \n Expected error(s) have {<error position>=<unreported error>}: $errorMap" )
637
640
else None
@@ -672,6 +675,35 @@ trait ParallelTesting extends RunnerOrchestration { self =>
672
675
(errorMap, expectedErrors)
673
676
}
674
677
678
+ /**
679
+ * We want to warn the developer about some of the possible typos when trying to point "error" and "nopos-error"
680
+ * For example - A warning could be emitted if the developer mistakenly types in "//error" instead of "// error"
681
+ * or "//nopos-error" instead of "// nopos-error"
682
+ *
683
+ * @param files test files
684
+ * @return Sequence of warning messages
685
+ */
686
+ def getWarnings (files : Seq [JFile ]) : Seq [String ] = {
687
+
688
+ def hasTypo (line : String ) : Boolean = line.contains(" //error" ) || line.contains(" //nopos-error" )
689
+
690
+ def getWarning (line : String , fileName : String ): String = if (line.contains(" //error" )) {
691
+ s " Wrong : //error \n Correct : // error "
692
+ } else if (line.contains(" //nopos-error" )) {
693
+ s " Wrong : //nopos-error \n Correct : // nopos-error "
694
+ } else " "
695
+
696
+ val fileNamesAndLineNumber : Seq [(String , String , Int )] = for {
697
+ file <- files.filter(_.getName.endsWith(" .scala" ))
698
+ (line, lineNbr) <- Source .fromFile(file, " UTF-8" ).getLines().zipWithIndex.filter({ case (line, _) => hasTypo(line) })
699
+ } yield {
700
+ (file.getName, line, lineNbr)
701
+ }
702
+ fileNamesAndLineNumber.map({
703
+ case (fileName, line, lineNbr) => s " Possible typo in $fileName at line number $lineNbr \n " +
704
+ getWarning(line, fileName)})
705
+ }
706
+
675
707
def getMissingExpectedErrors (errorMap : HashMap [String , Integer ], reporterErrors : Iterator [MessageContainer ]) = ! reporterErrors.forall { error =>
676
708
val key = if (error.pos.exists) {
677
709
def toRelative (path : String ): String = // For some reason, absolute paths leak from the compiler itself...
0 commit comments