@@ -45,15 +45,27 @@ class CoverageTests:
4545 lines
4646 end fixWindowsPaths
4747
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 " ))
5166
52- Files .walk(dir).filter(runOnFile).forEach(path => {
53- val fileName = path.getFileName.toString.stripSuffix(" .scala" )
54- val targetDir = computeCoverageInTmp(path, dir, run)
5567 val targetFile = targetDir.resolve(s " scoverage.coverage " )
56- val expectFile = path.resolveSibling( s " $fileName .scoverage.check " )
68+
5769 if updateCheckFiles then
5870 Files .copy(targetFile, expectFile, StandardCopyOption .REPLACE_EXISTING )
5971 else
@@ -63,9 +75,6 @@ class CoverageTests:
6375 val instructions = FileDiff .diffMessage(expectFile.toString, targetFile.toString)
6476 fail(s " Coverage report differs from expected data. \n $instructions" )
6577
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 " )
6978 if run && Files .exists(expectMeasurementFile) then
7079
7180 // Note that this assumes that the test invoked was single threaded,
@@ -86,14 +95,20 @@ class CoverageTests:
8695 })
8796
8897 /** 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 =
9099 val target = Files .createTempDirectory(" coverage" )
91100 val options = defaultOptions.and(" -Ycheck:instrumentCoverage" , " -coverage-out" , target.toString, " -sourceroot" , sourceRoot.toString)
92101 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+ }
94107 test.checkRuns()
95108 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)
97112 test.checkCompile()
98113 target
99114
0 commit comments