Skip to content

Commit 642ac61

Browse files
committed
It works for git ratchet too.
Note: we removed the test for an empty project folder (deleted L186-187) because it triggered a bug in Gradle gradle/gradle#18897. Hard to imagine how it could actually happen in the wild, so no sense banging our head against it.
1 parent 5f4a0b5 commit 642ac61

File tree

1 file changed

+35
-14
lines changed

1 file changed

+35
-14
lines changed

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

Lines changed: 35 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,10 @@
3131
import org.eclipse.jgit.revwalk.RevCommit;
3232
import org.eclipse.jgit.treewalk.TreeWalk;
3333
import org.gradle.testkit.runner.BuildResult;
34+
import org.gradle.testkit.runner.GradleRunner;
3435
import org.gradle.testkit.runner.TaskOutcome;
35-
import org.junit.jupiter.api.Test;
36+
import org.junit.jupiter.params.ParameterizedTest;
37+
import org.junit.jupiter.params.provider.ValueSource;
3638

3739
class GitRatchetGradleTest extends GradleIntegrationHarness {
3840
private static final String TEST_PATH = "src/markdown/test.md";
@@ -46,11 +48,24 @@ private Git initRepo() throws IllegalStateException, GitAPIException, IOExceptio
4648
return git;
4749
}
4850

49-
@Test
50-
void singleProjectExhaustive() throws Exception {
51+
@Override
52+
protected GradleRunner gradleRunner() throws IOException {
53+
return super.gradleRunner().withGradleVersion(GradleVersionSupport.CONFIGURATION_CACHE.version);
54+
}
55+
56+
@ParameterizedTest
57+
@ValueSource(ints = {0, 1})
58+
void singleProjectExhaustive(int useConfigCache) throws Exception {
5159
try (Git git = initRepo()) {
60+
if (useConfigCache == 1) {
61+
setFile("gradle.properties").toContent("org.gradle.unsafe.configuration-cache=true");
62+
}
5263
setFile("build.gradle").toLines(
53-
"plugins { id 'com.diffplug.spotless' }",
64+
"plugins {",
65+
" id 'com.diffplug.spotless'",
66+
" id 'com.diffplug.spotless-setup'",
67+
"}",
68+
"spotlessSetup { enableConfigCacheDaemonLocal = true }",
5469
"spotless {",
5570
" ratchetFrom 'baseline'",
5671
" format 'misc', {",
@@ -135,13 +150,17 @@ private BuildResultAssertion assertFail(String... tasks) throws Exception {
135150
return new BuildResultAssertion(gradleRunner().withArguments(tasks).buildAndFail());
136151
}
137152

138-
private static final String BASELINE_ROOT = "cf049829afeba064f27cd67911dc36e585c9d869";
153+
private static final String BASELINE_ROOT = "a5efb43a0da929853e596a85c1f225a60ae0acfd";
139154
private static final String BASELINE_CLEAN = "65fdd75c1ae00c0646f6487d68c44ddca51f0841";
140155
private static final String BASELINE_DIRTY = "4cfc3358ccbf186738b82a60276b1e5306bc3870";
141156

142-
@Test
143-
void multiProject() throws Exception {
157+
@ParameterizedTest
158+
@ValueSource(ints = {0, 1})
159+
void multiProject(int useConfigCache) throws Exception {
144160
try (Git git = initRepo()) {
161+
if (useConfigCache == 1) {
162+
setFile("gradle.properties").toContent("org.gradle.unsafe.configuration-cache=true");
163+
}
145164
setFile("settings.gradle").toLines(
146165
"plugins {",
147166
" id 'com.diffplug.spotless' apply false",
@@ -159,14 +178,21 @@ void multiProject() throws Exception {
159178
" bumpThisNumberIfACustomStepChanges(1)",
160179
" }",
161180
"}");
162-
setFile(".gitignore").toContent("build/\n.gradle\n");
163-
setFile("build.gradle").toContent("apply from: rootProject.file('spotless.gradle') // root");
181+
setFile(".gitignore").toContent("build/\n.gradle\n*.properties\n");
182+
setFile("build.gradle").toLines(
183+
"apply plugin: 'com.diffplug.spotless-setup'",
184+
"spotlessSetup { enableConfigCacheDaemonLocal = true }",
185+
"apply from: rootProject.file('spotless.gradle') // root");
164186
setFile(TEST_PATH).toContent("HELLO");
165187
setFile("clean/build.gradle").toContent("apply from: rootProject.file('spotless.gradle') // clean");
166188
setFile("clean/" + TEST_PATH).toContent("HELLO");
167189
setFile("dirty/build.gradle").toContent("apply from: rootProject.file('spotless.gradle') // dirty");
168190
setFile("dirty/" + TEST_PATH).toContent("HELLO");
191+
setFile("added/build.gradle").toContent("apply from: rootProject.file('spotless.gradle') // added");
169192
RevCommit baseline = addAndCommit(git);
193+
if (useConfigCache == 1) {
194+
setFile("gradle.properties").toContent("org.gradle.unsafe.configuration-cache=true");
195+
}
170196

171197
ObjectId cleanFolder = TreeWalk.forPath(git.getRepository(), "clean", baseline.getTree()).getObjectId(0);
172198
ObjectId dirtyFolder = TreeWalk.forPath(git.getRepository(), "dirty", baseline.getTree()).getObjectId(0);
@@ -180,12 +206,7 @@ void multiProject() throws Exception {
180206
.outcome(":clean:spotlessCheck", TaskOutcome.SUCCESS)
181207
.outcome(":dirty:spotlessCheck", TaskOutcome.SUCCESS);
182208

183-
setFile("added/build.gradle").toContent("apply from: rootProject.file('spotless.gradle') // added");
184209
setFile("added/" + TEST_PATH).toContent("HELLO");
185-
186-
TreeWalk isNull = TreeWalk.forPath(git.getRepository(), "added", baseline.getTree());
187-
Assertions.assertThat(isNull).isNull();
188-
189210
assertPass("spotlessMisc")
190211
.outcome(":spotlessMisc", TaskOutcome.UP_TO_DATE)
191212
.outcome(":clean:spotlessMisc", TaskOutcome.UP_TO_DATE)

0 commit comments

Comments
 (0)