|
1 | 1 | /*
|
2 |
| - * Copyright 2021 DiffPlug |
| 2 | + * Copyright 2024 DiffPlug |
3 | 3 | *
|
4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License");
|
5 | 5 | * you may not use this file except in compliance with the License.
|
|
20 | 20 | import java.io.File;
|
21 | 21 | import java.io.IOException;
|
22 | 22 |
|
| 23 | +import org.gradle.testkit.runner.GradleRunner; |
23 | 24 | import org.junit.jupiter.api.Test;
|
24 | 25 |
|
25 |
| -class NativeCmdIntegrationTest extends GradleIntegrationHarness { |
| 26 | +interface NativeCmdIntegrationTest { |
26 | 27 | @Test
|
27 |
| - void nativeCmd() throws IOException { |
| 28 | + default void nativeCmd() throws IOException { |
28 | 29 | // This will only work if /usr/bin/sed is available
|
29 | 30 | assumeThat(new File("/usr/bin/sed")).exists();
|
30 | 31 |
|
31 |
| - setFile("build.gradle").toLines( |
| 32 | + GradleIntegrationHarness harness = (GradleIntegrationHarness) this; |
| 33 | + harness.setFile("build.gradle").toLines( |
32 | 34 | "plugins {",
|
33 | 35 | " id 'com.diffplug.spotless'",
|
34 | 36 | "}",
|
35 | 37 | "spotless {",
|
| 38 | + " lineEndings 'UNIX'", |
36 | 39 | " format 'test', {",
|
37 |
| - " target '**/*.txt'", |
| 40 | + " target '*.txt'", |
38 | 41 | " nativeCmd('sed', '/usr/bin/sed', ['s/placeholder/replaced/g'])",
|
39 | 42 | " }",
|
40 | 43 | "}");
|
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 | + class NativeCmdWithoutConfigCacheTest extends GradleIntegrationHarness implements NativeCmdIntegrationTest {} |
| 50 | + |
| 51 | + class NativeCmdWithConfigCacheTest extends GradleIntegrationHarness implements NativeCmdIntegrationTest { |
| 52 | + @Override |
| 53 | + public GradleRunner gradleRunner() throws IOException { |
| 54 | + setFile("gradle.properties").toContent("org.gradle.unsafe.configuration-cache=true"); |
| 55 | + setFile("gradle.properties").toContent("org.gradle.configuration-cache=true"); |
| 56 | + return super.gradleRunner().withGradleVersion(GradleVersionSupport.CONFIGURATION_CACHE.version); |
| 57 | + } |
44 | 58 | }
|
45 | 59 | }
|
0 commit comments