@@ -16,27 +16,28 @@ import dotty.tools.dotc.Main
1616
1717@ Category (Array (classOf [BootstrappedOnlyTests ]))
1818class 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
6065object 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" )
0 commit comments