Skip to content

Commit 1b990ab

Browse files
committed
1162: adding tests verifying issue
results in 'Couldn't resolve parser "php"' on gradle side and 'Couldn't resolve parser "java"' on maven side
1 parent 3226d2b commit 1b990ab

File tree

3 files changed

+105
-4
lines changed

3 files changed

+105
-4
lines changed

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

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,48 @@ void usePhpCommunityPlugin() throws IOException {
183183
assertFile("php-example.php").sameAsResource("npm/prettier/plugins/php.clean");
184184
}
185185

186+
/**
187+
* This test is to ensure that we can have multiple prettier instances in one spotless config.
188+
*
189+
* @see <a href="https://github.com/diffplug/spotless/issues/1162">Issue #1162 on github</a>
190+
*/
191+
@Test
192+
void usePhpAndJavaCommunityPlugin() throws IOException {
193+
setFile("build.gradle").toLines(
194+
"plugins {",
195+
" id 'com.diffplug.spotless'",
196+
"}",
197+
"repositories { mavenCentral() }",
198+
"def prettierConfigPhp = [:]",
199+
"prettierConfigPhp['tabWidth'] = 3",
200+
"prettierConfigPhp['parser'] = 'php'",
201+
"def prettierPackagesPhp = [:]",
202+
"prettierPackagesPhp['prettier'] = '2.0.5'",
203+
"prettierPackagesPhp['@prettier/plugin-php'] = '0.14.2'",
204+
"def prettierConfigJava = [:]",
205+
"prettierConfigJava['tabWidth'] = 4",
206+
"prettierConfigJava['parser'] = 'java'",
207+
"def prettierPackagesJava = [:]",
208+
"prettierPackagesJava['prettier'] = '2.0.5'",
209+
"prettierPackagesJava['prettier-plugin-java'] = '0.8.0'",
210+
"spotless {",
211+
" format 'php', {",
212+
" target 'php-example.php'",
213+
" prettier(prettierPackagesPhp).config(prettierConfigPhp)",
214+
" }",
215+
" java {",
216+
" target 'JavaTest.java'",
217+
" prettier(prettierPackagesJava).config(prettierConfigJava)",
218+
" }",
219+
"}");
220+
setFile("php-example.php").toResource("npm/prettier/plugins/php.dirty");
221+
setFile("JavaTest.java").toResource("npm/prettier/plugins/java-test.dirty");
222+
final BuildResult spotlessApply = gradleRunner().withArguments("--stacktrace", "spotlessApply").build();
223+
Assertions.assertThat(spotlessApply.getOutput()).contains("BUILD SUCCESSFUL");
224+
assertFile("php-example.php").sameAsResource("npm/prettier/plugins/php.clean");
225+
assertFile("JavaTest.java").sameAsResource("npm/prettier/plugins/java-test.clean");
226+
}
227+
186228
@Test
187229
void autodetectNpmrcFileConfig() throws IOException {
188230
setFile(".npmrc").toLines(

plugin-maven/src/test/java/com/diffplug/spotless/maven/MavenIntegrationHarness.java

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,7 @@ private static String getSystemProperty(String name) {
285285
return value;
286286
}
287287

288-
private static String[] groupWithSteps(String group, String[] includes, String... steps) {
288+
protected static String[] groupWithSteps(String group, String[] includes, String... steps) {
289289
String[] result = new String[steps.length + includes.length + 2];
290290
result[0] = "<" + group + ">";
291291
System.arraycopy(includes, 0, result, 1, includes.length);
@@ -294,15 +294,22 @@ private static String[] groupWithSteps(String group, String[] includes, String..
294294
return result;
295295
}
296296

297-
private static String[] groupWithSteps(String group, String... steps) {
297+
protected static String[] groupWithSteps(String group, String... steps) {
298298
return groupWithSteps(group, new String[]{}, steps);
299299
}
300300

301-
private static String[] including(String... includes) {
301+
protected static String[] including(String... includes) {
302302
return groupWithSteps("includes", groupWithSteps("include", includes));
303303
}
304304

305-
private static String[] formats(String... formats) {
305+
protected static String[] formats(String... formats) {
306306
return groupWithSteps("formats", formats);
307307
}
308+
309+
protected static String[] formats(String[]... formats) {
310+
String[] formatsArray = Arrays.stream(formats)
311+
.flatMap(Arrays::stream)
312+
.toArray(String[]::new);
313+
return formats(formatsArray);
314+
}
308315
}

plugin-maven/src/test/java/com/diffplug/spotless/maven/prettier/PrettierFormatStepTest.java

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,58 @@ void unique_dependency_config() throws Exception {
106106
assertThat(result.stdOutUtf8()).contains(Prettier.ERROR_MESSAGE_ONLY_ONE_CONFIG);
107107
}
108108

109+
/**
110+
* This test is to ensure that we can have multiple prettier instances in one spotless config.
111+
*
112+
* @see <a href="https://github.com/diffplug/spotless/issues/1162">Issue #1162 on github</a>
113+
*/
114+
@Test
115+
void multiple_prettier_configs() throws Exception {
116+
writePom(
117+
formats(
118+
groupWithSteps("format", including("php-example.php"),
119+
"<prettier>",
120+
" <devDependencyProperties>",
121+
" <property>",
122+
" <name>prettier</name>",
123+
" <value>2.0.5</value>",
124+
" </property>",
125+
" <property>",
126+
" <name>@prettier/plugin-php</name>",
127+
" <value>0.14.2</value>",
128+
" </property>",
129+
" </devDependencyProperties>",
130+
" <config>",
131+
" <tabWidth>3</tabWidth>",
132+
" <parser>php</parser>",
133+
" </config>",
134+
"</prettier>"),
135+
groupWithSteps("java", including("JavaTest.java"),
136+
"<prettier>",
137+
" <devDependencyProperties>",
138+
" <property>",
139+
" <name>prettier</name>",
140+
" <value>2.0.5</value>",
141+
" </property>",
142+
" <property>",
143+
" <name>prettier-plugin-java</name>",
144+
" <value>0.8.0</value>",
145+
" </property>",
146+
" </devDependencyProperties>",
147+
" <config>",
148+
" <tabWidth>4</tabWidth>",
149+
" <parser>java</parser>",
150+
" </config>",
151+
"</prettier>")));
152+
153+
setFile("php-example.php").toResource("npm/prettier/plugins/php.dirty");
154+
setFile("JavaTest.java").toResource("npm/prettier/plugins/java-test.dirty");
155+
mavenRunner().withArguments("spotless:apply").runNoError();
156+
assertFile("php-example.php").sameAsResource("npm/prettier/plugins/php.clean");
157+
assertFile("JavaTest.java").sameAsResource("npm/prettier/plugins/java-test.clean");
158+
159+
}
160+
109161
@Test
110162
void custom_plugin() throws Exception {
111163
writePomWithFormatSteps(

0 commit comments

Comments
 (0)