Skip to content

Commit 5018a12

Browse files
authored
Merge pull request #8330 from michelou/dotty-i620
Fix printed file path in PrintingTest.scala
2 parents 76caf35 + 53a986f commit 5018a12

File tree

2 files changed

+21
-10
lines changed

2 files changed

+21
-10
lines changed

compiler/test/dotty/tools/dotc/printing/PrintingTest.scala

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,6 @@ class PrintingTest {
2121
val testsDir = "tests/printing"
2222
val options = List("-Xprint:typer", "-color:never", "-classpath", TestConfiguration.basicClasspath)
2323

24-
private def fileContent(filePath: String): List[String] =
25-
if (new File(filePath).exists)
26-
Source.fromFile(filePath, "UTF-8").getLines().toList
27-
else Nil
28-
29-
3024
private def compileFile(path: JPath): Boolean = {
3125
val baseFilePath = path.toString.stripSuffix(".scala")
3226
val checkFilePath = baseFilePath + ".check"
@@ -42,8 +36,20 @@ class PrintingTest {
4236
}
4337

4438
val actualLines = byteStream.toString("UTF-8").split("\\r?\\n")
45-
46-
FileDiff.checkAndDump(path.toString, actualLines.toIndexedSeq, checkFilePath)
39+
// 'options' includes option '-Xprint:typer' so the first output line
40+
// looks similar to "result of tests/printing/i620.scala after typer:";
41+
// check files use slashes as file separators (Unix) but running tests
42+
// on Windows produces backslashes.
43+
// NB. option '-Xprint:<..>' can specify several phases.
44+
val filteredLines =
45+
if (config.Properties.isWin)
46+
actualLines.map(line =>
47+
if (line.startsWith("result of")) line.replaceAll("\\\\", "/") else line
48+
)
49+
else
50+
actualLines
51+
52+
FileDiff.checkAndDump(path.toString, filteredLines.toIndexedSeq, checkFilePath)
4753
}
4854

4955
@Test

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

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package dotty.tools.vulpix
33
import scala.io.Source
44
import java.io.File
55
import java.lang.System.{lineSeparator => EOL}
6+
import java.nio.file.{Files, Paths}
67

78
object FileDiff {
89
def diffMessage(expectFile: String, actualFile: String): String =
@@ -34,15 +35,19 @@ object FileDiff {
3435
outFile.writeAll(content.mkString("", EOL, EOL))
3536
}
3637

37-
def checkAndDump(sourceTitle: String, actualLines: Seq[String], checkFilePath: String): Boolean =
38+
def checkAndDump(sourceTitle: String, actualLines: Seq[String], checkFilePath: String): Boolean = {
39+
val outFilePath = checkFilePath + ".out"
3840
FileDiff.check(sourceTitle, actualLines, checkFilePath) match {
3941
case Some(msg) =>
40-
val outFilePath = checkFilePath + ".out"
4142
FileDiff.dump(outFilePath, actualLines)
4243
println(msg)
4344
println(FileDiff.diffMessage(checkFilePath, outFilePath))
4445
false
4546
case _ =>
47+
val jOutFilePath = Paths.get(outFilePath)
48+
Files.deleteIfExists(jOutFilePath)
4649
true
4750
}
51+
}
52+
4853
}

0 commit comments

Comments
 (0)