Skip to content

Commit dab39eb

Browse files
committed
Fixes #7051 Detect typos in neg tests and give a warning
1 parent a80df17 commit dab39eb

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

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

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -658,20 +658,48 @@ trait ParallelTesting extends RunnerOrchestration { self =>
658658
if (errors > 0)
659659
errorMap.put(s"${file.getPath}:${lineNbr}", errors)
660660

661+
661662
val noposErrors = line.sliding("// nopos-error".length).count(_.mkString == "// nopos-error")
662663
if (noposErrors > 0) {
663664
val nopos = errorMap.get("nopos")
664665
val existing: Integer = if (nopos eq null) 0 else nopos
665666
errorMap.put("nopos", noposErrors + existing)
666667
}
667668

669+
maybeWarning(line).foreach(warning => echo(s"Possible typo in file ${file.getCanonicalPath} at line number $lineNbr \n$warning"))
670+
668671
expectedErrors += noposErrors + errors
669672
}
670673
}
671674

672675
(errorMap, expectedErrors)
673676
}
674677

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 line the line which will be checked for possible typos
684+
* @return Some(warningMessage) or None
685+
*/
686+
def maybeWarning(line : String) : Option[String] = {
687+
688+
def hasTypo(line : String) : Boolean = line.contains("//error") || line.contains("//nopos-error")
689+
690+
def getWarning(line: String): String = if (line.contains("//error")) {
691+
s"Wrong : //error\nCorrect : // error"
692+
} else if (line.contains("//nopos-error")) {
693+
s"Wrong : //nopos-error\nCorrect : // nopos-error"
694+
} else ""
695+
696+
if(hasTypo(line)){
697+
Some(getWarning(line))
698+
}else {
699+
None
700+
}
701+
}
702+
675703
def getMissingExpectedErrors(errorMap: HashMap[String, Integer], reporterErrors: Iterator[MessageContainer]) = !reporterErrors.forall { error =>
676704
val key = if (error.pos.exists) {
677705
def toRelative(path: String): String = // For some reason, absolute paths leak from the compiler itself...

0 commit comments

Comments
 (0)