Skip to content

Commit f878e95

Browse files
authored
Merge pull request #611 from scala/backport-lts-3.3-23534
Backport "Fix line and path separators in test" to 3.3 LTS
2 parents 06bd2d4 + ae34ce9 commit f878e95

38 files changed

+28
-43
lines changed

compiler/src/dotty/tools/dotc/report.scala

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,8 +132,6 @@ object report:
132132
case Nil => pos
133133
recur(pos.sourcePos, tpd.enclosingInlineds)
134134

135-
private object messageRendering extends MessageRendering
136-
137135
// Should only be called from Run#enrichErrorMessage.
138136
def enrichErrorMessage(errorMessage: String)(using Context): String =
139137
if ctx.settings.YnoEnrichErrorMessages.value then errorMessage

compiler/src/dotty/tools/dotc/reporting/MessageRendering.scala

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import java.lang.System.{lineSeparator => EOL}
88

99
import core.Contexts.*
1010
import core.Decorators.*
11+
import io.AbstractFile
1112
import printing.Highlighting.{Blue, Red, Yellow}
1213
import printing.SyntaxHighlighting
1314
import Diagnostic.*
@@ -158,9 +159,12 @@ trait MessageRendering {
158159
.mkString(EOL)
159160
}
160161

162+
// file.path or munge it to normalize for testing
163+
protected def renderPath(file: AbstractFile): String = file.path
164+
161165
/** The source file path, line and column numbers from the given SourcePosition */
162166
protected def posFileStr(pos: SourcePosition): String =
163-
val path = pos.source.file.path
167+
val path = renderPath(pos.source.file)
164168
if pos.exists then s"$path:${pos.line + 1}:${pos.column}" else path
165169

166170
/** The separator between errors containing the source file and error type

compiler/test/dotty/tools/dotc/reporting/TestReporter.scala

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,19 @@
1-
package dotty.tools
1+
package dotty
2+
package tools
23
package dotc
34
package reporting
45

5-
import scala.language.unsafeNulls
6-
import java.io.{BufferedReader, FileInputStream, FileOutputStream, FileReader, PrintStream, PrintWriter, StringReader, StringWriter, File as JFile}
6+
import java.io.{File as JFile, *}
7+
import java.nio.file.Files.readAllLines
78
import java.text.SimpleDateFormat
89
import java.util.Date
10+
11+
import core.Contexts.*
912
import core.Decorators.*
13+
import interfaces.Diagnostic.{ERROR, WARNING}
14+
import io.AbstractFile
15+
import util.SourcePosition
16+
import Diagnostic.*
1017

1118
import scala.collection.mutable
1219
import scala.jdk.CollectionConverters.*
@@ -29,13 +36,17 @@ extends Reporter with UniqueMessagePositions with HideNonSensicalMessages with M
2936
final def messages: Iterator[String] = _messageBuf.iterator
3037

3138
protected final val _consoleBuf = new StringWriter
32-
protected final val _consoleReporter = new ConsoleReporter(null, new PrintWriter(_consoleBuf))
39+
protected final val _consoleReporter = new ConsoleReporter(null, new PrintWriter(_consoleBuf)):
40+
override protected def renderPath(file: AbstractFile): String = TestReporter.renderPath(file)
41+
3342
final def consoleOutput: String = _consoleBuf.toString
3443

3544
private var _skip: Boolean = false
3645
final def setSkip(): Unit = _skip = true
3746
final def skipped: Boolean = _skip
3847

48+
override protected def renderPath(file: AbstractFile): String = TestReporter.renderPath(file)
49+
3950
protected final def inlineInfo(pos: SourcePosition)(using Context): String =
4051
if (pos.exists) {
4152
if (pos.outer.exists)
@@ -149,10 +160,16 @@ object TestReporter {
149160
Properties.rerunFailed &&
150161
failedTestsFile.exists() &&
151162
failedTestsFile.isFile
152-
)(java.nio.file.Files.readAllLines(failedTestsFile.toPath).asScala.toList)
163+
)(readAllLines(failedTestsFile.toPath).asScala.toList)
153164

154165
def writeFailedTests(tests: List[String]): Unit =
155166
initLog()
156167
tests.foreach(failed => failedTestsWriter.println(failed))
157168
failedTestsWriter.flush()
169+
170+
def renderPath(file: AbstractFile): String =
171+
if JFile.separatorChar == '\\' then
172+
file.path.replace('\\', '/')
173+
else
174+
file.path
158175
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -667,7 +667,7 @@ trait ParallelTesting extends RunnerOrchestration:
667667
checkFile(testSource).foreach(diffTest(testSource, _, reporterOutputLines(reporters), reporters, logger))
668668

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

672672
private[ParallelTesting] def executeTestSuite(): this.type = {
673673
assert(testSourcesCompleted == 0, "not allowed to re-use a `CompileRun`")

tests/neg-custom-args/captures/cc-this2.check

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
-- Error: tests/neg-custom-args/captures/cc-this2/D_2.scala:2:6 --------------------------------------------------------
32
2 |class D extends C: // error
43
|^

tests/neg-macros/annot-crash.check

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
-- Error: tests/neg-macros/annot-crash/Test_2.scala:1:0 ----------------------------------------------------------------
32
1 |@crash // error
43
|^^^^^^

tests/neg-macros/annot-empty-result.check

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
-- Error: tests/neg-macros/annot-empty-result/Test_2.scala:5:2 ---------------------------------------------------------
32
5 | @nilAnnot // error
43
| ^^^^^^^^^

tests/neg-macros/annot-error-annot.check

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
-- Error: tests/neg-macros/annot-error-annot/Test_2.scala:17:6 ---------------------------------------------------------
32
16 |@error
43
17 |class cGlobal // error

tests/neg-macros/annot-ill-abort.check

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
-- Error: tests/neg-macros/annot-ill-abort/Test_2.scala:1:0 ------------------------------------------------------------
32
1 |@crash // error
43
|^^^^^^

tests/neg-macros/annot-mod-class-add-top-method.check

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
-- Error: tests/neg-macros/annot-mod-class-add-top-method/Test_2.scala:1:0 ---------------------------------------------
32
1 |@addTopLevelMethod // error
43
|^^^^^^^^^^^^^^^^^^

0 commit comments

Comments
 (0)