@@ -54,15 +54,27 @@ class CoverageTests:
5454 lines
5555 end fixWindowsPaths
5656
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 " ))
6075
61- Files .walk(dir).filter(runOnFile).forEach(path => {
62- val fileName = path.getFileName.toString.stripSuffix(" .scala" )
63- val targetDir = computeCoverageInTmp(path, dir, run)
6476 val targetFile = targetDir.resolve(s " scoverage.coverage " )
65- val expectFile = path.resolveSibling( s " $fileName .scoverage.check " )
77+
6678 if updateCheckFiles then
6779 Files .copy(targetFile, expectFile, StandardCopyOption .REPLACE_EXISTING )
6880 else
@@ -72,9 +84,6 @@ class CoverageTests:
7284 val instructions = FileDiff .diffMessage(expectFile.toString, targetFile.toString)
7385 fail(s " Coverage report differs from expected data. \n $instructions" )
7486
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 " )
7887 if run && Files .exists(expectMeasurementFile) then
7988
8089 // Note that this assumes that the test invoked was single threaded,
@@ -95,14 +104,20 @@ class CoverageTests:
95104 })
96105
97106 /** 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 =
99108 val target = Files .createTempDirectory(" coverage" )
100109 val options = defaultOptions.and(" -Ycheck:instrumentCoverage" , " -coverage-out" , target.toString, " -sourceroot" , sourceRoot.toString)
101110 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+ }
103116 test.checkRuns()
104117 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)
106121 test.checkCompile()
107122 target
108123
0 commit comments