Skip to content

Fix line and path separators in test #23534

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions compiler/src/dotty/tools/dotc/report.scala
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,6 @@ object report:
case Nil => pos
recur(pos.sourcePos, tpd.enclosingInlineds)

private object messageRendering extends MessageRendering

// Should only be called from Run#enrichErrorMessage.
def enrichErrorMessage(errorMessage: String)(using Context): String =
if ctx.settings.XnoEnrichErrorMessages.value then errorMessage
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import java.lang.System.{lineSeparator => EOL}

import core.Contexts.*
import core.Decorators.*
import io.AbstractFile
import printing.Highlighting.{Blue, Red, Yellow}
import printing.SyntaxHighlighting
import Diagnostic.*
Expand Down Expand Up @@ -158,9 +159,12 @@ trait MessageRendering {
.mkString(EOL)
}

// file.path or munge it to normalize for testing
protected def renderPath(file: AbstractFile): String = file.path

/** The source file path, line and column numbers from the given SourcePosition */
protected def posFileStr(pos: SourcePosition): String =
val path = pos.source.file.path
val path = renderPath(pos.source.file)
if pos.exists then s"$path:${pos.line + 1}:${pos.column}" else path

/** The separator between errors containing the source file and error type
Expand Down
36 changes: 24 additions & 12 deletions compiler/test/dotty/tools/dotc/reporting/TestReporter.scala
Original file line number Diff line number Diff line change
@@ -1,23 +1,25 @@
package dotty.tools
package dotty
package tools
package dotc
package reporting

import scala.language.unsafeNulls
import java.io.{BufferedReader, FileInputStream, FileOutputStream, FileReader, PrintStream, PrintWriter, StringReader, StringWriter, File as JFile}
import java.io.{File as JFile, *}
import java.nio.file.Files.readAllLines
import java.text.SimpleDateFormat
import java.util.Date
import core.Decorators.*

import scala.collection.mutable
import scala.jdk.CollectionConverters.*
import util.SourcePosition
import core.Contexts.*
import Diagnostic.*
import dotty.Properties
import core.Decorators.*
import interfaces.Diagnostic.{ERROR, WARNING}
import io.AbstractFile
import util.SourcePosition
import Diagnostic.*

import scala.io.Codec
import scala.collection.mutable
import scala.compiletime.uninitialized
import scala.io.Codec
import scala.jdk.CollectionConverters.*
import scala.language.unsafeNulls

class TestReporter protected (outWriter: PrintWriter, logLevel: Int)
extends Reporter with UniqueMessagePositions with HideNonSensicalMessages with MessageRendering {
Expand All @@ -30,13 +32,17 @@ extends Reporter with UniqueMessagePositions with HideNonSensicalMessages with M
final def messages: Iterator[String] = _messageBuf.iterator

protected final val _consoleBuf = new StringWriter
protected final val _consoleReporter = new ConsoleReporter(null, new PrintWriter(_consoleBuf))
protected final val _consoleReporter = new ConsoleReporter(null, new PrintWriter(_consoleBuf)):
override protected def renderPath(file: AbstractFile): String = TestReporter.renderPath(file)

final def consoleOutput: String = _consoleBuf.toString

private var _skip: Boolean = false
final def setSkip(): Unit = _skip = true
final def skipped: Boolean = _skip

override protected def renderPath(file: AbstractFile): String = TestReporter.renderPath(file)

protected final def inlineInfo(pos: SourcePosition)(using Context): String =
if (pos.exists) {
if (pos.outer.exists)
Expand Down Expand Up @@ -152,10 +158,16 @@ object TestReporter {
Properties.rerunFailed &&
failedTestsFile.exists() &&
failedTestsFile.isFile
)(java.nio.file.Files.readAllLines(failedTestsFile.toPath).asScala.toList)
)(readAllLines(failedTestsFile.toPath).asScala.toList)

def writeFailedTests(tests: List[String]): Unit =
initLog()
tests.foreach(failed => failedTestsWriter.println(failed))
failedTestsWriter.flush()

def renderPath(file: AbstractFile): String =
if JFile.separatorChar == '\\' then
file.path.replace('\\', '/')
else
file.path
}
4 changes: 2 additions & 2 deletions compiler/test/dotty/tools/vulpix/ParallelTesting.scala
Original file line number Diff line number Diff line change
Expand Up @@ -728,7 +728,7 @@ trait ParallelTesting extends RunnerOrchestration { self =>
testSource.checkFile.foreach(diffTest(testSource, _, reporterOutputLines(reporters), reporters, logger))

private def reporterOutputLines(reporters: Seq[TestReporter]): List[String] =
reporters.flatMap(_.consoleOutput.split("\n")).toList
reporters.flatMap(_.consoleOutput.linesIterator).toList

private[ParallelTesting] def executeTestSuite(): this.type = {
assert(testSourcesCompleted == 0, "not allowed to re-use a `CompileRun`")
Expand Down Expand Up @@ -1041,7 +1041,7 @@ trait ParallelTesting extends RunnerOrchestration { self =>
testReporter
}
if !failedBestEffortCompilation.isEmpty then
Some(failedBestEffortCompilation.flatMap(_.consoleOutput.split("\n")).mkString("\n"))
Some(failedBestEffortCompilation.flatMap(_.consoleOutput.linesIterator).mkString("\n"))
else
None
}
Expand Down
1 change: 0 additions & 1 deletion tests/neg-custom-args/captures/cc-this2.check
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

-- Error: tests/neg-custom-args/captures/cc-this2/D_2.scala:3:8 --------------------------------------------------------
3 | this: D^ => // error
| ^^
Expand Down
1 change: 0 additions & 1 deletion tests/neg-macros/annot-crash.check
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

-- Error: tests/neg-macros/annot-crash/Test_2.scala:1:0 ----------------------------------------------------------------
1 |@crash // error
|^^^^^^
Expand Down
1 change: 0 additions & 1 deletion tests/neg-macros/annot-empty-result.check
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

-- Error: tests/neg-macros/annot-empty-result/Test_2.scala:5:2 ---------------------------------------------------------
5 | @nilAnnot // error
| ^^^^^^^^^
Expand Down
1 change: 0 additions & 1 deletion tests/neg-macros/annot-error-annot.check
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

-- Error: tests/neg-macros/annot-error-annot/Test_2.scala:17:6 ---------------------------------------------------------
16 |@error
17 |class cGlobal // error
Expand Down
1 change: 0 additions & 1 deletion tests/neg-macros/annot-ill-abort.check
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

-- Error: tests/neg-macros/annot-ill-abort/Test_2.scala:1:0 ------------------------------------------------------------
1 |@crash // error
|^^^^^^
Expand Down
1 change: 0 additions & 1 deletion tests/neg-macros/annot-mod-class-add-top-method.check
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

-- Error: tests/neg-macros/annot-mod-class-add-top-method/Test_2.scala:1:0 ---------------------------------------------
1 |@addTopLevelMethod // error
|^^^^^^^^^^^^^^^^^^
Expand Down
1 change: 0 additions & 1 deletion tests/neg-macros/annot-mod-class-add-top-val.check
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

-- Error: tests/neg-macros/annot-mod-class-add-top-val/Test_2.scala:1:0 ------------------------------------------------
1 |@addTopLevelVal // error
|^^^^^^^^^^^^^^^
Expand Down
1 change: 0 additions & 1 deletion tests/neg-macros/annot-on-type.check
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

-- Error: tests/neg-macros/annot-on-type/Test_2.scala:6:7 --------------------------------------------------------------
5 | @voidAnnot
6 | type C // error
Expand Down
1 change: 0 additions & 1 deletion tests/neg-macros/annot-result-owner.check
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

-- Error: tests/neg-macros/annot-result-owner/Test_2.scala:1:0 ---------------------------------------------------------
1 |@insertVal // error
|^^^^^^^^^^
Expand Down
1 change: 0 additions & 1 deletion tests/neg-macros/beta-reduce-inline-result.check
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

-- [E007] Type Mismatch Error: tests/neg-macros/beta-reduce-inline-result/Test_2.scala:11:41 ---------------------------
11 | val x2: 4 = Macros.betaReduce(dummy1)(3) // error
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Expand Down
1 change: 0 additions & 1 deletion tests/neg-macros/delegate-match-1.check
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

-- Error: tests/neg-macros/delegate-match-1/Test_2.scala:6:2 -----------------------------------------------------------
6 | f // error
| ^
Expand Down
1 change: 0 additions & 1 deletion tests/neg-macros/delegate-match-2.check
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

-- Error: tests/neg-macros/delegate-match-2/Test_2.scala:5:2 -----------------------------------------------------------
5 | f // error
| ^
Expand Down
1 change: 0 additions & 1 deletion tests/neg-macros/delegate-match-3.check
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

-- Error: tests/neg-macros/delegate-match-3/Test_2.scala:3:2 -----------------------------------------------------------
3 | f // error
| ^
Expand Down
1 change: 0 additions & 1 deletion tests/neg-macros/i11386.check
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

-- Error: tests/neg-macros/i11386/Test_2.scala:6:10 --------------------------------------------------------------------
6 | dummy(0) // error
| ^
Expand Down
1 change: 0 additions & 1 deletion tests/neg-macros/i13991.check
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

-- Error: tests/neg-macros/i13991/Test_2.scala:6:5 ---------------------------------------------------------------------
6 | v2 // error
| ^^
Expand Down
1 change: 0 additions & 1 deletion tests/neg-macros/i16582.check
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

-- Error: tests/neg-macros/i16582/Test_2.scala:6:27 --------------------------------------------------------------------
6 | val o2 = ownerDoesNotWork(2) // error
| ^^^^^^^^^^^^^^^^^^^
Expand Down
1 change: 0 additions & 1 deletion tests/neg-macros/i16835.check
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

-- Error: tests/neg-macros/i16835/Test_2.scala:1:17 --------------------------------------------------------------------
1 |def test: Unit = foo // error
| ^^^
Expand Down
1 change: 0 additions & 1 deletion tests/neg-macros/i18113.check
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

-- Error: tests/neg-macros/i18113/Test_2.scala:7:8 ---------------------------------------------------------------------
7 | X.test(ref) // error
| ^^^^^^^^^^^
Expand Down
1 change: 0 additions & 1 deletion tests/neg-macros/i18113b.check
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

-- Error: tests/neg-macros/i18113b/Test_2.scala:7:8 --------------------------------------------------------------------
7 | X.test(ref) // error
| ^^^^^^^^^^^
Expand Down
1 change: 0 additions & 1 deletion tests/neg-macros/i18677-a.check
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

-- Error: tests/neg-macros/i18677-a/Test_2.scala:4:6 -------------------------------------------------------------------
3 |@extendFoo
4 |class AFoo // error
Expand Down
1 change: 0 additions & 1 deletion tests/neg-macros/i18677-b.check
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

-- Error: tests/neg-macros/i18677-b/Test_2.scala:4:6 -------------------------------------------------------------------
3 |@extendFoo
4 |class AFoo // error
Expand Down
1 change: 0 additions & 1 deletion tests/neg-macros/i18825.check
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@

error overriding method toString in class Foo of type (): String;
method toString of type (): String cannot override final member method toString in class Foo
1 change: 0 additions & 1 deletion tests/neg-macros/i19676.check
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

-- Error: tests/neg-macros/i19676/Test_2.scala:3:0 ---------------------------------------------------------------------
3 |@buggy // error
|^^^^^^
Expand Down
1 change: 0 additions & 1 deletion tests/neg-macros/i21916.check
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

-- Error: tests/neg-macros/i21916/Test_2.scala:3:27 --------------------------------------------------------------------
3 |@main def Test = Macro.test() // error
| ^^^^^^^^^^^^
Expand Down
1 change: 0 additions & 1 deletion tests/neg-macros/i23008.check
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

-- Error: tests/neg-macros/i23008/Test_2.scala:1:24 --------------------------------------------------------------------
1 |@main def Test = Macros.buildString // error
| ^^^^^^^^^^^^^^^^^^
Expand Down
1 change: 0 additions & 1 deletion tests/neg-macros/i6432.check
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

-- Error: tests/neg-macros/i6432/Test_2.scala:4:6 ----------------------------------------------------------------------
4 | foo"abc${"123"}xyz${"456"}fgh" // error // error // error
| ^^^
Expand Down
1 change: 0 additions & 1 deletion tests/neg-macros/i6432b.check
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

-- Error: tests/neg-macros/i6432b/Test_2.scala:4:8 ---------------------------------------------------------------------
4 | foo"""abc${"123"}xyz${"456"}fgh""" // error // error // error
| ^^^
Expand Down
1 change: 0 additions & 1 deletion tests/neg-macros/i6976.check
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

-- Error: tests/neg-macros/i6976/Test_2.scala:5:44 ---------------------------------------------------------------------
5 | def main(args: Array[String]): Unit = mcr { 2 } // error
| ^^^^^^^^^
Expand Down
1 change: 0 additions & 1 deletion tests/neg-macros/i9014.check
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

-- Error: tests/neg-macros/i9014/Test_2.scala:1:23 ---------------------------------------------------------------------
1 |val tests = summon[Bar] // error
| ^
Expand Down
1 change: 0 additions & 1 deletion tests/neg-macros/i9014b.check
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

-- [E172] Type Error: tests/neg-macros/i9014b/Test_2.scala:1:23 --------------------------------------------------------
1 |val tests = summon[Bar] // error
| ^
Expand Down
1 change: 0 additions & 1 deletion tests/neg-macros/i9685.check
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

-- [E008] Not Found Error: tests/neg-macros/i9685/Test_2.scala:3:4 -----------------------------------------------------
3 | 1.asdf // error
| ^^^^^^
Expand Down
1 change: 0 additions & 1 deletion tests/neg-macros/ill-abort.check
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

-- Error: tests/neg-macros/ill-abort/quoted_2.scala:1:15 ---------------------------------------------------------------
1 |def test = fail() // error
| ^^^^^^
Expand Down
1 change: 0 additions & 1 deletion tests/neg-macros/newClassParamsMissingArgument.check
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

-- Error: tests/neg-macros/newClassParamsMissingArgument/Test_2.scala:4:2 ----------------------------------------------
4 | makeClass("foo") // error // error
| ^^^^^^^^^^^^^^^^
Expand Down
1 change: 0 additions & 1 deletion tests/neg-macros/wrong-owner.check
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

-- Error: tests/neg-macros/wrong-owner/Test_2.scala:5:6 ----------------------------------------------------------------
3 |@experimental
4 |@wrongOwner
Expand Down
1 change: 0 additions & 1 deletion tests/neg/experimental-message-experimental-flag.check
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

-- Error: tests/neg/experimental-message-experimental-flag/Test_2.scala:3:10 -------------------------------------------
3 |def g() = f() // error
| ^
Expand Down
1 change: 0 additions & 1 deletion tests/neg/i13190.check
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

-- [E172] Type Error: tests/neg/i13190/B_2.scala:14:38 -----------------------------------------------------------------
14 | summon[FindField[R, "B"] =:= Double] // error
| ^
Expand Down
1 change: 0 additions & 1 deletion tests/neg/i20245.check
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

-- [E046] Cyclic Error: tests/neg/i20245/Typer_2.scala:16:57 -----------------------------------------------------------
16 | private[typer] val unification = new Unification(using this) // error
| ^
Expand Down
1 change: 0 additions & 1 deletion tests/neg/i9408b.check
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

-- Migration Warning: tests/neg/i9408b/Test_2.scala:8:20 ---------------------------------------------------------------
8 | val length: Int = "abc" // warn
| ^^^^^
Expand Down
1 change: 0 additions & 1 deletion tests/neg/mixin-forwarder-clash2.check
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

-- [E120] Naming Error: tests/neg/mixin-forwarder-clash2/B_2.scala:1:6 -------------------------------------------------
1 |class Bar2 extends Bar1 with Two[Foo] // error
| ^
Expand Down
1 change: 0 additions & 1 deletion tests/neg/yimports-custom.check
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

-- [E006] Not Found Error: tests/neg/yimports-custom/C_2.scala:5:16 ----------------------------------------------------
5 | def greet() = println("hello, world!") // error
| ^^^^^^^
Expand Down
1 change: 0 additions & 1 deletion tests/neg/yimports-stable.check
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

error: bad preamble import hello.world.potions
-- [E006] Not Found Error: tests/neg/yimports-stable/C_2.scala:4:9 -----------------------------------------------------
4 | val v: Numb = magic // error // error
Expand Down
1 change: 0 additions & 1 deletion tests/warn/i22212.check
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

-- [E029] Pattern Match Exhaustivity Warning: tests/warn/i22212/Test_2.scala:3:19 --------------------------------------
3 | Macro.makeMatch() // warn: match may not be exhaustive.
| ^^^^^^^^^^^^^^^^^
Expand Down
1 change: 0 additions & 1 deletion tests/warn/i22795.check
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

-- Deprecation Warning: tests/warn/i22795/test_1.scala:4:7 -------------------------------------------------------------
4 | lib.m() // warn
| ^^^^^^^
Expand Down
Loading