Skip to content

Fix coverage tests on windows #14945

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 1 commit into from
Apr 14, 2022
Merged
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
14 changes: 12 additions & 2 deletions compiler/test/dotty/tools/dotc/coverage/CoverageTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import java.nio.file.{Files, FileSystems, Path, Paths, StandardCopyOption}
import scala.jdk.CollectionConverters.*
import scala.util.Properties.userDir
import scala.language.unsafeNulls
import scala.collection.mutable.Buffer

@Category(Array(classOf[BootstrappedOnlyTests]))
class CoverageTests:
Expand All @@ -31,6 +32,15 @@ class CoverageTests:
checkCoverageIn(rootSrc.resolve("run"), true)

def checkCoverageIn(dir: Path, run: Boolean)(using TestGroup): Unit =
/** Converts \ to / on windows, to make the tests pass without changing the serialization. */
def fixWindowsPaths(lines: Buffer[String]): Buffer[String] =
val separator = java.io.File.separatorChar
if separator != '/' then
lines.map(_.replace("\\" + separator, "/")) // escape the separator
else
lines
end fixWindowsPaths

Files.walk(dir).filter(scalaFile.matches).forEach(p => {
val path = p
val fileName = path.getFileName.toString.stripSuffix(".scala")
Expand All @@ -41,8 +51,8 @@ class CoverageTests:
if updateCheckFiles then
Files.copy(targetFile, expectFile, StandardCopyOption.REPLACE_EXISTING)
else
val expected = Files.readAllLines(expectFile).asScala
val obtained = Files.readAllLines(targetFile).asScala
val expected = fixWindowsPaths(Files.readAllLines(expectFile).asScala)
val obtained = fixWindowsPaths(Files.readAllLines(targetFile).asScala)
if expected != obtained then
for ((exp, actual),i) <- expected.zip(obtained).filter(_ != _).zipWithIndex do
Console.err.println(s"wrong line ${i+1}:")
Expand Down