diff --git a/compiler/test/dotty/tools/dotc/printing/PrintingTest.scala b/compiler/test/dotty/tools/dotc/printing/PrintingTest.scala index ebbc08e49d91..460d8d459718 100644 --- a/compiler/test/dotty/tools/dotc/printing/PrintingTest.scala +++ b/compiler/test/dotty/tools/dotc/printing/PrintingTest.scala @@ -21,12 +21,6 @@ class PrintingTest { val testsDir = "tests/printing" val options = List("-Xprint:typer", "-color:never", "-classpath", TestConfiguration.basicClasspath) - private def fileContent(filePath: String): List[String] = - if (new File(filePath).exists) - Source.fromFile(filePath, "UTF-8").getLines().toList - else Nil - - private def compileFile(path: JPath): Boolean = { val baseFilePath = path.toString.stripSuffix(".scala") val checkFilePath = baseFilePath + ".check" @@ -42,8 +36,20 @@ class PrintingTest { } val actualLines = byteStream.toString("UTF-8").split("\\r?\\n") - - FileDiff.checkAndDump(path.toString, actualLines.toIndexedSeq, checkFilePath) + // 'options' includes option '-Xprint:typer' so the first output line + // looks similar to "result of tests/printing/i620.scala after typer:"; + // check files use slashes as file separators (Unix) but running tests + // on Windows produces backslashes. + // NB. option '-Xprint:<..>' can specify several phases. + val filteredLines = + if (config.Properties.isWin) + actualLines.map(line => + if (line.startsWith("result of")) line.replaceAll("\\\\", "/") else line + ) + else + actualLines + + FileDiff.checkAndDump(path.toString, filteredLines.toIndexedSeq, checkFilePath) } @Test diff --git a/compiler/test/dotty/tools/vulpix/FileDiff.scala b/compiler/test/dotty/tools/vulpix/FileDiff.scala index 2ff3524ce772..7eef57d4888b 100644 --- a/compiler/test/dotty/tools/vulpix/FileDiff.scala +++ b/compiler/test/dotty/tools/vulpix/FileDiff.scala @@ -3,6 +3,7 @@ package dotty.tools.vulpix import scala.io.Source import java.io.File import java.lang.System.{lineSeparator => EOL} +import java.nio.file.{Files, Paths} object FileDiff { def diffMessage(expectFile: String, actualFile: String): String = @@ -34,15 +35,19 @@ object FileDiff { outFile.writeAll(content.mkString("", EOL, EOL)) } - def checkAndDump(sourceTitle: String, actualLines: Seq[String], checkFilePath: String): Boolean = + def checkAndDump(sourceTitle: String, actualLines: Seq[String], checkFilePath: String): Boolean = { + val outFilePath = checkFilePath + ".out" FileDiff.check(sourceTitle, actualLines, checkFilePath) match { case Some(msg) => - val outFilePath = checkFilePath + ".out" FileDiff.dump(outFilePath, actualLines) println(msg) println(FileDiff.diffMessage(checkFilePath, outFilePath)) false case _ => + val jOutFilePath = Paths.get(outFilePath) + Files.deleteIfExists(jOutFilePath) true } + } + }