@@ -17,6 +17,8 @@ import scala.language.unsafeNulls
17
17
import scala .collection .mutable .Buffer
18
18
import dotty .tools .dotc .util .DiffUtil
19
19
20
+ import java .util .stream .Collectors
21
+
20
22
@ Category (Array (classOf [BootstrappedOnlyTests ]))
21
23
class CoverageTests :
22
24
import CoverageTests .{* , given }
@@ -61,6 +63,26 @@ class CoverageTests:
61
63
val instructions = FileDiff .diffMessage(expectFile.toString, targetFile.toString)
62
64
fail(s " Coverage report differs from expected data. \n $instructions" )
63
65
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
+ if run && Files .exists(expectMeasurementFile) then
70
+
71
+ // Note that this assumes that the test invoked was single threaded,
72
+ // if that is not the case then this will have to be adjusted
73
+ val targetMeasurementFile = findMeasurementFile(targetDir)
74
+
75
+ if updateCheckFiles then
76
+ Files .copy(targetMeasurementFile, expectMeasurementFile, StandardCopyOption .REPLACE_EXISTING )
77
+
78
+ else
79
+ val targetMeasurementFile = findMeasurementFile(targetDir)
80
+ val expectedMeasurements = fixWindowsPaths(Files .readAllLines(expectMeasurementFile).asScala)
81
+ val obtainedMeasurements = fixWindowsPaths(Files .readAllLines(targetMeasurementFile).asScala)
82
+ if expectedMeasurements != obtainedMeasurements then
83
+ val instructions = FileDiff .diffMessage(expectMeasurementFile.toString, targetMeasurementFile.toString)
84
+ fail(s " Measurement report differs from expected data. \n $instructions" )
85
+ ()
64
86
})
65
87
66
88
/** Generates the coverage report for the given input file, in a temporary directory. */
@@ -75,6 +97,14 @@ class CoverageTests:
75
97
test.checkCompile()
76
98
target
77
99
100
+ private def findMeasurementFile (targetDir : Path ): Path = {
101
+ val allFilesInTarget = Files .list(targetDir).collect(Collectors .toList).asScala
102
+ allFilesInTarget.filter(_.getFileName.toString.startsWith(" scoverage.measurements." )).headOption.getOrElse(
103
+ throw new AssertionError (s " Expected to find measurement file in targetDir [ ${targetDir}] but none were found. " )
104
+ )
105
+ }
106
+
107
+
78
108
object CoverageTests extends ParallelTesting :
79
109
import scala .concurrent .duration .*
80
110
0 commit comments