Skip to content

Commit eaac645

Browse files
committed
Added tests for exclude by filepath
1 parent cda4ce9 commit eaac645

File tree

3 files changed

+31
-6
lines changed

3 files changed

+31
-6
lines changed

build.sbt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ resolvers := ("releases" at "https://oss.sonatype.org/service/local/staging/depl
1212

1313
javacOptions ++= Seq("-source", "1.6", "-target", "1.6")
1414

15-
scalaVersion := "2.11.2"
15+
scalaVersion := "2.11.1"
1616

17-
crossScalaVersions := Seq("2.10.4", "2.11.2")
17+
crossScalaVersions := Seq("2.10.4", "2.11.1")
1818

1919
libraryDependencies ++= Seq(
2020
"org.scala-lang" % "scala-compiler" % scalaVersion.value % "provided",

src/main/scala/scoverage/CoverageFilter.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ class RegexCoverageFilter(excludedPackages: Seq[String],
4848
}
4949

5050
override def isFileIncluded(file: SourceFile): Boolean = {
51-
def isFileMatch(file:SourceFile) = excludedFilePatterns.exists(_.matcher(file.path).matches)
51+
def isFileMatch(file: SourceFile) = excludedFilePatterns.exists(_.matcher(file.path.replace(".scala", "")).matches)
5252
excludedFilePatterns.isEmpty || !isFileMatch(file)
5353
}
5454

src/test/scala/scoverage/RegexCoverageFilterTest.scala

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
11
package scoverage
22

3-
import org.scalatest.FreeSpec
3+
import java.io.{InputStream, File, OutputStream}
44

5-
import scala.reflect.internal.util.{BatchSourceFile, NoFile, SourceFile}
5+
import org.mockito.Mockito
6+
import org.scalatest.mock.MockitoSugar
7+
import org.scalatest.{Matchers, FreeSpec}
68

7-
class RegexCoverageFilterTest extends FreeSpec {
9+
import scala.reflect.internal.util._
10+
import scala.reflect.io.{Path, AbstractFile}
11+
12+
class RegexCoverageFilterTest extends FreeSpec with Matchers with MockitoSugar {
813

914
"isClassIncluded" - {
1015

@@ -36,6 +41,26 @@ class RegexCoverageFilterTest extends FreeSpec {
3641
assert(!new RegexCoverageFilter(Seq(".*eee"), Nil).isClassIncluded("scoverageeee"))
3742
}
3843
}
44+
"isFileIncluded" - {
45+
val abstractFile = mock[AbstractFile]
46+
Mockito.when(abstractFile.path).thenReturn("sammy.scala")
47+
"should return true for empty excludes" in {
48+
val file = new BatchSourceFile(abstractFile, Array.emptyCharArray)
49+
new RegexCoverageFilter(Nil, Nil).isFileIncluded(file) shouldBe true
50+
}
51+
"should exclude by filename" in {
52+
val file = new BatchSourceFile(abstractFile, Array.emptyCharArray)
53+
new RegexCoverageFilter(Nil, Seq("sammy")).isFileIncluded(file) shouldBe false
54+
}
55+
"should exclude by regex wildcard" in {
56+
val file = new BatchSourceFile(abstractFile, Array.emptyCharArray)
57+
new RegexCoverageFilter(Nil, Seq("sam.*")).isFileIncluded(file) shouldBe false
58+
}
59+
"should not exclude non matching regex" in {
60+
val file = new BatchSourceFile(abstractFile, Array.emptyCharArray)
61+
new RegexCoverageFilter(Nil, Seq("qweqeqwe")).isFileIncluded(file) shouldBe true
62+
}
63+
}
3964
"getExcludedLineNumbers" - {
4065
"should exclude no lines if no magic comments are found" in {
4166
val file =

0 commit comments

Comments
 (0)