Skip to content

Commit 5396129

Browse files
Allow text comments on the same line as the marker comments
1 parent 81c90fb commit 5396129

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

src/main/scala/scoverage/CoverageFilter.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ class CoverageFilter(excludedPackages: Seq[String]) {
2121
mutable.WeakHashMap.empty
2222

2323
final val scoverageExclusionCommentsRegex =
24-
"""(?ms)^\s*//\s*(\$COVERAGE-OFF\$)\s*$.*?(^\s*//\s*\$COVERAGE-ON\$\s*$|\Z)""".r
24+
"""(?ms)^\s*//\s*(\$COVERAGE-OFF\$).*?(^\s*//\s*\$COVERAGE-ON\$|\Z)""".r
2525

2626
/**
2727
* True if the given className has not been excluded by the

src/test/scala/scoverage/CoverageFilterTest.scala

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,29 @@ class CoverageFilterTest extends FlatSpec {
9696
numbers === List(Range(4,9), Range(12,16))
9797
}
9898

99+
"getExcludedLineNumbers" should "allow text comments on the same line as the markers" in {
100+
val file =
101+
"""1
102+
|2
103+
|3
104+
| // $COVERAGE-OFF$ because the next lines are boring
105+
|5
106+
|6
107+
|7
108+
|8
109+
| // $COVERAGE-ON$ resume coverage here
110+
|10
111+
|11
112+
| // $COVERAGE-OFF$ but ignore this bit
113+
|13
114+
|14
115+
|15
116+
""".stripMargin
117+
118+
val numbers = new CoverageFilter(Nil).getExcludedLineNumbers(mockSourceFile(file))
119+
numbers === List(Range(4,9), Range(12,16))
120+
}
121+
99122
private def mockSourceFile(contents: String): SourceFile = {
100123
new BatchSourceFile(NoFile, contents.toCharArray)
101124
}

0 commit comments

Comments
 (0)