Skip to content

Fix printed file path in PrintingTest.scala #8330

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Feb 18, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 14 additions & 8 deletions compiler/test/dotty/tools/dotc/printing/PrintingTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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
Expand Down
9 changes: 7 additions & 2 deletions compiler/test/dotty/tools/vulpix/FileDiff.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down Expand Up @@ -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
}
}

}