Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Allow text comments on the same line as the marker comments
  • Loading branch information
RichardBradley committed Mar 21, 2014
commit 5396129f07ee182d5dcca06f16fd461f599beda4
2 changes: 1 addition & 1 deletion src/main/scala/scoverage/CoverageFilter.scala
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class CoverageFilter(excludedPackages: Seq[String]) {
mutable.WeakHashMap.empty

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

/**
* True if the given className has not been excluded by the
Expand Down
23 changes: 23 additions & 0 deletions src/test/scala/scoverage/CoverageFilterTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,29 @@ class CoverageFilterTest extends FlatSpec {
numbers === List(Range(4,9), Range(12,16))
}

"getExcludedLineNumbers" should "allow text comments on the same line as the markers" in {
val file =
"""1
|2
|3
| // $COVERAGE-OFF$ because the next lines are boring
|5
|6
|7
|8
| // $COVERAGE-ON$ resume coverage here
|10
|11
| // $COVERAGE-OFF$ but ignore this bit
|13
|14
|15
""".stripMargin

val numbers = new CoverageFilter(Nil).getExcludedLineNumbers(mockSourceFile(file))
numbers === List(Range(4,9), Range(12,16))
}

private def mockSourceFile(contents: String): SourceFile = {
new BatchSourceFile(NoFile, contents.toCharArray)
}
Expand Down