From 29a4e77f422ff6a37df0ecfa1e1a22fb8200aa99 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Micheloud?= Date: Mon, 17 Feb 2020 12:18:19 +0100 Subject: [PATCH 1/2] fix printed file path in PrintingTest.scala --- .../tools/dotc/printing/PrintingTest.scala | 22 ++++++++++++------- .../test/dotty/tools/vulpix/FileDiff.scala | 10 +++++++-- 2 files changed, 22 insertions(+), 10 deletions(-) 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..24635c53f0b6 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,20 @@ 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) + if (Files.exists(jOutFilePath)) + try { Files.delete(jOutFilePath) } catch { case _: Exception => () } true } + } + } From 53a986f55aea43724f1844b2a2917cba4c4fcc30 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Micheloud?= Date: Mon, 17 Feb 2020 16:17:37 +0100 Subject: [PATCH 2/2] minor change to address review --- compiler/test/dotty/tools/vulpix/FileDiff.scala | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/compiler/test/dotty/tools/vulpix/FileDiff.scala b/compiler/test/dotty/tools/vulpix/FileDiff.scala index 24635c53f0b6..7eef57d4888b 100644 --- a/compiler/test/dotty/tools/vulpix/FileDiff.scala +++ b/compiler/test/dotty/tools/vulpix/FileDiff.scala @@ -45,8 +45,7 @@ object FileDiff { false case _ => val jOutFilePath = Paths.get(outFilePath) - if (Files.exists(jOutFilePath)) - try { Files.delete(jOutFilePath) } catch { case _: Exception => () } + Files.deleteIfExists(jOutFilePath) true } }