Skip to content

Commit 2f24be9

Browse files
committed
Support file and package exclusions for Scala 3.4.2+
1 parent c332d57 commit 2f24be9

25 files changed

+341
-10
lines changed

README.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -325,8 +325,10 @@ If you want to customize plugin's configuration parameters used by compilation s
325325
</project>
326326
```
327327

328-
Read [SBT SCoverage Plugin documentation](https://github.com/scoverage/sbt-scoverage) for more information about [highlighting](https://github.com/scoverage/sbt-scoverage#highlighting) and [excludedPackages](https://github.com/scoverage/sbt-scoverage#exclude-classes-and-packages).
328+
Read [SBT SCoverage Plugin documentation](https://github.com/scoverage/sbt-scoverage) for more information about
329+
[excludedPackages and excludedFiles](https://github.com/scoverage/sbt-scoverage?tab=readme-ov-file#exclude-classes-and-packages-and-files).
329330

331+
File and package exclusions are supported for Scala 2 and Scala 3 since version `3.4.2`.
330332

331333
### Checking minimum test coverage level
332334

src/it/integration_tests_parent/pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919
<compiler.plugin.version>3.11.0</compiler.plugin.version>
2020
<surefire.plugin.version>3.1.2</surefire.plugin.version>
21-
<scala.plugin.version>4.8.1</scala.plugin.version>
21+
<scala.plugin.version>4.9.1</scala.plugin.version>
2222
<scalatest.plugin.version>2.0.0</scalatest.plugin.version>
2323
<project-info-reports.plugin.version>3.5.0</project-info-reports.plugin.version>
2424
<site.plugin.version>3.12.1</site.plugin.version>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
invoker.goals=clean verify site -e -ntp
+51
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
3+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
5+
<modelVersion>4.0.0</modelVersion>
6+
7+
<parent>
8+
<groupId>it.scoverage-maven-plugin</groupId>
9+
<artifactId>integration_tests_parent</artifactId>
10+
<version>1.0-SNAPSHOT</version>
11+
<relativePath>../integration_tests_parent/pom.xml</relativePath>
12+
</parent>
13+
14+
<artifactId>test_exclusion</artifactId>
15+
<version>1.0-SNAPSHOT</version>
16+
<packaging>jar</packaging>
17+
<name>Test Scoverage exclusion</name>
18+
<description>Test Scoverage exclusion</description>
19+
20+
<properties>
21+
<scala.compat.version>3</scala.compat.version>
22+
<scala.version>3.4.1</scala.version>
23+
<scala.library.artifact.id>scala3-library_3</scala.library.artifact.id>
24+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
25+
</properties>
26+
27+
<build>
28+
<plugins>
29+
<plugin>
30+
<groupId>org.apache.maven.plugins</groupId>
31+
<artifactId>maven-compiler-plugin</artifactId>
32+
</plugin>
33+
<plugin>
34+
<groupId>net.alchim31.maven</groupId>
35+
<artifactId>scala-maven-plugin</artifactId>
36+
</plugin>
37+
<plugin>
38+
<groupId>org.scalatest</groupId>
39+
<artifactId>scalatest-maven-plugin</artifactId>
40+
</plugin>
41+
<plugin>
42+
<groupId>@project.groupId@</groupId>
43+
<artifactId>@project.artifactId@</artifactId>
44+
<configuration>
45+
<excludedPackages>.*package02.*;.*package05</excludedPackages>
46+
<excludedFiles>.*Package03HelloService.*;.*Package03ByeService</excludedFiles>
47+
</configuration>
48+
</plugin>
49+
</plugins>
50+
</build>
51+
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package org.package01
2+
3+
object Package01HelloService {
4+
5+
// gonna be included in coverage report
6+
def hello: String = "Hello from package01"
7+
8+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// gonna be excluded from coverage report by package exclusion
2+
package org.package02.nested02
3+
4+
object ImGonnaBeExcludedCauseImInPackage02Nested02 {
5+
6+
def hello: String = "Hello from package02.nested02"
7+
8+
}
9+
10+
object SameStoryBro {
11+
12+
def hello: String = "Hello from package02.nested02 again"
13+
14+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// gonna be excluded from coverage report by package exclusion
2+
package org.package02
3+
4+
object ImGonnaBeExcludedCauseImInPackage02 {
5+
6+
def hello: String = "Hello from package02"
7+
8+
}
9+
10+
object SameStoryBro {
11+
12+
def hello: String = "Hello from package02 again"
13+
14+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package org.package03
2+
3+
object Package03ByeService {
4+
5+
// gonna be excluded from coverage report by file exclusion
6+
def bye: String = "Bye from package03"
7+
8+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package org.package03
2+
3+
object Package03HelloService1 {
4+
5+
// gonna be excluded from coverage report by file exclusion
6+
def hello: String = "Hello from package03 service 1"
7+
8+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package org.package03
2+
3+
object Package03HelloService2 {
4+
5+
// gonna be excluded from coverage report by file exclusion
6+
def hello: String = "Hello from package03 service 2"
7+
8+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// gonna be excluded from coverage report by package exclusion
2+
package org.package05
3+
4+
object ImGonnaBeExcludedCauseImInPackage05 {
5+
6+
def hello: String = "Hello from package05"
7+
8+
}
9+
10+
object SameStoryBro {
11+
12+
def hello: String = "Hello from package05 again"
13+
14+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package org.package01
2+
3+
import org.scalatest.wordspec.AnyWordSpec
4+
5+
class Package01HelloServiceTest extends AnyWordSpec {
6+
7+
"Package01HelloService" should {
8+
"say hello" in {
9+
assert(Package01HelloService.hello == "Hello from package01")
10+
}
11+
}
12+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
try {
2+
3+
def logFile = new File(basedir, "build.log")
4+
def lines = logFile.readLines()
5+
assert lines.contains("[WARNING] Package exclusion is supported since Scala 3.4.2")
6+
assert lines.contains("[WARNING] File exclusion is supported since Scala 3.4.2")
7+
assert lines.contains("[INFO] Statement coverage.: 10.00%")
8+
9+
return true
10+
11+
} catch (Throwable e) {
12+
e.printStackTrace()
13+
return false
14+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
invoker.goals=clean verify site -e -ntp
+51
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
3+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
5+
<modelVersion>4.0.0</modelVersion>
6+
7+
<parent>
8+
<groupId>it.scoverage-maven-plugin</groupId>
9+
<artifactId>integration_tests_parent</artifactId>
10+
<version>1.0-SNAPSHOT</version>
11+
<relativePath>../integration_tests_parent/pom.xml</relativePath>
12+
</parent>
13+
14+
<artifactId>test_exclusion</artifactId>
15+
<version>1.0-SNAPSHOT</version>
16+
<packaging>jar</packaging>
17+
<name>Test Scoverage exclusion</name>
18+
<description>Test Scoverage exclusion</description>
19+
20+
<properties>
21+
<scala.compat.version>3</scala.compat.version>
22+
<scala.version>3.4.2</scala.version>
23+
<scala.library.artifact.id>scala3-library_3</scala.library.artifact.id>
24+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
25+
</properties>
26+
27+
<build>
28+
<plugins>
29+
<plugin>
30+
<groupId>org.apache.maven.plugins</groupId>
31+
<artifactId>maven-compiler-plugin</artifactId>
32+
</plugin>
33+
<plugin>
34+
<groupId>net.alchim31.maven</groupId>
35+
<artifactId>scala-maven-plugin</artifactId>
36+
</plugin>
37+
<plugin>
38+
<groupId>org.scalatest</groupId>
39+
<artifactId>scalatest-maven-plugin</artifactId>
40+
</plugin>
41+
<plugin>
42+
<groupId>@project.groupId@</groupId>
43+
<artifactId>@project.artifactId@</artifactId>
44+
<configuration>
45+
<excludedPackages>.*package02.*;.*package05</excludedPackages>
46+
<excludedFiles>.*Package03HelloService.*;.*Package03ByeService</excludedFiles>
47+
</configuration>
48+
</plugin>
49+
</plugins>
50+
</build>
51+
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package org.package01
2+
3+
object Package01HelloService {
4+
5+
// gonna be included in coverage report
6+
def hello: String = "Hello from package01"
7+
8+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// gonna be excluded from coverage report by package exclusion
2+
package org.package02.nested02
3+
4+
object ImGonnaBeExcludedCauseImInPackage02Nested02 {
5+
6+
def hello: String = "Hello from package02.nested02"
7+
8+
}
9+
10+
object SameStoryBro {
11+
12+
def hello: String = "Hello from package02.nested02 again"
13+
14+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// gonna be excluded from coverage report by package exclusion
2+
package org.package02
3+
4+
object ImGonnaBeExcludedCauseImInPackage02 {
5+
6+
def hello: String = "Hello from package02"
7+
8+
}
9+
10+
object SameStoryBro {
11+
12+
def hello: String = "Hello from package02 again"
13+
14+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package org.package03
2+
3+
object Package03ByeService {
4+
5+
// gonna be excluded from coverage report by file exclusion
6+
def bye: String = "Bye from package03"
7+
8+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package org.package03
2+
3+
object Package03HelloService1 {
4+
5+
// gonna be excluded from coverage report by file exclusion
6+
def hello: String = "Hello from package03 service 1"
7+
8+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package org.package03
2+
3+
object Package03HelloService2 {
4+
5+
// gonna be excluded from coverage report by file exclusion
6+
def hello: String = "Hello from package03 service 2"
7+
8+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// gonna be excluded from coverage report by package exclusion
2+
package org.package05
3+
4+
object ImGonnaBeExcludedCauseImInPackage05 {
5+
6+
def hello: String = "Hello from package05"
7+
8+
}
9+
10+
object SameStoryBro {
11+
12+
def hello: String = "Hello from package05 again"
13+
14+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package org.package01
2+
3+
import org.scalatest.wordspec.AnyWordSpec
4+
5+
class Package01HelloServiceTest extends AnyWordSpec {
6+
7+
"Package01HelloService" should {
8+
"say hello" in {
9+
assert(Package01HelloService.hello == "Hello from package01")
10+
}
11+
}
12+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
try {
2+
3+
def logFile = new File(basedir, "build.log")
4+
def lines = logFile.readLines()
5+
assert lines.contains("[INFO] Statement coverage.: 100.00%")
6+
assert lines.contains("[INFO] Branch coverage....: 100.00%")
7+
8+
def scoverageFile = new File(basedir, "target/scoverage.xml")
9+
assert scoverageFile.exists()
10+
11+
def reportFile = new File(basedir, "target/site/scoverage/index.html")
12+
assert reportFile.exists()
13+
14+
return true
15+
16+
} catch (Throwable e) {
17+
e.printStackTrace()
18+
return false
19+
}

0 commit comments

Comments
 (0)