Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support file and package exclusions for Scala 3.4.2+ #237

Merged
merged 1 commit into from
May 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -325,8 +325,10 @@ If you want to customize plugin's configuration parameters used by compilation s
</project>
```

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).
Read [SBT SCoverage Plugin documentation](https://github.com/scoverage/sbt-scoverage) for more information about
[excludedPackages and excludedFiles](https://github.com/scoverage/sbt-scoverage?tab=readme-ov-file#exclude-classes-and-packages-and-files).

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

### Checking minimum test coverage level

Expand Down
2 changes: 1 addition & 1 deletion src/it/integration_tests_parent/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

<compiler.plugin.version>3.11.0</compiler.plugin.version>
<surefire.plugin.version>3.1.2</surefire.plugin.version>
<scala.plugin.version>4.8.1</scala.plugin.version>
<scala.plugin.version>4.9.1</scala.plugin.version>
<scalatest.plugin.version>2.0.0</scalatest.plugin.version>
<project-info-reports.plugin.version>3.5.0</project-info-reports.plugin.version>
<site.plugin.version>3.12.1</site.plugin.version>
Expand Down
1 change: 1 addition & 0 deletions src/it/test_exclusion_Scala3_4_1/invoker.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
invoker.goals=clean verify site -e -ntp
51 changes: 51 additions & 0 deletions src/it/test_exclusion_Scala3_4_1/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<?xml version="1.0" encoding="UTF-8"?>

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>it.scoverage-maven-plugin</groupId>
<artifactId>integration_tests_parent</artifactId>
<version>1.0-SNAPSHOT</version>
<relativePath>../integration_tests_parent/pom.xml</relativePath>
</parent>

<artifactId>test_exclusion</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<name>Test Scoverage exclusion</name>
<description>Test Scoverage exclusion</description>

<properties>
<scala.compat.version>3</scala.compat.version>
<scala.version>3.4.1</scala.version>
<scala.library.artifact.id>scala3-library_3</scala.library.artifact.id>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
</plugin>
<plugin>
<groupId>net.alchim31.maven</groupId>
<artifactId>scala-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.scalatest</groupId>
<artifactId>scalatest-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>@project.groupId@</groupId>
<artifactId>@project.artifactId@</artifactId>
<configuration>
<excludedPackages>.*package02.*;.*package05</excludedPackages>
<excludedFiles>.*Package03HelloService.*;.*Package03ByeService</excludedFiles>
</configuration>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package org.package01

object Package01HelloService {

// gonna be included in coverage report
def hello: String = "Hello from package01"

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// gonna be excluded from coverage report by package exclusion
package org.package02.nested02

object ImGonnaBeExcludedCauseImInPackage02Nested02 {

def hello: String = "Hello from package02.nested02"

}

object SameStoryBro {

def hello: String = "Hello from package02.nested02 again"

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// gonna be excluded from coverage report by package exclusion
package org.package02

object ImGonnaBeExcludedCauseImInPackage02 {

def hello: String = "Hello from package02"

}

object SameStoryBro {

def hello: String = "Hello from package02 again"

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package org.package03

object Package03ByeService {

// gonna be excluded from coverage report by file exclusion
def bye: String = "Bye from package03"

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package org.package03

object Package03HelloService1 {

// gonna be excluded from coverage report by file exclusion
def hello: String = "Hello from package03 service 1"

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package org.package03

object Package03HelloService2 {

// gonna be excluded from coverage report by file exclusion
def hello: String = "Hello from package03 service 2"

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// gonna be excluded from coverage report by package exclusion
package org.package05

object ImGonnaBeExcludedCauseImInPackage05 {

def hello: String = "Hello from package05"

}

object SameStoryBro {

def hello: String = "Hello from package05 again"

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package org.package01

import org.scalatest.wordspec.AnyWordSpec

class Package01HelloServiceTest extends AnyWordSpec {

"Package01HelloService" should {
"say hello" in {
assert(Package01HelloService.hello == "Hello from package01")
}
}
}
14 changes: 14 additions & 0 deletions src/it/test_exclusion_Scala3_4_1/validate.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
try {

def logFile = new File(basedir, "build.log")
def lines = logFile.readLines()
assert lines.contains("[WARNING] Package exclusion is supported since Scala 3.4.2")
assert lines.contains("[WARNING] File exclusion is supported since Scala 3.4.2")
assert lines.contains("[INFO] Statement coverage.: 10.00%")

return true

} catch (Throwable e) {
e.printStackTrace()
return false
}
1 change: 1 addition & 0 deletions src/it/test_exclusion_Scala3_4_2/invoker.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
invoker.goals=clean verify site -e -ntp
51 changes: 51 additions & 0 deletions src/it/test_exclusion_Scala3_4_2/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<?xml version="1.0" encoding="UTF-8"?>

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>it.scoverage-maven-plugin</groupId>
<artifactId>integration_tests_parent</artifactId>
<version>1.0-SNAPSHOT</version>
<relativePath>../integration_tests_parent/pom.xml</relativePath>
</parent>

<artifactId>test_exclusion</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<name>Test Scoverage exclusion</name>
<description>Test Scoverage exclusion</description>

<properties>
<scala.compat.version>3</scala.compat.version>
<scala.version>3.4.2</scala.version>
<scala.library.artifact.id>scala3-library_3</scala.library.artifact.id>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
</plugin>
<plugin>
<groupId>net.alchim31.maven</groupId>
<artifactId>scala-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.scalatest</groupId>
<artifactId>scalatest-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>@project.groupId@</groupId>
<artifactId>@project.artifactId@</artifactId>
<configuration>
<excludedPackages>.*package02.*;.*package05</excludedPackages>
<excludedFiles>.*Package03HelloService.*;.*Package03ByeService</excludedFiles>
</configuration>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package org.package01

object Package01HelloService {

// gonna be included in coverage report
def hello: String = "Hello from package01"

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// gonna be excluded from coverage report by package exclusion
package org.package02.nested02

object ImGonnaBeExcludedCauseImInPackage02Nested02 {

def hello: String = "Hello from package02.nested02"

}

object SameStoryBro {

def hello: String = "Hello from package02.nested02 again"

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// gonna be excluded from coverage report by package exclusion
package org.package02

object ImGonnaBeExcludedCauseImInPackage02 {

def hello: String = "Hello from package02"

}

object SameStoryBro {

def hello: String = "Hello from package02 again"

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package org.package03

object Package03ByeService {

// gonna be excluded from coverage report by file exclusion
def bye: String = "Bye from package03"

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package org.package03

object Package03HelloService1 {

// gonna be excluded from coverage report by file exclusion
def hello: String = "Hello from package03 service 1"

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package org.package03

object Package03HelloService2 {

// gonna be excluded from coverage report by file exclusion
def hello: String = "Hello from package03 service 2"

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// gonna be excluded from coverage report by package exclusion
package org.package05

object ImGonnaBeExcludedCauseImInPackage05 {

def hello: String = "Hello from package05"

}

object SameStoryBro {

def hello: String = "Hello from package05 again"

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package org.package01

import org.scalatest.wordspec.AnyWordSpec

class Package01HelloServiceTest extends AnyWordSpec {

"Package01HelloService" should {
"say hello" in {
assert(Package01HelloService.hello == "Hello from package01")
}
}
}
19 changes: 19 additions & 0 deletions src/it/test_exclusion_Scala3_4_2/validate.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
try {

def logFile = new File(basedir, "build.log")
def lines = logFile.readLines()
assert lines.contains("[INFO] Statement coverage.: 100.00%")
assert lines.contains("[INFO] Branch coverage....: 100.00%")

def scoverageFile = new File(basedir, "target/scoverage.xml")
assert scoverageFile.exists()

def reportFile = new File(basedir, "target/site/scoverage/index.html")
assert reportFile.exists()

return true

} catch (Throwable e) {
e.printStackTrace()
return false
}
Loading