|
1 | 1 | package scoverage
|
2 | 2 |
|
3 |
| -import org.scalatest.FreeSpec |
| 3 | +import java.io.{InputStream, File, OutputStream} |
4 | 4 |
|
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} |
6 | 8 |
|
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 { |
8 | 13 |
|
9 | 14 | "isClassIncluded" - {
|
10 | 15 |
|
@@ -36,6 +41,26 @@ class RegexCoverageFilterTest extends FreeSpec {
|
36 | 41 | assert(!new RegexCoverageFilter(Seq(".*eee"), Nil).isClassIncluded("scoverageeee"))
|
37 | 42 | }
|
38 | 43 | }
|
| 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 | + } |
39 | 64 | "getExcludedLineNumbers" - {
|
40 | 65 | "should exclude no lines if no magic comments are found" in {
|
41 | 66 | val file =
|
|
0 commit comments