Skip to content

Commit 47a84a6

Browse files
committed
Updated coverage tests after updating coverage filter
1 parent 0da7989 commit 47a84a6

File tree

2 files changed

+113
-111
lines changed

2 files changed

+113
-111
lines changed

src/test/scala/scoverage/CoverageTest.scala

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,16 @@ class CoverageTest extends FunSuite with BeforeAndAfter with OneInstancePerTest
1414

1515
test("coverage for no invoked statements is 0") {
1616
val coverage = Coverage()
17-
coverage.add(MeasuredStatement("", Location("", "", ClassType.Object, ""), 1, 2, 3, 4, "", "", "", false, 0))
17+
coverage.add(MeasuredStatement("", Location("", "", ClassType.Object, "", ""), 1, 2, 3, 4, "", "", "", false, 0))
1818
assert(0 === coverage.statementCoverage)
1919
}
2020

2121
test("coverage for invoked statements") {
2222
val coverage = Coverage()
23-
coverage.add(MeasuredStatement("", Location("", "", ClassType.Object, ""), 1, 2, 3, 4, "", "", "", false, 3))
24-
coverage.add(MeasuredStatement("", Location("", "", ClassType.Object, ""), 2, 2, 3, 4, "", "", "", false, 0))
25-
coverage.add(MeasuredStatement("", Location("", "", ClassType.Object, ""), 3, 2, 3, 4, "", "", "", false, 0))
26-
coverage.add(MeasuredStatement("", Location("", "", ClassType.Object, ""), 4, 2, 3, 4, "", "", "", false, 0))
23+
coverage.add(MeasuredStatement("", Location("", "", ClassType.Object, "", ""), 1, 2, 3, 4, "", "", "", false, 3))
24+
coverage.add(MeasuredStatement("", Location("", "", ClassType.Object, "", ""), 2, 2, 3, 4, "", "", "", false, 0))
25+
coverage.add(MeasuredStatement("", Location("", "", ClassType.Object, "", ""), 3, 2, 3, 4, "", "", "", false, 0))
26+
coverage.add(MeasuredStatement("", Location("", "", ClassType.Object, "", ""), 4, 2, 3, 4, "", "", "", false, 0))
2727
assert(0.25 === coverage.statementCoverage)
2828
}
2929
}

src/test/scala/scoverage/RegexCoverageFilterTest.scala

Lines changed: 108 additions & 106 deletions
Original file line numberDiff line numberDiff line change
@@ -1,122 +1,124 @@
11
package scoverage
22

3-
import org.scalatest.FlatSpec
4-
import scala.reflect.internal.util.{NoFile, BatchSourceFile, SourceFile}
3+
import org.scalatest.FreeSpec
54

