Skip to content

Commit

Permalink
Add support for -coverage-exclude-classlikes and -coverage-exclude-fi…
Browse files Browse the repository at this point in the history
…les for Scala 3
  • Loading branch information
msigmond committed Jun 22, 2024
1 parent b276e62 commit 43732c1
Show file tree
Hide file tree
Showing 8 changed files with 112 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ public void reportScoverageWithoutNormalCompilationAndWithExcludedClasses() thro
Assert.assertFalse(resolve(buildDir(), "classes/scala/scoverage/org/hello/World.class").exists());
}

private void assertReportFilesExist() {
protected void assertReportFilesExist() {

Assert.assertTrue(resolve(reportDir(), "index.html").exists());
Assert.assertTrue(resolve(reportDir(), "org/hello/World.scala.html").exists());
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package org.scoverage;

import org.junit.Assert;

import java.util.List;

public class ScalaSingleModuleTestScala3 extends ScalaSingleModuleTest {

@Override
protected List<String> getVersionAgruments() {
return ScalaVersionArguments.version3;
}

@Override
public void checkScoverage() throws Exception {
AssertableBuildResult result = run("clean", ScoveragePlugin.getCHECK_NAME());

result.assertTaskSucceeded(ScoveragePlugin.getCOMPILE_NAME());
result.assertTaskSucceeded(ScoveragePlugin.getREPORT_NAME());
result.assertTaskSucceeded(ScoveragePlugin.getCHECK_NAME());
result.assertTaskDoesntExist(ScoveragePlugin.getAGGREGATE_NAME());

assertReportFilesExist();
assertCoverage(66.67);
}

@Override
public void reportScoverageWithExcludedClasses() throws Exception {
AssertableBuildResult result = run("clean", ScoveragePlugin.getREPORT_NAME(),
"-PexcludedFile=.*");

result.assertTaskSucceeded(ScoveragePlugin.getCOMPILE_NAME());
result.assertTaskSucceeded(ScoveragePlugin.getREPORT_NAME());
result.assertTaskDoesntExist(ScoveragePlugin.getCHECK_NAME());
result.assertTaskDoesntExist(ScoveragePlugin.getAGGREGATE_NAME());

Assert.assertTrue(resolve(reportDir(), "index.html").exists());
Assert.assertFalse(resolve(reportDir(), "org/hello/World.scala.html").exists());
assertCoverage(100.0); // coverage is 100 since no classes are covered

// compiled class should exist in the default classes directory, but not in scoverage
Assert.assertTrue(resolve(buildDir(), "classes/scala/main/org/hello/World.class").exists());
}

@Override
public void reportScoverageWithoutNormalCompilationAndWithExcludedClasses() throws Exception {
AssertableBuildResult result = run("clean", ScoveragePlugin.getREPORT_NAME(),
"-PexcludedFile=.*", "-P" + ScoveragePlugin.getSCOVERAGE_COMPILE_ONLY_PROPERTY());

Assert.assertTrue(resolve(reportDir(), "index.html").exists());
Assert.assertFalse(resolve(reportDir(), "org/hello/World.scala.html").exists());
assertCoverage(100.0); // coverage is 100 since no classes are covered

// compiled class should exist in the default classes directory, but not in scoverage
Assert.assertTrue(resolve(buildDir(), "classes/scala/main/org/hello/World.class").exists());
}
}
24 changes: 24 additions & 0 deletions src/functionalTest/java/org/scoverage/ScalaVersionArguments.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package org.scoverage;

import java.util.Arrays;
import java.util.List;

public interface ScalaVersionArguments {
List<String> version2 = Arrays.asList(
"-PscalaVersionMajor=2",
"-PscalaVersionMinor=13",
"-PscalaVersionBuild=14",
"-PjunitVersion=5.3.2",
"-PjunitPlatformVersion=1.3.2",
"-PscalatestVersion=3.2.16"
);

List<String> version3 = Arrays.asList(
"-PscalaVersionMajor=3",
"-PscalaVersionMinor=4",
"-PscalaVersionBuild=2",
"-PjunitVersion=5.3.2",
"-PjunitPlatformVersion=1.3.2",
"-PscalatestVersion=3.2.16"
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -115,16 +115,14 @@ private Double coverage(File reportDir, CoverageType coverageType) throws IOExce
return coverageType.normalize(rawValue) * 100.0;
}

protected List<String> getVersionAgruments() {
return ScalaVersionArguments.version2;
}

private void configureArguments(String... arguments) {

List<String> fullArguments = new ArrayList<>();
List<String> fullArguments = new ArrayList<>(getVersionAgruments());

fullArguments.add("-PscalaVersionMajor=2");
fullArguments.add("-PscalaVersionMinor=13");
fullArguments.add("-PscalaVersionBuild=14");
fullArguments.add("-PjunitVersion=5.3.2");
fullArguments.add("-PjunitPlatformVersion=1.3.2");
fullArguments.add("-PscalatestVersion=3.0.8");
if (Boolean.parseBoolean(System.getProperty("failOnWarning"))) {
fullArguments.add("--warning-mode=fail");
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,20 @@ apply plugin: 'java'
apply plugin: 'scala'

dependencies {
implementation group: 'org.scala-lang', name: 'scala-library', version: "${scalaVersionMajor}.${scalaVersionMinor}.${scalaVersionBuild}"
if (project.getProperties().get("scalaVersionMajor").equals("2")) {
implementation group: 'org.scala-lang', name: 'scala-library', version: "${scalaVersionMajor}.${scalaVersionMinor}.${scalaVersionBuild}"

testImplementation group: 'org.scalatest', name: 'scalatest_2.13', version: scalatestVersion
testImplementation group: 'org.scalatestplus', name: 'junit-4-13_2.13', version: "${scalatestVersion}.0"
} else {
implementation group: 'org.scala-lang', name: 'scala3-library_3', version: "${scalaVersionMajor}.${scalaVersionMinor}.${scalaVersionBuild}"

testImplementation group: 'org.scalatest', name: 'scalatest_3', version: scalatestVersion
testImplementation group: 'org.scalatestplus', name: 'junit-4-13_3', version: "${scalatestVersion}.0"
}

testRuntimeOnly group: 'org.junit.vintage', name: 'junit-vintage-engine', version: junitVersion
testImplementation group: 'org.junit.platform', name: 'junit-platform-runner', version: junitPlatformVersion

testImplementation group: 'org.scalatest', name: "scalatest_${scalaVersionMajor}.${scalaVersionMinor}", version: scalatestVersion
}

test {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package org.hello

import org.junit.runner.RunWith
import org.scalatest.FunSuite
import org.scalatest.junit.JUnitRunner
import org.scalatest.funsuite._
import org.scalatestplus.junit.JUnitRunner

@RunWith(classOf[JUnitRunner])
class TestNothingSuite extends FunSuite {
class TestNothingSuite extends AnyFunSuite {

test("nothing") {
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package org.hello

import org.junit.runner.RunWith
import org.scalatest.FunSuite
import org.scalatest.junit.JUnitRunner
import org.scalatest.funsuite._
import org.scalatestplus.junit.JUnitRunner

@RunWith(classOf[JUnitRunner])
class WorldSuite extends FunSuite {
class WorldSuite extends AnyFunSuite {

test("foo") {
new World().foo()
Expand Down
8 changes: 8 additions & 0 deletions src/main/groovy/org/scoverage/ScoveragePlugin.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,14 @@ class ScoveragePlugin implements Plugin<PluginAware> {
} else {
parameters.add("-sourceroot:${project.rootDir.absolutePath}".toString())
parameters.add("-coverage-out:${extension.dataDir.get().absolutePath}".toString())
if (extension.excludedPackages.get()) {
def packages = extension.excludedPackages.get().join(',')
parameters.add("-coverage-exclude-classlikes:$packages".toString())
}
if (extension.excludedFiles.get()) {
def packages = extension.excludedFiles.get().join(';')
parameters.add("-coverage-exclude-files:$packages".toString())
}
scalaCompileOptions.additionalParameters = parameters
}
}
Expand Down

0 comments on commit 43732c1

Please sign in to comment.