Skip to content

Commit c2bc0a0

Browse files
TheElectronWillsmarter
authored andcommitted
Check the runtime output of some coverage tests
1 parent 0d9bf9a commit c2bc0a0

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+1234
-1006
lines changed

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

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -16,27 +16,28 @@ import dotty.tools.dotc.Main
1616

1717
@Category(Array(classOf[BootstrappedOnlyTests]))
1818
class CoverageTests:
19-
import CoverageTests.*
20-
import CoverageTests.given
19+
import CoverageTests.{*, given}
2120

2221
private val scalaFile = FileSystems.getDefault.getPathMatcher("glob:**.scala")
2322
private val rootSrc = Paths.get(System.getProperty("dotty.tools.dotc.coverage.test"))
24-
private val expectDir = rootSrc.resolve("expect")
2523

2624
@Test
27-
def checkInstrumentedCode(): Unit =
28-
given TestGroup = TestGroup("instrumentCoverage")
29-
val updateCheckfiles = dotty.Properties.testsUpdateCheckfile
30-
val sourceRoot = rootSrc.toString
25+
def checkCoverageStatements(): Unit =
26+
checkCoverageIn(rootSrc.resolve("pos"), false)
3127

32-
Files.walk(expectDir).filter(scalaFile.matches).forEach(p => {
28+
@Test
29+
def checkInstrumentedRuns(): Unit =
30+
checkCoverageIn(rootSrc.resolve("run"), true)
31+
32+
def checkCoverageIn(dir: Path, run: Boolean)(using TestGroup): Unit =
33+
Files.walk(dir).filter(scalaFile.matches).forEach(p => {
3334
val path = p
3435
val fileName = path.getFileName.toString.stripSuffix(".scala")
35-
val targetDir = computeCoverageInTmp(path, sourceRoot)
36+
val targetDir = computeCoverageInTmp(path, dir, run)
3637
val targetFile = targetDir.resolve(s"scoverage.coverage")
37-
val expectFile = expectDir.resolve(s"$fileName.scoverage.check")
38+
val expectFile = p.resolveSibling(s"$fileName.scoverage.check")
3839

39-
if updateCheckfiles then
40+
if updateCheckFiles then
4041
Files.copy(targetFile, expectFile, StandardCopyOption.REPLACE_EXISTING)
4142
else
4243
val expected = Files.readAllLines(expectFile).asScala
@@ -51,10 +52,14 @@ class CoverageTests:
5152
})
5253

5354
/** Generates the coverage report for the given input file, in a temporary directory. */
54-
def computeCoverageInTmp(inputFile: Path, sourceRoot: String)(using TestGroup): Path =
55+
def computeCoverageInTmp(inputFile: Path, sourceRoot: Path, run: Boolean)(using TestGroup): Path =
5556
val target = Files.createTempDirectory("coverage")
56-
val options = defaultOptions.and("-Ycheck:instrumentCoverage", "-coverage-out", target.toString, "-coverage-sourceroot", sourceRoot)
57-
compileFile(inputFile.toString, options).checkCompile()
57+
val options = defaultOptions.and("-Ycheck:instrumentCoverage", "-coverage-out", target.toString, "-coverage-sourceroot", sourceRoot.toString)
58+
val test = compileFile(inputFile.toString, options)
59+
if run then
60+
test.checkRuns()
61+
else
62+
test.checkCompile()
5863
target
5964

6065
object CoverageTests extends ParallelTesting:
@@ -72,3 +77,5 @@ object CoverageTests extends ParallelTesting:
7277
@AfterClass def tearDown(): Unit =
7378
super.cleanup()
7479
summaryReport.echoSummary()
80+
81+
given TestGroup = TestGroup("instrumentCoverage")

project/Build.scala

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -613,13 +613,15 @@ object Build {
613613
testCoverage := Def.inputTaskDyn {
614614
val args = spaceDelimited("<arg>").parsed
615615
if (args.contains("--help")) {
616-
println("usage: testCoverage [--update-checkfiles]")
616+
println("usage: testCoverage [--update-checkfiles] [<args>]")
617617
(Test / testOnly).toTask(" not.a.test")
618618
} else {
619619
val updateCheckfile = args.contains("--update-checkfiles")
620+
val otherArgs = args.filter(_ != "--update-checkfiles")
620621
val test = "dotty.tools.dotc.coverage.CoverageTests"
621622
val argUpdateCheckfile = if (updateCheckfile) "-Ddotty.tests.updateCheckfiles=TRUE" else ""
622-
val cmd = s" $test -- $argUpdateCheckfile"
623+
val argCustom = if (otherArgs.nonEmpty) otherArgs.mkString(" ") else ""
624+
val cmd = s" $test -- $argUpdateCheckfile $argCustom"
623625
(Test/testOnly).toTask(cmd)
624626
}
625627
}.evaluated,

tests/coverage/expect/Currying.scoverage.check

Lines changed: 0 additions & 258 deletions
This file was deleted.

tests/coverage/expect/Lifting.scala

Lines changed: 0 additions & 18 deletions
This file was deleted.

0 commit comments

Comments
 (0)