Skip to content

Commit a5f5b34

Browse files
committed
Include all statements excluded by $COVERAGE-OFF$
Statements surrounded by $COVERAGE-OFF$ / $COVERAGE-ON$ tags are now included in the scoverage-data/scoverage.coverage.xml and scoverage.xml files however an "ignored" attribute has been added to the Statement object to indicate that the statement is contained within the above tags.
1 parent 274d5e3 commit a5f5b34

File tree

5 files changed

+29
-19
lines changed

5 files changed

+29
-19
lines changed

scalac-scoverage-plugin/src/main/scala/scoverage/Serializer.scala

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,9 @@ object Serializer {
6969
<count>
7070
{stmt.count.toString}
7171
</count>
72+
<ignored>
73+
{stmt.ignored.toString}
74+
</ignored>
7275
</statement>
7376
Utility.trim(xml) + "\n"
7477
}
@@ -86,6 +89,7 @@ object Serializer {
8689
val statements = xml \ "statement" map (node => {
8790
val source = (node \ "source").text
8891
val count = (node \ "count").text.toInt
92+
val ignored = (node \ "ignored").text.toBoolean
8993
val branch = (node \ "branch").text.toBoolean
9094
val _package = (node \ "package").text
9195
val _class = (node \ "class").text
@@ -112,12 +116,12 @@ object Serializer {
112116
line,
113117
desc,
114118
symbolName,
115-
treeName, branch, count)
119+
treeName, branch, count, ignored)
116120
})
117121

118122
val coverage = Coverage()
119123
for ( statement <- statements )
120-
coverage.add(statement)
124+
if (!statement.ignored) coverage.add(statement)
121125
coverage
122126
}
123127

scalac-scoverage-plugin/src/main/scala/scoverage/coverage.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,8 @@ case class Statement(source: String,
9494
symbolName: String,
9595
treeName: String,
9696
branch: Boolean,
97-
var count: Int = 0) extends java.io.Serializable {
97+
var count: Int = 0,
98+
ignored: Boolean = false) extends java.io.Serializable {
9899
def invoked(): Unit = count = count + 1
99100
def isInvoked = count > 0
100101
}

scalac-scoverage-plugin/src/main/scala/scoverage/plugin.scala

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -166,22 +166,23 @@ class ScoverageInstrumentationComponent(val global: Global)
166166
reporter.echo(s"[warn] Could not instrument [${tree.getClass.getSimpleName}/${tree.symbol}]. No pos.")
167167
tree
168168
case Some(source) =>
169+
val id = statementIds.incrementAndGet
170+
val statement = Statement(
171+
source.path,
172+
location,
173+
id,
174+
safeStart(tree),
175+
safeEnd(tree),
176+
safeLine(tree),
177+
original.toString,
178+
Option(original.symbol).fold("<nosymbol>")(_.fullNameString),
179+
tree.getClass.getSimpleName,
180+
branch
181+
)
169182
if (tree.pos.isDefined && !isStatementIncluded(tree.pos)) {
183+
coverage.add(statement.copy(ignored = true))
170184
tree
171185
} else {
172-
val id = statementIds.incrementAndGet
173-
val statement = Statement(
174-
source.path,
175-
location,
176-
id,
177-
safeStart(tree),
178-
safeEnd(tree),
179-
safeLine(tree),
180-
original.toString,
181-
Option(original.symbol).fold("<nosymbol>")(_.fullNameString),
182-
tree.getClass.getSimpleName,
183-
branch
184-
)
185186
coverage.add(statement)
186187

187188
val apply = invokeCall(id)

scalac-scoverage-plugin/src/main/scala/scoverage/report/ScoverageXmlReader.scala

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ object ScoverageXmlReader {
3131
val count = node \ "@invocation-count"
3232
val symbolName = node \ "@symbol"
3333
val treeName = node \ "@tree"
34+
val ignored = node \ "@ignored"
3435

3536
val location = Location(pkg.text,
3637
classname.text,
@@ -52,7 +53,8 @@ object ScoverageXmlReader {
5253
symbolName.text,
5354
treeName.text,
5455
branch.text.toBoolean,
55-
count.text.toInt
56+
count.text.toInt,
57+
ignored.text.toBoolean
5658
)
5759
}
5860
coverage

scalac-scoverage-plugin/src/main/scala/scoverage/report/ScoverageXmlWriter.scala

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,8 @@ class ScoverageXmlWriter(sourceDirectories: Seq[File], outputDir: File, debug: B
4646
symbol={Serializer.escape(stmt.symbolName)}
4747
tree={Serializer.escape(stmt.treeName)}
4848
branch={stmt.branch.toString}
49-
invocation-count={stmt.count.toString}>
49+
invocation-count={stmt.count.toString}
50+
ignored={stmt.ignored.toString}>
5051
{Serializer.escape(stmt.desc)}
5152
</statement>
5253
case false =>
@@ -60,7 +61,8 @@ class ScoverageXmlWriter(sourceDirectories: Seq[File], outputDir: File, debug: B
6061
end={stmt.end.toString}
6162
line={stmt.line.toString}
6263
branch={stmt.branch.toString}
63-
invocation-count={stmt.count.toString}/>
64+
invocation-count={stmt.count.toString}
65+
ignored={stmt.ignored.toString}/>
6466
}
6567
}
6668

0 commit comments

Comments
 (0)