Skip to content
Open
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
2 changes: 1 addition & 1 deletion .github/workflows/gradle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,4 @@ jobs:
- name: Grant execute permission for gradlew
run: chmod +x gradlew
- name: Build with Gradle
run: ./gradlew --info --stacktrace check ${{ matrix.additional-check-args }}
run: ./gradlew --info --stacktrace --configuration-cache check ${{ matrix.additional-check-args }}
10 changes: 8 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@ You can find instructions on how to apply the plugin at http://plugins.gradle.or
1. `reportScoverage`: Produces XML and HTML reports for analysing test code coverage.

The plugin automatically creates a `report{Task name}Scoverage` task for each test task in your
Gradle build. The `reportScoverage` task will run all test tasks and you can use the individual
tasks to run only the desired tests. For example, to run only the unit tests and no other test
Gradle build. Coverage measurement runs via a companion `scoverage{Task name}` task so normal `test`
tasks are left unchanged. The `reportScoverage` task will run all scoverage test tasks and you can use
the individual tasks to run only the desired tests. For example, to run only the unit tests and no other test
tasks (e.g., integration tests), you can run `reportTestScoverage`.

2. `aggregateScoverage`: Aggregates coverage statistics in composite builds.
Expand All @@ -37,6 +38,11 @@ You can find instructions on how to apply the plugin at http://plugins.gradle.or
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 cache

The plugin supports Gradle's [configuration cache](https://docs.gradle.org/current/userguide/configuration_cache.html) on Gradle 9+.
Enable it with `--configuration-cache` or in `gradle.properties`.

### Configuration

