|
1 | 1 | package scoverage |
2 | 2 |
|
3 | | -import org.scalatest.FlatSpec |
4 | | -import scala.reflect.internal.util.{NoFile, BatchSourceFile, SourceFile} |
| 3 | +import org.scalatest.FreeSpec |
5 | 4 |
|
6 | | -class RegexCoverageFilterTest extends FlatSpec { |
| 5 | +import scala.reflect.internal.util.{BatchSourceFile, NoFile, SourceFile} |
7 | 6 |
|
8 | | - "isClassIncluded" should "return true for empty excludes" in { |
9 | | - assert(new RegexCoverageFilter(Nil).isClassIncluded("x")) |
10 | | - } |
| 7 | +class RegexCoverageFilterTest extends FreeSpec { |
11 | 8 |
|
12 | | - "isClassIncluded" should "not crash for empty input" in { |
13 | | - assert(new RegexCoverageFilter(Nil).isClassIncluded("")) |
14 | | - } |
| 9 | + "isClassIncluded" - { |
15 | 10 |
|
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 | + } |
19 | 14 |
|
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 | + } |
23 | 18 |
|
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 | + } |
27 | 22 |
|
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 | + } |
31 | 26 |
|
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 | + } |
35 | 30 |
|
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 | + } |
51 | 34 |
|
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 | + } |
74 | 38 | } |
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 | + } |
120 | 122 | } |
121 | 123 |
|
122 | 124 | private def mockSourceFile(contents: String): SourceFile = { |
|
0 commit comments