@@ -16,27 +16,28 @@ import dotty.tools.dotc.Main
16
16
17
17
@ Category (Array (classOf [BootstrappedOnlyTests ]))
18
18
class CoverageTests :
19
- import CoverageTests .*
20
- import CoverageTests .given
19
+ import CoverageTests .{* , given }
21
20
22
21
private val scalaFile = FileSystems .getDefault.getPathMatcher(" glob:**.scala" )
23
22
private val rootSrc = Paths .get(System .getProperty(" dotty.tools.dotc.coverage.test" ))
24
- private val expectDir = rootSrc.resolve(" expect" )
25
23
26
24
@ 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 )
31
27
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 => {
33
34
val path = p
34
35
val fileName = path.getFileName.toString.stripSuffix(" .scala" )
35
- val targetDir = computeCoverageInTmp(path, sourceRoot )
36
+ val targetDir = computeCoverageInTmp(path, dir, run )
36
37
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 " )
38
39
39
- if updateCheckfiles then
40
+ if updateCheckFiles then
40
41
Files .copy(targetFile, expectFile, StandardCopyOption .REPLACE_EXISTING )
41
42
else
42
43
val expected = Files .readAllLines(expectFile).asScala
@@ -51,10 +52,14 @@ class CoverageTests:
51
52
})
52
53
53
54
/** 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 =
55
56
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()
58
63
target
59
64
60
65
object CoverageTests extends ParallelTesting :
@@ -72,3 +77,5 @@ object CoverageTests extends ParallelTesting:
72
77
@ AfterClass def tearDown (): Unit =
73
78
super .cleanup()
74
79
summaryReport.echoSummary()
80
+
81
+ given TestGroup = TestGroup (" instrumentCoverage" )
0 commit comments