Skip to content

Commit ba45d46

Browse files
authored
Merge pull request #14945 from TheElectronWill/fix-win-coverage-tests
Fix coverage tests on windows
2 parents bc79e95 + 0529bf8 commit ba45d46

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

compiler/test/dotty/tools/dotc/coverage/CoverageTests.scala

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import java.nio.file.{Files, FileSystems, Path, Paths, StandardCopyOption}
1414
import scala.jdk.CollectionConverters.*
1515
import scala.util.Properties.userDir
1616
import scala.language.unsafeNulls
17+
import scala.collection.mutable.Buffer
1718

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

3334
def checkCoverageIn(dir: Path, run: Boolean)(using TestGroup): Unit =
35+
/** Converts \ to / on windows, to make the tests pass without changing the serialization. */
36+
def fixWindowsPaths(lines: Buffer[String]): Buffer[String] =
37+
val separator = java.io.File.separatorChar
38+
if separator != '/' then
39+
lines.map(_.replace("\\" + separator, "/")) // escape the separator
40+
else
41+
lines
42+
end fixWindowsPaths
43+
3444
Files.walk(dir).filter(scalaFile.matches).forEach(p => {
3545
val path = p
3646
val fileName = path.getFileName.toString.stripSuffix(".scala")
@@ -41,8 +51,8 @@ class CoverageTests:
4151
if updateCheckFiles then
4252
Files.copy(targetFile, expectFile, StandardCopyOption.REPLACE_EXISTING)
4353
else
44-
val expected = Files.readAllLines(expectFile).asScala
45-
val obtained = Files.readAllLines(targetFile).asScala
54+
val expected = fixWindowsPaths(Files.readAllLines(expectFile).asScala)
55+
val obtained = fixWindowsPaths(Files.readAllLines(targetFile).asScala)
4656
if expected != obtained then
4757
for ((exp, actual),i) <- expected.zip(obtained).filter(_ != _).zipWithIndex do
4858
Console.err.println(s"wrong line ${i+1}:")

0 commit comments

Comments
 (0)