6-
class RegexCoverageFilterTest extends FlatSpec {
5+
import scala.reflect.internal.util.{BatchSourceFile, NoFile, SourceFile}
76

8-
"isClassIncluded" should "return true for empty excludes" in {
9-
assert(new RegexCoverageFilter(Nil).isClassIncluded("x"))
10-
}
7+
class RegexCoverageFilterTest extends FreeSpec {
118

12-
"isClassIncluded" should "not crash for empty input" in {
13-
assert(new RegexCoverageFilter(Nil).isClassIncluded(""))
14-
}
9+
"isClassIncluded" - {
1510

16-
"isClassIncluded" should "exclude scoverage -> scoverage" in {
17-
assert(!new RegexCoverageFilter(Seq("scoverage")).isClassIncluded("scoverage"))
18-
}
11+
"should return true for empty excludes" in {
12+
assert(new RegexCoverageFilter(Nil, Nil).isClassIncluded("x"))
13+
}
1914

20-
"isClassIncluded" should "include scoverage -> scoverageeee" in {
21-
assert(new RegexCoverageFilter(Seq("scoverage")).isClassIncluded("scoverageeee"))
22-
}
15+
"should not crash for empty input" in {
16+
assert(new RegexCoverageFilter(Nil, Nil).isClassIncluded(""))
17+
}
2318

24-
"isClassIncluded" should "exclude scoverage* -> scoverageeee" in {
25-
assert(!new RegexCoverageFilter(Seq("scoverage*")).isClassIncluded("scoverageeee"))
26-
}
19+
"should exclude scoverage -> scoverage" in {
20+
assert(!new RegexCoverageFilter(Seq("scoverage"), Nil).isClassIncluded("scoverage"))
21+
}
2722

28-
"isClassIncluded" should "include eee -> scoverageeee" in {
29-
assert(new RegexCoverageFilter(Seq("eee")).isClassIncluded("scoverageeee"))
30-
}
23+
"should include scoverage -> scoverageeee" in {
24+
assert(new RegexCoverageFilter(Seq("scoverage"), Nil).isClassIncluded("scoverageeee"))
25+
}
3126

32-
"isClassIncluded" should "exclude .*eee -> scoverageeee" in {
33-
assert(!new RegexCoverageFilter(Seq(".*eee")).isClassIncluded("scoverageeee"))
34-
}
27+
"should exclude scoverage* -> scoverageeee" in {
28+
assert(!new RegexCoverageFilter(Seq("scoverage*"), Nil).isClassIncluded("scoverageeee"))
29+
}
3530

36-
"getExcludedLineNumbers" should "exclude no lines if no magic comments are found" in {
37-
val file =
38-
"""1
39-
|2
40-
|3
41-
|4
42-
|5
43-
|6
44-
|7
45-
|8
46-
""".stripMargin
47-
48-
val numbers = new RegexCoverageFilter(Nil).getExcludedLineNumbers(mockSourceFile(file))
49-
numbers === List.empty
50-
}
31+
"should include eee -> scoverageeee" in {
32+
assert(new RegexCoverageFilter(Seq("eee"), Nil).isClassIncluded("scoverageeee"))
33+
}
5134

52-
"getExcludedLineNumbers" should "exclude lines between magic comments" in {
53-
val file =
54-
"""1
55-
|2
56-
|3
57-
| // $COVERAGE-OFF$
58-
|5
59-
|6
60-
|7
61-
|8
62-
| // $COVERAGE-ON$
63-
|10
64-
|11
65-
| // $COVERAGE-OFF$
66-
|13
67-
| // $COVERAGE-ON$
68-
|15
69-
|16
70-
""".stripMargin
71-
72-
val numbers = new RegexCoverageFilter(Nil).getExcludedLineNumbers(mockSourceFile(file))
73-
numbers === List(Range(4,9), Range(12,14))
35+
"should exclude .*eee -> scoverageeee" in {
36+
assert(!new RegexCoverageFilter(Seq(".*eee"), Nil).isClassIncluded("scoverageeee"))
37+
}
7438
}
75-
76-
"getExcludedLineNumbers" should "exclude all lines after an upaired magic comment" in {
77-
val file =
78-
"""1
79-
|2
80-
|3
81-
| // $COVERAGE-OFF$
82-
|5
83-
|6
84-
|7
85-
|8
86-
| // $COVERAGE-ON$
87-
|10
88-
|11
89-
| // $COVERAGE-OFF$
90-
|13
91-
|14
92-
|15
93-
""".stripMargin
94-
95-
val numbers = new RegexCoverageFilter(Nil).getExcludedLineNumbers(mockSourceFile(file))
96-
numbers === List(Range(4,9), Range(12,16))
97-
}
98-
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 RegexCoverageFilter(Nil).getExcludedLineNumbers(mockSourceFile(file))
119-
numbers === List(Range(4,9), Range(12,16))
39+
"getExcludedLineNumbers" - {
40+
"should exclude no lines if no magic comments are found" in {
41+
val file =
42+
"""1
43+
|2
44+
|3
45+
|4
46+
|5
47+
|6
48+
|7
49+
|8
50+
""".stripMargin
51+
52+
val numbers = new RegexCoverageFilter(Nil, Nil).getExcludedLineNumbers(mockSourceFile(file))
53+
numbers === List.empty
54+
}
55+
"should exclude lines between magic comments" in {
56+
val file =
57+
"""1
58+
|2
59+
|3
60+
| // $COVERAGE-OFF$
61+
|5
62+
|6
63+
|7
64+
|8
65+
| // $COVERAGE-ON$
66+
|10
67+
|11
68+
| // $COVERAGE-OFF$
69+
|13
70+
| // $COVERAGE-ON$
71+
|15
72+
|16
73+
""".stripMargin
74+
75+
val numbers = new RegexCoverageFilter(Nil, Nil).getExcludedLineNumbers(mockSourceFile(file))
76+
numbers === List(Range(4, 9), Range(12, 14))
77+
}
78+
"should exclude all lines after an upaired magic comment" in {
79+
val file =
80+
"""1
81+
|2
82+
|3
83+
| // $COVERAGE-OFF$
84+
|5
85+
|6
86+
|7
87+
|8
88+
| // $COVERAGE-ON$
89+
|10
90+
|11
91+
| // $COVERAGE-OFF$
92+
|13
93+
|14
94+
|15
95+
""".stripMargin
96+
97+
val numbers = new RegexCoverageFilter(Nil, Nil).getExcludedLineNumbers(mockSourceFile(file))
98+
numbers === List(Range(4, 9), Range(12, 16))
99+
}
100+
"should allow text comments on the same line as the markers" in {
101+
val file =
102+
"""1
103+
|2
104+
|3
105+
| // $COVERAGE-OFF$ because the next lines are boring
106+
|5
107+
|6
108+
|7
109+
|8
110+
| // $COVERAGE-ON$ resume coverage here
111+
|10
112+
|11
113+
| // $COVERAGE-OFF$ but ignore this bit
114+
|13
115+
|14
116+
|15
117+
""".stripMargin
118+
119+
val numbers = new RegexCoverageFilter(Nil, Nil).getExcludedLineNumbers(mockSourceFile(file))
120+
numbers === List(Range(4, 9), Range(12, 16))
121+
}
120122
}
121123

122124
private def mockSourceFile(contents: String): SourceFile = {

0 commit comments

Comments
 (0)