Skip to content

Commit 29a4e77

Browse files
committed
fix printed file path in PrintingTest.scala
1 parent 516978a commit 29a4e77

File tree

2 files changed

+22
-10
lines changed

2 files changed

+22
-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: 8 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,20 @@ 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+
if (Files.exists(jOutFilePath))
49+
try { Files.delete(jOutFilePath) } catch { case _: Exception => () }
4650
true
4751
}
52+
}
53+
4854
}

0 commit comments

Comments
 (0)