Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 6ba902a

Browse files
authored
Fix line and path separators in test (#23534)
Fixes #23458 Splitting on NL leaves the CR if present. Just use `linesIterator`. Introduce a template method for rendering paths. The test reporter replaces windows convention when run on windows, so that check files are correct; `FileDiff.matches` currently accounts for comparing lines of text when run on windows. Previously, a `TestReporter` with empty console output would contribute a NL because `"".split("\n")` is not empty. (There is a test reporter per compilation group.)
2 parents e1f2505 + 45afde7 commit 6ba902a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+31
-60
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: 24 additions & 12 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, FileasJFile}
6+
import java.io.{FileasJFile, *}
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 {
@@ -30,13 +32,17 @@ extends Reporter with UniqueMessagePositions with HideNonSensicalMessages with M
3032
final def messages: Iterator[String] = _messageBuf.iterator
3133

3234
protected final val _consoleBuf = new StringWriter
33-
protected final val _consoleReporter = new ConsoleReporter(null, new PrintWriter(_consoleBuf))
35+
protected final val _consoleReporter = new ConsoleReporter(null, new PrintWriter(_consoleBuf)):
36+
override protected def renderPath(file: AbstractFile): String = TestReporter.renderPath(file)
37+
3438
final def consoleOutput: String = _consoleBuf.toString
3539

3640
private var _skip: Boolean = false
3741
final def setSkip(): Unit = _skip = true
3842
final def skipped: Boolean = _skip
3943

44+
override protected def renderPath(file: AbstractFile): String = TestReporter.renderPath(file)
45+
4046
protected final def inlineInfo(pos: SourcePosition)(using Context): String =
4147
if (pos.exists) {
4248
if (pos.outer.exists)
@@ -152,10 +158,16 @@ object TestReporter {
152158
Properties.rerunFailed &&
153159
failedTestsFile.exists() &&
154160
failedTestsFile.isFile
155-
)(java.nio.file.Files.readAllLines(failedTestsFile.toPath).asScala.toList)
161+
)(readAllLines(failedTestsFile.toPath).asScala.toList)
156162

157163
def writeFailedTests(tests: List[String]): Unit =
158164
initLog()
159165
tests.foreach(failed => failedTestsWriter.println(failed))
160166
failedTestsWriter.flush()
167+
168+
def renderPath(file: AbstractFile): String =
169+
if JFile.separatorChar == '\\' then
170+
file.path.replace('\\', '/')
171+
else
172+
file.path
161173
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -730,7 +730,7 @@ trait ParallelTesting extends RunnerOrchestration:
730730
testSource.checkFile.foreach(diffTest(testSource, _, reporterOutputLines(reporters), reporters, logger))
731731

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

735735
private[ParallelTesting] def executeTestSuite(): this.type = {
736736
assert(testSourcesCompleted == 0, "not allowed to re-use a `CompileRun`")
@@ -1043,7 +1043,7 @@ trait ParallelTesting extends RunnerOrchestration:
10431043
testReporter
10441044
}
10451045
if !failedBestEffortCompilation.isEmpty then
1046-
Some(failedBestEffortCompilation.flatMap(_.consoleOutput.split("\n")).mkString("\n"))
1046+
Some(failedBestEffortCompilation.flatMap(_.consoleOutput.linesIterator).mkString("\n"))
10471047
else
10481048
None
10491049
}

‎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:3:8 --------------------------------------------------------
32
3 | this: D^ => // 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)

AltStyle によって変換されたページ (->オリジナル) /