Skip to content

Commit dab4466

Browse files
committed
Test rig handles NL at EOF in neg
1 parent da68463 commit dab4466

File tree

4 files changed

+37
-24
lines changed

4 files changed

+37
-24
lines changed

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

Lines changed: 31 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@ import dotty.tools.vulpix.TestConfiguration.defaultOptions
4141
* using this, you should be running your JUnit tests **sequentially**, as the
4242
* test suite itself runs with a high level of concurrency.
4343
*/
44-
trait ParallelTesting extends RunnerOrchestration { self =>
45-
import ParallelTesting._
44+
trait ParallelTesting extends RunnerOrchestration:
45+
import ParallelTesting.*
4646

4747
/** If the running environment supports an interactive terminal, each `Test`
4848
* will be run with a progress bar and real time feedback
@@ -992,29 +992,33 @@ trait ParallelTesting extends RunnerOrchestration { self =>
992992
(errorMap, expectedErrors)
993993
end getErrorMapAndExpectedCount
994994

995-
// return unfulfilled expected errors and unexpected diagnostics
995+
// return unfulfilled expected errors and unexpected diagnostics.
996+
// the errorMap of expected errors is drained and returned as unfulfilled.
997+
// a diagnostic at EOF after NL is recorded at the preceding line,
998+
// to obviate `anypos-error` in that case.
996999
def getMissingExpectedErrors(errorMap: HashMap[String, Integer], reporterErrors: Iterator[Diagnostic]): (List[String], List[String]) =
9971000
val unexpected, unpositioned = ListBuffer.empty[String]
9981001
// For some reason, absolute paths leak from the compiler itself...
9991002
def relativize(path: String): String = path.split(JFile.separatorChar).dropWhile(_ != "tests").mkString(JFile.separator)
10001003
def seenAt(key: String): Boolean =
10011004
errorMap.get(key) match
1002-
case null => false
1003-
case 1 => errorMap.remove(key); true
1004-
case n => errorMap.put(key, n - 1); true
1005+
case null => false
1006+
case 1 => errorMap.remove(key); true
1007+
case n => errorMap.put(key, n - 1); true
10051008
def sawDiagnostic(d: Diagnostic): Unit =
1006-
d.pos.nonInlined match
1007-
case srcpos if srcpos.exists =>
1008-
val key = s"${relativize(srcpos.source.file.toString)}:${srcpos.line + 1}"
1009-
if !seenAt(key) then unexpected += key
1010-
case srcpos =>
1011-
if !seenAt("nopos") then unpositioned += relativize(srcpos.source.file.toString)
1009+
val srcpos = d.pos.nonInlined.adjustedAtEOF
1010+
val relatively = relativize(srcpos.source.file.toString)
1011+
if srcpos.exists then
1012+
val key = s"${relatively}:${srcpos.line + 1}"
1013+
if !seenAt(key) then unexpected += key
1014+
else
1015+
if !seenAt("nopos") then unpositioned += relatively
10121016

10131017
reporterErrors.foreach(sawDiagnostic)
10141018

1015-
errorMap.get("anypos") match
1016-
case n if n == unexpected.size => errorMap.remove("anypos") ; unexpected.clear()
1017-
case _ =>
1019+
if errorMap.get("anypos") == unexpected.size then
1020+
errorMap.remove("anypos")
1021+
unexpected.clear()
10181022

10191023
(errorMap.asScala.keys.toList, (unexpected ++ unpositioned).toList)
10201024
end getMissingExpectedErrors
@@ -1834,9 +1838,8 @@ trait ParallelTesting extends RunnerOrchestration { self =>
18341838
def isUserDebugging: Boolean =
18351839
val mxBean = ManagementFactory.getRuntimeMXBean
18361840
mxBean.getInputArguments.asScala.exists(_.contains("jdwp"))
1837-
}
18381841

1839-
object ParallelTesting {
1842+
object ParallelTesting:
18401843

18411844
def defaultOutputDir: String = "out"+JFile.separator
18421845

@@ -1851,4 +1854,14 @@ object ParallelTesting {
18511854
def isBestEffortTastyFile(f: JFile): Boolean =
18521855
f.getName.endsWith(".betasty")
18531856

1854-
}
1857+
extension (pos: SourcePosition)
1858+
private def adjustedAtEOF: SourcePosition =
1859+
if pos.span.isSynthetic
1860+
&& pos.span.isZeroExtent
1861+
&& pos.span.exists
1862+
&& pos.span.start == pos.source.length
1863+
&& pos.source(pos.span.start - 1) == '\n'
1864+
then
1865+
pos.withSpan(pos.span.shift(-1))
1866+
else
1867+
pos

tests/neg/i23815.check

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
| ^
44
| ':' or '{' expected, but 'end of statement' found
55
| Nested package statements that are not at the beginning of the file require braces or ':' with an indented body.
6-
-- [E040] Syntax Error: tests/neg/i23815.scala:9:15 --------------------------------------------------------------------
7-
9 |// anypos-error
8-
| ^
9-
| '}' expected, but eof found
6+
-- [E040] Syntax Error: tests/neg/i23815.scala:9:8 ---------------------------------------------------------------------
7+
9 |// error
8+
| ^
9+
| '}' expected, but eof found

tests/neg/i23815.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@ trait T1
66

77
package t2 // error
88
trait T2
9-
// anypos-error
9+
// error

tests/neg/parser-stability-11.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@ case class x0 // error // error
33
}
44
package x0 // error
55
class x0 // error
6-
// anypos-error
6+
// error

0 commit comments

Comments
 (0)