Skip to content

Commit cfe1058

Browse files
committed
Run IdeHookTest with and without configuration cache.
1 parent ce70ea7 commit cfe1058

File tree

1 file changed

+50
-18
lines changed

1 file changed

+50
-18
lines changed

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

Lines changed: 50 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,19 @@
1919
import java.io.IOException;
2020
import java.io.Writer;
2121
import java.nio.charset.StandardCharsets;
22+
import java.util.stream.Stream;
2223

2324
import org.assertj.core.api.Assertions;
25+
import org.gradle.testkit.runner.GradleRunner;
2426
import org.junit.jupiter.api.BeforeEach;
25-
import org.junit.jupiter.api.Test;
27+
import org.junit.jupiter.api.TestInstance;
28+
import org.junit.jupiter.params.ParameterizedTest;
29+
import org.junit.jupiter.params.provider.MethodSource;
2630

2731
import com.diffplug.common.base.StringPrinter;
2832
import com.diffplug.common.io.Files;
2933

34+
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
3035
class IdeHookTest extends GradleIntegrationHarness {
3136
private String output, error;
3237
private File dirty, clean, diverge, outofbounds;
@@ -57,12 +62,16 @@ void before() throws IOException {
5762
Files.write("ABC".getBytes(StandardCharsets.UTF_8), outofbounds);
5863
}
5964

60-
private void runWith(String... arguments) throws IOException {
65+
private static Stream<Boolean> configurationCacheProvider() {
66+
return Stream.of(false, true);
67+
}
68+
69+
private void runWith(boolean configurationCache, String... arguments) throws IOException {
6170
StringBuilder output = new StringBuilder();
6271
StringBuilder error = new StringBuilder();
6372
try (Writer outputWriter = new StringPrinter(output::append).toWriter();
6473
Writer errorWriter = new StringPrinter(error::append).toWriter();) {
65-
gradleRunner()
74+
gradleRunner(configurationCache)
6675
.withArguments(arguments)
6776
.forwardStdOutput(outputWriter)
6877
.forwardStdError(errorWriter)
@@ -72,37 +81,60 @@ private void runWith(String... arguments) throws IOException {
7281
this.error = error.toString();
7382
}
7483

75-
@Test
76-
void dirty() throws IOException {
77-
runWith("spotlessApply", "--quiet", "-PspotlessIdeHook=" + dirty.getAbsolutePath(), "-PspotlessIdeHookUseStdOut");
84+
protected GradleRunner gradleRunner(boolean configurationCache) throws IOException {
85+
if (configurationCache) {
86+
setFile("gradle.properties").toContent("org.gradle.unsafe.configuration-cache=true");
87+
setFile("settings.gradle").toContent("enableFeaturePreview(\"STABLE_CONFIGURATION_CACHE\")");
88+
return super.gradleRunner().withGradleVersion(GradleVersionSupport.STABLE_CONFIGURATION_CACHE.version);
89+
} else {
90+
File gradleProps = new File(rootFolder(), "gradle.properties");
91+
if (gradleProps.exists()) {
92+
gradleProps.delete();
93+
}
94+
File settingsGradle = new File(rootFolder(), "settings.gradle");
95+
if (settingsGradle.exists()) {
96+
settingsGradle.delete();
97+
}
98+
return super.gradleRunner();
99+
}
100+
}
101+
102+
@ParameterizedTest
103+
@MethodSource("configurationCacheProvider")
104+
void dirty(boolean configurationCache) throws IOException {
105+
runWith(configurationCache, "spotlessApply", "--quiet", "-PspotlessIdeHook=" + dirty.getAbsolutePath(), "-PspotlessIdeHookUseStdOut");
78106
Assertions.assertThat(output).isEqualTo("abc");
79107
Assertions.assertThat(error).startsWith("IS DIRTY");
80108
}
81109

82-
@Test
83-
void clean() throws IOException {
84-
runWith("spotlessApply", "--quiet", "-PspotlessIdeHook=" + clean.getAbsolutePath(), "-PspotlessIdeHookUseStdOut");
110+
@ParameterizedTest
111+
@MethodSource("configurationCacheProvider")
112+
void clean(boolean configurationCache) throws IOException {
113+
runWith(configurationCache, "spotlessApply", "--quiet", "-PspotlessIdeHook=" + clean.getAbsolutePath(), "-PspotlessIdeHookUseStdOut");
85114
Assertions.assertThat(output).isEmpty();
86115
Assertions.assertThat(error).startsWith("IS CLEAN");
87116
}
88117

89-
@Test
90-
void diverge() throws IOException {
91-
runWith("spotlessApply", "--quiet", "-PspotlessIdeHook=" + diverge.getAbsolutePath(), "-PspotlessIdeHookUseStdOut");
118+
@ParameterizedTest
119+
@MethodSource("configurationCacheProvider")
120+
void diverge(boolean configurationCache) throws IOException {
121+
runWith(configurationCache, "spotlessApply", "--quiet", "-PspotlessIdeHook=" + diverge.getAbsolutePath(), "-PspotlessIdeHookUseStdOut");
92122
Assertions.assertThat(output).isEmpty();
93123
Assertions.assertThat(error).startsWith("DID NOT CONVERGE");
94124
}
95125

96-
@Test
97-
void outofbounds() throws IOException {
98-
runWith("spotlessApply", "--quiet", "-PspotlessIdeHook=" + outofbounds.getAbsolutePath(), "-PspotlessIdeHookUseStdOut");
126+
@ParameterizedTest
127+
@MethodSource("configurationCacheProvider")
128+
void outofbounds(boolean configurationCache) throws IOException {
129+
runWith(configurationCache, "spotlessApply", "--quiet", "-PspotlessIdeHook=" + outofbounds.getAbsolutePath(), "-PspotlessIdeHookUseStdOut");
99130
Assertions.assertThat(output).isEmpty();
100131
Assertions.assertThat(error).isEmpty();
101132
}
102133

103-
@Test
104-
void notAbsolute() throws IOException {
105-
runWith("spotlessApply", "--quiet", "-PspotlessIdeHook=build.gradle", "-PspotlessIdeHookUseStdOut");
134+
@ParameterizedTest
135+
@MethodSource("configurationCacheProvider")
136+
void notAbsolute(boolean configurationCache) throws IOException {
137+
runWith(configurationCache, "spotlessApply", "--quiet", "-PspotlessIdeHook=build.gradle", "-PspotlessIdeHookUseStdOut");
106138
Assertions.assertThat(output).isEmpty();
107139
Assertions.assertThat(error).contains("Argument passed to spotlessIdeHook must be an absolute path");
108140
}

0 commit comments

Comments
 (0)