From 837be4593f4681fce9d0d08d2d17c79d65528fb4 Mon Sep 17 00:00:00 2001 From: Nicolas Stucki Date: Tue, 19 Apr 2022 13:34:46 +0200 Subject: [PATCH 1/2] Use filter in coverage tests Fixes #14968 --- .../tools/dotc/coverage/CoverageTests.scala | 36 +++++++++---------- 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/compiler/test/dotty/tools/dotc/coverage/CoverageTests.scala b/compiler/test/dotty/tools/dotc/coverage/CoverageTests.scala index 6f978bc131d8..15e6af6fe562 100644 --- a/compiler/test/dotty/tools/dotc/coverage/CoverageTests.scala +++ b/compiler/test/dotty/tools/dotc/coverage/CoverageTests.scala @@ -41,24 +41,24 @@ class CoverageTests: lines end fixWindowsPaths - Files.walk(dir).filter(scalaFile.matches).forEach(p => { - val path = p - val fileName = path.getFileName.toString.stripSuffix(".scala") - val targetDir = computeCoverageInTmp(path, dir, run) - val targetFile = targetDir.resolve(s"scoverage.coverage") - val expectFile = p.resolveSibling(s"$fileName.scoverage.check") - - if updateCheckFiles then - Files.copy(targetFile, expectFile, StandardCopyOption.REPLACE_EXISTING) - else - 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}:") - Console.err.println(s" expected: $exp") - Console.err.println(s" actual : $actual") - fail(s"$targetFile differs from expected $expectFile") + Files.walk(dir).filter(scalaFile.matches).forEach(path => { + if Properties.testsFilter.isEmpty || Properties.testsFilter.exists(path.toString.contains) then + val fileName = path.getFileName.toString.stripSuffix(".scala") + val targetDir = computeCoverageInTmp(path, dir, run) + val targetFile = targetDir.resolve(s"scoverage.coverage") + val expectFile = path.resolveSibling(s"$fileName.scoverage.check") + + if updateCheckFiles then + Files.copy(targetFile, expectFile, StandardCopyOption.REPLACE_EXISTING) + else + 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}:") + Console.err.println(s" expected: $exp") + Console.err.println(s" actual : $actual") + fail(s"$targetFile differs from expected $expectFile") }) From 318f610908fe0b5ace9e84c04de3a83ba414601e Mon Sep 17 00:00:00 2001 From: Nicolas Stucki Date: Tue, 19 Apr 2022 16:20:28 +0200 Subject: [PATCH 2/2] Update compiler/test/dotty/tools/dotc/coverage/CoverageTests.scala Co-authored-by: Guillaume Raffin --- .../tools/dotc/coverage/CoverageTests.scala | 38 ++++++++++--------- 1 file changed, 20 insertions(+), 18 deletions(-) diff --git a/compiler/test/dotty/tools/dotc/coverage/CoverageTests.scala b/compiler/test/dotty/tools/dotc/coverage/CoverageTests.scala index 15e6af6fe562..9edc3f5b1cf9 100644 --- a/compiler/test/dotty/tools/dotc/coverage/CoverageTests.scala +++ b/compiler/test/dotty/tools/dotc/coverage/CoverageTests.scala @@ -41,24 +41,26 @@ class CoverageTests: lines end fixWindowsPaths - Files.walk(dir).filter(scalaFile.matches).forEach(path => { - if Properties.testsFilter.isEmpty || Properties.testsFilter.exists(path.toString.contains) then - val fileName = path.getFileName.toString.stripSuffix(".scala") - val targetDir = computeCoverageInTmp(path, dir, run) - val targetFile = targetDir.resolve(s"scoverage.coverage") - val expectFile = path.resolveSibling(s"$fileName.scoverage.check") - - if updateCheckFiles then - Files.copy(targetFile, expectFile, StandardCopyOption.REPLACE_EXISTING) - else - 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}:") - Console.err.println(s" expected: $exp") - Console.err.println(s" actual : $actual") - fail(s"$targetFile differs from expected $expectFile") + def runOnFile(p: Path): Boolean = + scalaFile.matches(p) && + (Properties.testsFilter.isEmpty || Properties.testsFilter.exists(p.toString.contains)) + + Files.walk(dir).filter(runOnFile).forEach(path => { + val fileName = path.getFileName.toString.stripSuffix(".scala") + val targetDir = computeCoverageInTmp(path, dir, run) + val targetFile = targetDir.resolve(s"scoverage.coverage") + val expectFile = path.resolveSibling(s"$fileName.scoverage.check") + if updateCheckFiles then + Files.copy(targetFile, expectFile, StandardCopyOption.REPLACE_EXISTING) + else + 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}:") + Console.err.println(s" expected: $exp") + Console.err.println(s" actual : $actual") + fail(s"$targetFile differs from expected $expectFile") })