Skip to content

Commit 829a275

Browse files
committed
Run the NativeCmd integration test with and without the configuration cache to reproduce #2347.
1 parent dbe3d97 commit 829a275

File tree

1 file changed

+22
-8
lines changed

1 file changed

+22
-8
lines changed

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

+22-8
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2021 DiffPlug
2+
* Copyright 2024 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.
@@ -20,26 +20,40 @@
2020
import java.io.File;
2121
import java.io.IOException;
2222

23+
import org.gradle.testkit.runner.GradleRunner;
2324
import org.junit.jupiter.api.Test;
2425

25-
class NativeCmdIntegrationTest extends GradleIntegrationHarness {
26+
interface NativeCmdTestCase {
2627
@Test
27-
void nativeCmd() throws IOException {
28+
default void nativeCmd() throws IOException {
2829
// This will only work if /usr/bin/sed is available
2930
assumeThat(new File("/usr/bin/sed")).exists();
3031

31-
setFile("build.gradle").toLines(
32+
GradleIntegrationHarness harness = (GradleIntegrationHarness) this;
33+
harness.setFile("build.gradle").toLines(
3234
"plugins {",
3335
" id 'com.diffplug.spotless'",
3436
"}",
3537
"spotless {",
38+
" lineEndings 'UNIX'",
3639
" format 'test', {",
37-
" target '**/*.txt'",
40+
" target '*.txt'",
3841
" nativeCmd('sed', '/usr/bin/sed', ['s/placeholder/replaced/g'])",
3942
" }",
4043
"}");
41-
setFile("test.txt").toResource("native_cmd/dirty.txt");
42-
gradleRunner().withArguments("spotlessApply").build();
43-
assertFile("test.txt").sameAsResource("native_cmd/clean.txt");
44+
harness.setFile("test.txt").toResource("native_cmd/dirty.txt");
45+
harness.gradleRunner().withArguments("spotlessApply", "--stacktrace").build();
46+
harness.assertFile("test.txt").sameAsResource("native_cmd/clean.txt");
47+
}
48+
}
49+
50+
class NativeCmdWithoutConfigCacheTest extends GradleIntegrationHarness implements NativeCmdTestCase {}
51+
52+
class NativeCmdWithConfigCacheTest extends GradleIntegrationHarness implements NativeCmdTestCase {
53+
@Override
54+
protected GradleRunner gradleRunner() throws IOException {
55+
setFile("gradle.properties").toContent("org.gradle.unsafe.configuration-cache=true");
56+
setFile("settings.gradle").toContent("enableFeaturePreview(\"STABLE_CONFIGURATION_CACHE\")");
57+
return super.gradleRunner().withGradleVersion(GradleVersionSupport.CONFIGURATION_CACHE.version);
4458
}
4559
}

0 commit comments

Comments
 (0)