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