Skip to content

Commit 8fb81c8

Browse files
committed
Format paths for testing
1 parent 976a8f5 commit 8fb81c8

File tree

3 files changed

+24
-14
lines changed

3 files changed

+24
-14
lines changed

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

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

147-
private object messageRendering extends MessageRendering
148-
149147
// Should only be called from Run#enrichErrorMessage.
150148
def enrichErrorMessage(errorMessage: String)(using Context): String =
151149
if ctx.settings.XnoEnrichErrorMessages.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: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,25 @@
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
9-
import core.Decorators.*
1010

11-
import scala.collection.mutable
12-
import scala.jdk.CollectionConverters.*
13-
import util.SourcePosition
1411
import core.Contexts.*
15-
import Diagnostic.*
16-
import dotty.Properties
12+
import core.Decorators.*
1713
import interfaces.Diagnostic.{ERROR, WARNING}
14+
import io.AbstractFile
15+
import util.SourcePosition
16+
import Diagnostic.*
1817

19-
import scala.io.Codec
18+
import scala.collection.mutable
2019
import scala.compiletime.uninitialized
20+
import scala.io.Codec
21+
import scala.jdk.CollectionConverters.*
22+
import scala.language.unsafeNulls
2123

2224
class TestReporter protected (outWriter: PrintWriter, logLevel: Int)
2325
extends Reporter with UniqueMessagePositions with HideNonSensicalMessages with MessageRendering {
@@ -37,6 +39,12 @@ extends Reporter with UniqueMessagePositions with HideNonSensicalMessages with M
3739
final def setSkip(): Unit = _skip = true
3840
final def skipped: Boolean = _skip
3941

42+
override protected def renderPath(file: AbstractFile): String =
43+
if JFile.separatorChar == '\\' then
44+
file.path.replace('\\', '/')
45+
else
46+
file.path
47+
4048
protected final def inlineInfo(pos: SourcePosition)(using Context): String =
4149
if (pos.exists) {
4250
if (pos.outer.exists)
@@ -152,7 +160,7 @@ object TestReporter {
152160
Properties.rerunFailed &&
153161
failedTestsFile.exists() &&
154162
failedTestsFile.isFile
155-
)(java.nio.file.Files.readAllLines(failedTestsFile.toPath).asScala.toList)
163+
)(readAllLines(failedTestsFile.toPath).asScala.toList)
156164

157165
def writeFailedTests(tests: List[String]): Unit =
158166
initLog()

0 commit comments

Comments
 (0)