Skip to content

Commit c3a8c82

Browse files
committed
Gradle custom step test now runs with and without configuration cache.
1 parent a52fa2f commit c3a8c82

File tree

1 file changed

+38
-3
lines changed

1 file changed

+38
-3
lines changed

plugin-gradle/src/test/java/com/diffplug/gradle/spotless/BumpThisNumberIfACustomStepChangesTest.java

Lines changed: 38 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2016-2024 DiffPlug
2+
* Copyright 2016-2025 DiffPlug
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -17,9 +17,39 @@
1717

1818
import java.io.IOException;
1919

20+
import org.gradle.testkit.runner.GradleRunner;
2021
import org.junit.jupiter.api.Test;
2122

22-
class BumpThisNumberIfACustomStepChangesTest extends GradleIntegrationHarness {
23+
abstract class BumpThisNumberIfACustomStepChangesTest extends GradleIntegrationHarness {
24+
private boolean useConfigCache;
25+
26+
BumpThisNumberIfACustomStepChangesTest(boolean useConfigCache) {
27+
this.useConfigCache = useConfigCache;
28+
}
29+
30+
static class WithConfigCache extends BumpThisNumberIfACustomStepChangesTest {
31+
WithConfigCache() {
32+
super(true);
33+
}
34+
}
35+
36+
static class WithoutConfigCache extends BumpThisNumberIfACustomStepChangesTest {
37+
WithoutConfigCache() {
38+
super(false);
39+
}
40+
}
41+
42+
@Override
43+
public GradleRunner gradleRunner() throws IOException {
44+
if (useConfigCache) {
45+
setFile("gradle.properties").toLines("org.gradle.unsafe.configuration-cache=true",
46+
"org.gradle.configuration-cache=true");
47+
return super.gradleRunner().withGradleVersion(GradleVersionSupport.CONFIGURATION_CACHE.version);
48+
} else {
49+
return super.gradleRunner();
50+
}
51+
}
52+
2353
private void writeBuildFile(String toInsert) throws IOException {
2454
setFile("build.gradle").toLines(
2555
"plugins {",
@@ -50,7 +80,12 @@ void customRuleNeverUpToDate() throws IOException {
5080
writeContentWithBadFormatting();
5181
applyIsUpToDate(false);
5282
checkIsUpToDate(false);
53-
checkIsUpToDate(false);
83+
if (useConfigCache) {
84+
// if the config cache is in-effect, then it's okay for custom rules to become "up-to-date"
85+
checkIsUpToDate(true);
86+
} else {
87+
checkIsUpToDate(false);
88+
}
5489
}
5590

5691
@Test

0 commit comments

Comments
 (0)