@@ -45,15 +45,27 @@ class CoverageTests:
45
45
lines
46
46
end fixWindowsPaths
47
47
48
- def runOnFile (p : Path ): Boolean =
49
- scalaFile.matches(p) &&
50
- (Properties .testsFilter.isEmpty || Properties .testsFilter.exists(p.toString.contains))
48
+ def runOnFileOrDir (p : Path ): Boolean =
49
+ (scalaFile.matches(p) || Files .isDirectory(p))
50
+ && (p != dir)
51
+ && (Properties .testsFilter.isEmpty || Properties .testsFilter.exists(p.toString.contains))
52
+
53
+ Files .walk(dir, 1 ).filter(runOnFileOrDir).forEach(path => {
54
+ // measurement files only exist in the "run" category
55
+ // as these are generated at runtime by the scala.runtime.coverage.Invoker
56
+ val (targetDir, expectFile, expectMeasurementFile) =
57
+ if Files .isDirectory(path) then
58
+ val dirName = path.getFileName().toString
59
+ assert(! Files .walk(path).filter(scalaFile.matches(_)).toArray.isEmpty, s " No scala files found in test directory: ${path}" )
60
+ val targetDir = computeCoverageInTmp(path, isDirectory = true , dir, run)
61
+ (targetDir, path.resolve(s " test.scoverage.check " ), path.resolve(s " test.measurement.check " ))
62
+ else
63
+ val fileName = path.getFileName.toString.stripSuffix(" .scala" )
64
+ val targetDir = computeCoverageInTmp(path, isDirectory = false , dir, run)
65
+ (targetDir, path.resolveSibling(s " ${fileName}.scoverage.check " ), path.resolveSibling(s " ${fileName}.measurement.check " ))
51
66
52
- Files .walk(dir).filter(runOnFile).forEach(path => {
53
- val fileName = path.getFileName.toString.stripSuffix(" .scala" )
54
- val targetDir = computeCoverageInTmp(path, dir, run)
55
67
val targetFile = targetDir.resolve(s " scoverage.coverage " )
56
- val expectFile = path.resolveSibling( s " $fileName .scoverage.check " )
68
+
57
69
if updateCheckFiles then
58
70
Files .copy(targetFile, expectFile, StandardCopyOption .REPLACE_EXISTING )
59
71
else
@@ -63,9 +75,6 @@ class CoverageTests:
63
75
val instructions = FileDiff .diffMessage(expectFile.toString, targetFile.toString)
64
76
fail(s " Coverage report differs from expected data. \n $instructions" )
65
77
66
- // measurement files only exist in the "run" category
67
- // as these are generated at runtime by the scala.runtime.coverage.Invoker
68
- val expectMeasurementFile = path.resolveSibling(s " $fileName.measurement.check " )
69
78
if run && Files .exists(expectMeasurementFile) then
70
79
71
80
// Note that this assumes that the test invoked was single threaded,
@@ -86,14 +95,20 @@ class CoverageTests:
86
95
})
87
96
88
97
/** Generates the coverage report for the given input file, in a temporary directory. */
89
- def computeCoverageInTmp (inputFile : Path , sourceRoot : Path , run : Boolean )(using TestGroup ): Path =
98
+ def computeCoverageInTmp (inputFile : Path , isDirectory : Boolean , sourceRoot : Path , run : Boolean )(using TestGroup ): Path =
90
99
val target = Files .createTempDirectory(" coverage" )
91
100
val options = defaultOptions.and(" -Ycheck:instrumentCoverage" , " -coverage-out" , target.toString, " -sourceroot" , sourceRoot.toString)
92
101
if run then
93
- val test = compileDir(inputFile.getParent.toString, options)
102
+ val path = if isDirectory then inputFile.toString else inputFile.getParent.toString
103
+ val test = compileDir(path, options)
104
+ test.checkFilePaths.foreach { checkFilePath =>
105
+ assert(checkFilePath.exists, s " Expected checkfile for $path $checkFilePath does not exist. " )
106
+ }
94
107
test.checkRuns()
95
108
else
96
- val test = compileFile(inputFile.toString, options)
109
+ val test =
110
+ if isDirectory then compileDir(inputFile.toString, options)
111
+ else compileFile(inputFile.toString, options)
97
112
test.checkCompile()
98
113
target
99
114
0 commit comments