Expand Down
5 changes: 5 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,11 @@ task functionalTest(type: Test) {
group = 'verification'
testClassesDirs = sourceSets.functionalTest.output
classpath = sourceSets.functionalTest.runtimeClasspath
forkEvery = 1

filter {
includeTestsMatching 'org.scoverage.*'
}

testLogging {
events 'passed', 'failed', 'skipped'
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package org.scoverage;

import org.junit.Test;

public class ConfigurationCacheMultiModuleTest extends ScoverageFunctionalTest {

public ConfigurationCacheMultiModuleTest() {
super("scala-multi-module");
}

@Test
public void checkScoverageStoresAndReusesConfigurationCache() throws Exception {

cleanProjectForConfigurationCache();

prepareConfigurationCacheRun(ScoveragePlugin.getCHECK_NAME());
AssertableBuildResult firstRun = buildPreparedConfigurationCacheRun();
firstRun.assertConfigurationCacheStored();

prepareConfigurationCacheRun(ScoveragePlugin.getCHECK_NAME());
AssertableBuildResult secondRun = buildPreparedConfigurationCacheRun();

secondRun.assertConfigurationCacheReused();
secondRun.assertTaskSucceeded(ScoveragePlugin.getCHECK_NAME());
secondRun.assertTaskSucceeded("a:" + ScoveragePlugin.getCHECK_NAME());
}
}
34 changes: 34 additions & 0 deletions src/functionalTest/java/org/scoverage/ConfigurationCacheTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package org.scoverage;

import org.junit.Test;

import java.util.List;

public class ConfigurationCacheTest extends ScoverageFunctionalTest {

public ConfigurationCacheTest() {
super("scala-single-module");
}

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

@Test
public void checkScoverageStoresAndReusesConfigurationCache() throws Exception {

cleanProjectForConfigurationCache();

prepareConfigurationCacheRun(ScoveragePlugin.getCHECK_NAME());
AssertableBuildResult firstRun = buildPreparedConfigurationCacheRun();
firstRun.assertConfigurationCacheStored();

prepareConfigurationCacheRun(ScoveragePlugin.getCHECK_NAME());
AssertableBuildResult secondRun = buildPreparedConfigurationCacheRun();

secondRun.assertConfigurationCacheReused();
secondRun.assertTaskSucceeded(ScoveragePlugin.getCHECK_NAME());
assertCoverage(50.0);
}
}
12 changes: 6 additions & 6 deletions src/functionalTest/java/org/scoverage/ScalaMultiModuleTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ public void checkAndAggregateScoverage() throws Exception {
public void checkScoverageWithoutCoverageInRoot() throws Exception {

AssertableBuildResult result = runAndFail("clean", ScoveragePlugin.getCHECK_NAME(),
"test",
ScoveragePlugin.scoverageTestTaskName("test"),
"--tests", "org.hello.TestNothingSuite",
"--tests", "org.hello.a.WorldASuite",
"--tests", "org.hello.b.WorldBSuite",
Expand All @@ -181,7 +181,7 @@ public void checkScoverageWithoutCoverageInRoot() throws Exception {
public void checkScoverageWithoutCoverageInA() throws Exception {

AssertableBuildResult result = runAndFail("clean", ScoveragePlugin.getCHECK_NAME(),
"test",
ScoveragePlugin.scoverageTestTaskName("test"),
"--tests", "org.hello.a.TestNothingASuite",
"--tests", "org.hello.WorldSuite",
"--tests", "org.hello.b.WorldBSuite",
Expand All @@ -198,8 +198,8 @@ public void checkScoverageWithoutCoverageInA() throws Exception {
public void checkScoverageWithoutNormalCompilationAndWithoutCoverageInCommon() throws Exception {

AssertableBuildResult result = runAndFail("clean",
":a:test",
":common:test", "--tests", "org.hello.common.TestNothingCommonSuite",
":a:" + ScoveragePlugin.scoverageTestTaskName("test"),
":common:" + ScoveragePlugin.scoverageTestTaskName("test"), "--tests", "org.hello.common.TestNothingCommonSuite",
"-P" + ScoveragePlugin.getSCOVERAGE_COMPILE_ONLY_PROPERTY(),
ScoveragePlugin.getCHECK_NAME());

Expand All @@ -215,7 +215,7 @@ public void checkAndAggregateScoverageWithoutCoverageInRoot() throws Exception {
// should pass as the check on the root is for the aggregation (which covers > 50%)

AssertableBuildResult result = run("clean", ScoveragePlugin.getCHECK_NAME(),
ScoveragePlugin.getAGGREGATE_NAME(), "test",
ScoveragePlugin.getAGGREGATE_NAME(), ScoveragePlugin.scoverageTestTaskName("test"),
"--tests", "org.hello.TestNothingSuite",
"--tests", "org.hello.a.WorldASuite",
"--tests", "org.hello.b.WorldBSuite",
Expand All @@ -239,7 +239,7 @@ public void checkAndAggregateScoverageWithoutCoverageInRoot() throws Exception {
public void checkAndAggregateScoverageWithoutCoverageInAll() throws Exception {

AssertableBuildResult result = runAndFail("clean", ScoveragePlugin.getCHECK_NAME(),
ScoveragePlugin.getAGGREGATE_NAME(), "test",
ScoveragePlugin.getAGGREGATE_NAME(), ScoveragePlugin.scoverageTestTaskName("test"),
"--tests", "org.hello.TestNothingSuite",
"--tests", "org.hello.a.TestNothingASuite",
"--tests", "org.hello.b.TestNothingBSuite",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,17 +118,17 @@ public void checkScoverageOnlyA() {
@Test
public void checkScoverageWithoutIntTests() {
AssertableBuildResult result = dryRun("clean", ScoveragePlugin.getCHECK_NAME(),
"-x", "intTest");
"-x", ScoveragePlugin.scoverageTestTaskName("intTest"));

result.assertTaskExists(ScoveragePlugin.getREPORT_NAME());
result.assertTaskExists("a:" + ScoveragePlugin.getREPORT_NAME());
result.assertTaskExists("b:" + ScoveragePlugin.getREPORT_NAME());
result.assertTaskExists("common:" + ScoveragePlugin.getREPORT_NAME());
result.assertTaskDoesntExist("intTest");
result.assertTaskDoesntExist(ScoveragePlugin.scoverageTestTaskName("intTest"));
result.assertTaskExists("reportIntTestScoverage");
result.assertTaskDoesntExist("a:intTest");
result.assertTaskDoesntExist("b:intTest");
result.assertTaskDoesntExist("common:intTest");
result.assertTaskDoesntExist("a:" + ScoveragePlugin.scoverageTestTaskName("intTest"));
result.assertTaskDoesntExist("b:" + ScoveragePlugin.scoverageTestTaskName("intTest"));
result.assertTaskDoesntExist("common:" + ScoveragePlugin.scoverageTestTaskName("intTest"));
result.assertTaskExists("a:reportIntTestScoverage");
result.assertTaskExists("b:reportIntTestScoverage");
result.assertTaskExists("common:reportIntTestScoverage");
Expand Down Expand Up @@ -158,12 +158,12 @@ public void checkAndAggregateScoverage() throws Exception {
public void checkScoverageWithoutCoverageInRoot() throws Exception {

AssertableBuildResult result = runAndFail("clean", ScoveragePlugin.getCHECK_NAME(),
"test",
ScoveragePlugin.scoverageTestTaskName("test"),
"--tests", "org.hello.TestNothingSuite",
"--tests", "org.hello.a.WorldASuite",
"--tests", "org.hello.b.WorldBSuite",
"--tests", "org.hello.common.WorldCommonSuite",
"-x", "intTest");
"-x", ScoveragePlugin.scoverageTestTaskName("intTest"));

result.assertTaskFailed(ScoveragePlugin.getCHECK_NAME());

Expand All @@ -175,12 +175,12 @@ public void checkScoverageWithoutCoverageInRoot() throws Exception {
public void checkScoverageWithoutCoverageInA() throws Exception {

AssertableBuildResult result = runAndFail("clean", ScoveragePlugin.getCHECK_NAME(),
"test",
ScoveragePlugin.scoverageTestTaskName("test"),
"--tests", "org.hello.a.TestNothingASuite",
"--tests", "org.hello.WorldSuite",
"--tests", "org.hello.b.WorldBSuite",
"--tests", "org.hello.common.WorldCommonSuite",
"-x", ":a:intTest");
"-x", ":a:" + ScoveragePlugin.scoverageTestTaskName("intTest"));

result.assertTaskFailed("a:" + ScoveragePlugin.getCHECK_NAME());

Expand All @@ -193,8 +193,8 @@ public void checkScoverageWithoutCoverageInA() throws Exception {
public void checkScoverageWithoutNormalCompilationAndWithoutCoverageInCommon() throws Exception {

AssertableBuildResult result = runAndFail("clean",
":a:test",
":common:test", "--tests", "org.hello.common.TestNothingCommonSuite",
":a:" + ScoveragePlugin.scoverageTestTaskName("test"),
":common:" + ScoveragePlugin.scoverageTestTaskName("test"), "--tests", "org.hello.common.TestNothingCommonSuite",
"-P" + ScoveragePlugin.getSCOVERAGE_COMPILE_ONLY_PROPERTY(),
ScoveragePlugin.getCHECK_NAME());

Expand All @@ -210,7 +210,7 @@ public void checkAndAggregateScoverageWithoutCoverageInRoot() throws Exception {
// should pass as the check on the root is for the aggregation (which covers > 50%)

AssertableBuildResult result = run("clean", ScoveragePlugin.getCHECK_NAME(),
ScoveragePlugin.getAGGREGATE_NAME(), "test",
ScoveragePlugin.getAGGREGATE_NAME(), ScoveragePlugin.scoverageTestTaskName("test"),
"--tests", "org.hello.TestNothingSuite",
"--tests", "org.hello.a.WorldASuite",
"--tests", "org.hello.b.WorldBSuite",
Expand All @@ -234,12 +234,12 @@ public void checkAndAggregateScoverageWithoutCoverageInRoot() throws Exception {
public void checkAndAggregateScoverageWithoutCoverageInAll() throws Exception {

AssertableBuildResult result = runAndFail("clean", ScoveragePlugin.getCHECK_NAME(),
ScoveragePlugin.getAGGREGATE_NAME(), "test",
ScoveragePlugin.getAGGREGATE_NAME(), ScoveragePlugin.scoverageTestTaskName("test"),
"--tests", "org.hello.TestNothingSuite",
"--tests", "org.hello.a.TestNothingASuite",
"--tests", "org.hello.b.TestNothingBSuite",
"--tests", "org.hello.common.TestNothingCommonSuite",
"-x", "intTest");
"-x", ScoveragePlugin.scoverageTestTaskName("intTest"));

result.assertTaskSucceeded(ScoveragePlugin.getREPORT_NAME());
result.assertTaskSucceeded("a:" + ScoveragePlugin.getREPORT_NAME());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public void checkScoverage() throws Exception {
public void checkScoverageFails() throws Exception {

AssertableBuildResult result = runAndFail("clean", ScoveragePlugin.getCHECK_NAME(),
"test", "--tests", "org.hello.TestNothingSuite");
ScoveragePlugin.scoverageTestTaskName("test"), "--tests", "org.hello.TestNothingSuite");

result.assertTaskSucceeded(ScoveragePlugin.getCOMPILE_NAME());
result.assertTaskSucceeded(ScoveragePlugin.getREPORT_NAME());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,8 @@ public void checkScoverageIntTest() throws Exception {
public void checkScoverageFails() throws Exception {

AssertableBuildResult result = runAndFail("clean", ScoveragePlugin.getCHECK_NAME(),
"intTest", "--tests", "org.hello.TestNothingSuite",
"-x", "test");
ScoveragePlugin.scoverageTestTaskName("intTest"), "--tests", "org.hello.TestNothingSuite",
"-x", ScoveragePlugin.scoverageTestTaskName("test"));

result.assertTaskSucceeded(ScoveragePlugin.getCOMPILE_NAME());
result.assertTaskSucceeded(ScoveragePlugin.getREPORT_NAME());
Expand Down
77 changes: 77 additions & 0 deletions src/functionalTest/java/org/scoverage/ScoverageFunctionalTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,11 @@

import java.io.File;
import java.io.IOException;
import java.io.UncheckedIOException;
import java.nio.file.Files;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.List;
import java.util.regex.Pattern;

Expand Down Expand Up @@ -77,6 +80,45 @@ protected AssertableBuildResult run(String... arguments) {
return new AssertableBuildResult(runner.build());
}

protected AssertableBuildResult runWithConfigurationCache(String... arguments) {

configureConfigurationCacheArguments(arguments);
return new AssertableBuildResult(runner.build());
}

protected void prepareConfigurationCacheRun(String... arguments) {

configureConfigurationCacheArguments(arguments);
}

protected AssertableBuildResult buildPreparedConfigurationCacheRun() {

return new AssertableBuildResult(runner.build());
}

protected void cleanProjectForConfigurationCache() throws IOException {

deleteRecursively(buildDir());
deleteRecursively(new File(projectDir(), ".gradle"));
}

private void deleteRecursively(File directory) throws IOException {

if (!directory.exists()) {
return;
}

Files.walk(directory.toPath())
.sorted(Comparator.reverseOrder())
.forEach(path -> {
try {
Files.delete(path);
} catch (IOException e) {
throw new UncheckedIOException(e);
}
});
}

protected AssertableBuildResult runAndFail(String... arguments) {

configureArguments(arguments);
Expand Down Expand Up @@ -121,8 +163,23 @@ protected List<String> getVersionAgruments() {

private void configureArguments(String... arguments) {

configureArguments(false, arguments);
}

private void configureConfigurationCacheArguments(String... arguments) {

configureArguments(true, arguments);
}

private void configureArguments(boolean configurationCache, String... arguments) {

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

if (configurationCache) {
fullArguments.add("--configuration-cache");
fullArguments.add("--configuration-cache-problems=fail");
}

if (Boolean.parseBoolean(System.getProperty("failOnWarning"))) {
fullArguments.add("--warning-mode=fail");
} else {
Expand Down Expand Up @@ -201,6 +258,26 @@ private boolean taskExists(String taskName) {
Pattern regex = Pattern.compile("^(> Task )?" + fullTaskName(taskName), Pattern.MULTILINE);
return regex.matcher(result.getOutput()).find();
}

public void assertConfigurationCacheStored() {

Assert.assertTrue(
"Expected configuration cache to be stored",
result.getOutput().contains("Configuration cache entry stored")
|| result.getOutput().contains("Calculating task graph as no cached configuration is available")
);
}

public void assertConfigurationCacheReused() {

String output = result.getOutput();
Assert.assertTrue(
"Expected configuration cache to be reused",
output.contains("Reusing configuration cache")
|| output.contains("Configuration cache entry reused")
|| output.contains("from configuration cache")
);
}
}
}

Loading
Loading