Skip to content
Merged
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ You can find instructions on how to apply the plugin at http://plugins.gradle.or

`gradle checkScoverage` will automatically invoke `reportScoverage` but it won't generate aggregated reports.
In order to check coverage of aggregated reports one should use `gradle checkScoverage aggregateScoverage`.

**Note:** The plugin is not compatible with composite builds. For more information, see [the relevant issue](https://github.com/scoverage/gradle-scoverage/issues/98).

### Configuration

Expand Down
35 changes: 24 additions & 11 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ apply plugin: 'groovy'
sourceCompatibility = '1.8'
targetCompatibility = '1.8'


dependencies {
compileOnly "org.scoverage:scalac-scoverage-plugin_2.12:1.4.1"
implementation group: 'commons-io', name: 'commons-io', version: '2.6'
Expand All @@ -58,39 +59,51 @@ dependencies {
sourceSets {
functionalTest {
java.srcDir file('src/functionalTest/java')
resources.srcDir file('src/functionalTest/resources')
compileClasspath += sourceSets.main.output + configurations.testRuntimeClasspath
runtimeClasspath += output + compileClasspath
compileClasspath += sourceSets.main.output
runtimeClasspath += sourceSets.main.output
}
crossScalaVersionTest {
java.srcDir file('src/crossScalaVersionTest/java')
compileClasspath += sourceSets.main.output + sourceSets.functionalTest.output
runtimeClasspath += sourceSets.main.output + sourceSets.functionalTest.output
}
}

task crossScalaVersionFunctionalTest(type: Test) {
configurations {
functionalTestImplementation.extendsFrom testImplementation
functionalTestRuntimeOnly.extendsFrom testRuntimeOnly

crossScalaVersionTestImplementation.extendsFrom testImplementation
crossScalaVersionTestRuntimeOnly.extendsFrom testRuntimeOnly
}

task crossScalaVersionTest(type: Test) {
description = 'Runs the cross scala version functional test.'
group = 'verification'
testClassesDirs = sourceSets.functionalTest.output.classesDirs
classpath = sourceSets.functionalTest.runtimeClasspath
include "**/ScalaMultiModuleCrossVersionTest.*"
testClassesDirs = sourceSets.crossScalaVersionTest.output
classpath = sourceSets.crossScalaVersionTest.runtimeClasspath
forkEvery = 1 // crucial to run every test in its own JVM

testLogging.showStandardStreams = true

mustRunAfter test
}
check.dependsOn crossScalaVersionTest

task functionalTest(type: Test) {
description = 'Runs the functional tests.'
group = 'verification'
testClassesDirs = sourceSets.functionalTest.output.classesDirs
testClassesDirs = sourceSets.functionalTest.output
classpath = sourceSets.functionalTest.runtimeClasspath
exclude "**/ScalaMultiModuleCrossVersionTest.*"

testLogging.showStandardStreams = true

dependsOn crossScalaVersionFunctionalTest
mustRunAfter crossScalaVersionTest
}
check.dependsOn functionalTest

gradlePlugin {
testSourceSets sourceSets.functionalTest
testSourceSets sourceSets.functionalTest, sourceSets.crossScalaVersionTest
}

task groovydocJar(type: Jar, dependsOn: groovydoc) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package org.scoverage;

public class Scala211Test extends ScalaVersionTest {
public Scala211Test() {
super("2_11");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package org.scoverage;

public class Scala212Test extends ScalaVersionTest {
public Scala212Test() {
super("2_12");
}
}
15 changes: 15 additions & 0 deletions src/crossScalaVersionTest/java/org/scoverage/Scala213Test.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package org.scoverage;

import org.junit.Ignore;

/**
* Tests is currently ignored as support for Scala 2.13 is not available yet.
*
* @see <a href="https://github.com/scoverage/gradle-scoverage/issues/106">Issue #106</a>.
*/
@Ignore
public class Scala213Test extends ScalaVersionTest {
public Scala213Test() {
super("2_13");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package org.scoverage;

import org.junit.Assert;
import org.junit.Test;
import org.junit.jupiter.api.Tag;
import org.junit.runner.RunWith;
import org.junit.runners.Suite;
import org.scoverage.ScoverageFunctionalTest;
import org.scoverage.ScoveragePlugin;

import java.io.File;

public class ScalaCrossVersionAggregationTest extends ScoverageFunctionalTest {

public ScalaCrossVersionAggregationTest() {
super("scala-multi-module-cross-version");
}

@Test
public void checkAndAggregateAll() throws Exception {

AssertableBuildResult result = run("clean", ScoveragePlugin.getCHECK_NAME(),
ScoveragePlugin.getAGGREGATE_NAME());

result.assertTaskSkipped(ScoveragePlugin.getREPORT_NAME());
result.assertTaskSucceeded("2_11:" + ScoveragePlugin.getREPORT_NAME());
result.assertTaskSucceeded("2_12:" + ScoveragePlugin.getREPORT_NAME());
result.assertTaskSucceeded("2_13:" + ScoveragePlugin.getREPORT_NAME());
result.assertTaskSucceeded(ScoveragePlugin.getCHECK_NAME());
result.assertTaskSucceeded("2_11:" + ScoveragePlugin.getCHECK_NAME());
result.assertTaskSucceeded("2_12:" + ScoveragePlugin.getCHECK_NAME());
result.assertTaskSucceeded("2_13:" + ScoveragePlugin.getCHECK_NAME());
result.assertTaskSucceeded(ScoveragePlugin.getAGGREGATE_NAME());

assertAggregationFilesExist();
assertCoverage(100.0);
}

private void assertAggregationFilesExist() {

Assert.assertTrue(resolve(reportDir(), "index.html").exists());
Assert.assertTrue(resolve(reportDir(), "2_11/src/main/scala/org/hello/World2_11.scala.html").exists());
Assert.assertTrue(resolve(reportDir(), "2_12/src/main/scala/org/hello/World2_12.scala.html").exists());
Assert.assertTrue(resolve(reportDir(), "2_13/src/main/scala/org/hello/World2_13.scala.html").exists());
}
}
35 changes: 35 additions & 0 deletions src/crossScalaVersionTest/java/org/scoverage/ScalaVersionTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package org.scoverage;

import org.junit.Assert;
import org.junit.Test;
import org.junit.jupiter.api.Tag;
import org.scoverage.ScoverageFunctionalTest;
import org.scoverage.ScoveragePlugin;

import java.io.File;

/**
* This abstract class is used to test each scala version in an individual class.
* It is crucial that each test will be separated into its own class,
* as this is the only way to run these tests in separate JVM processes (via `forkEvery` gradle configuration).
*/
public abstract class ScalaVersionTest extends ScoverageFunctionalTest {

private final String scalaVersion;

public ScalaVersionTest(String scalaVersion) {
super("scala-multi-module-cross-version");
this.scalaVersion = scalaVersion;
}

@Test
public void report() throws Exception {

AssertableBuildResult result = run("clean", ":" + scalaVersion + ":" + ScoveragePlugin.getREPORT_NAME());
result.assertTaskSucceeded(scalaVersion + ":" + ScoveragePlugin.getREPORT_NAME());

File reportDir = reportDir(projectDir().toPath().resolve(scalaVersion).toFile());
Assert.assertTrue(resolve(reportDir, "index.html").exists());
Assert.assertTrue(resolve(reportDir, "src/main/scala/org/hello/World" + scalaVersion + ".scala.html").exists());
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package org.hello

class World211 {
class World2_11 {

def foo(): String = {
val s = "2" + "11"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import org.scalatest.FunSuite
import org.scalatest.junit.JUnitRunner

@RunWith(classOf[JUnitRunner])
class World212Suite extends FunSuite {
class World2_11Suite extends FunSuite {

test("foo") {
new World213().foo()
new World2_11().foo()
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package org.hello

class World213 {
class World2_12 {

def foo(): String = {
val s = "2" + "12"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import org.scalatest.FunSuite
import org.scalatest.junit.JUnitRunner

@RunWith(classOf[JUnitRunner])
class World211Suite extends FunSuite {
class World2_12Suite extends FunSuite {

test("foo") {
new World211().foo()
new World2_12().foo()
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package org.hello

class World212 {
class World2_13 {

def foo(): String = {
val s = "2" + "12"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ import org.scalatest.junit.JUnitRunner
class World212Suite extends FunSuite {

test("foo") {
new World212().foo()
new World2_13().foo()
}
}

This file was deleted.

Loading