Skip to content

Commit 719aa09

Browse files
author
Alex Simkin
committed
Bump default version. Add tests
1 parent b2e29e2 commit 719aa09

File tree

10 files changed

+125
-9
lines changed

10 files changed

+125
-9
lines changed

Diff for: lib/src/main/java/com/diffplug/spotless/scala/ScalaFmtStep.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,14 @@
3434
import com.diffplug.spotless.JarState;
3535
import com.diffplug.spotless.Provisioner;
3636

37-
/** Wraps up [scalafmt](https://github.com/olafurpg/scalafmt) as a FormatterStep. */
37+
/** Wraps up [scalafmt](https://github.com/scalameta/scalafmt) as a FormatterStep. */
3838
public class ScalaFmtStep {
3939
// prevent direct instantiation
4040
private ScalaFmtStep() {}
4141

4242
private static final Pattern VERSION_PRE_2_0 = Pattern.compile("[10]\\.(\\d+)\\.\\d+");
4343
private static final Pattern VERSION_PRE_3_0 = Pattern.compile("2\\.(\\d+)\\.\\d+");
44-
private static final String DEFAULT_VERSION = "2.0.1";
44+
private static final String DEFAULT_VERSION = "3.0.0";
4545
static final String NAME = "scalafmt";
4646
static final String MAVEN_COORDINATE_PRE_2_0 = "com.geirsson:scalafmt-core_2.11:";
4747
static final String MAVEN_COORDINATE_PRE_3_0 = "org.scalameta:scalafmt-core_2.11:";

Diff for: plugin-gradle/src/test/java/com/diffplug/gradle/spotless/ScalaExtensionTest.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2016-2020 DiffPlug
2+
* Copyright 2016-2021 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.
@@ -36,6 +36,6 @@ public void integration() throws IOException {
3636
setFile("scalafmt.conf").toResource("scala/scalafmt/scalafmt.conf");
3737
setFile("src/main/scala/basic.scala").toResource("scala/scalafmt/basic.dirty");
3838
gradleRunner().withArguments("spotlessApply").build();
39-
assertFile("src/main/scala/basic.scala").sameAsResource("scala/scalafmt/basic.cleanWithCustomConf_2.0.1");
39+
assertFile("src/main/scala/basic.scala").sameAsResource("scala/scalafmt/basic.cleanWithCustomConf_3.0.0");
4040
}
4141
}

Diff for: plugin-maven/src/test/java/com/diffplug/spotless/maven/IncludesExcludesTest.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public class IncludesExcludesTest extends MavenIntegrationHarness {
2424
private static final String JAVA_FORMATTED = "java/eclipse/JavaCodeFormatted.test";
2525
private static final String JAVA_UNFORMATTED = "java/eclipse/JavaCodeUnformatted.test";
2626
private static final String SCALA_UNFORMATTED = "scala/scalafmt/basic.dirty";
27-
private static final String SCALA_FORMATTED = "scala/scalafmt/basic.clean_2.0.1";
27+
private static final String SCALA_FORMATTED = "scala/scalafmt/basic.clean_3.0.0";
2828

2929
@Test
3030
public void testDefaultIncludesJava() throws Exception {

Diff for: plugin-maven/src/test/java/com/diffplug/spotless/maven/MultiModuleProjectTest.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ public void testConfigurationDependency() throws Exception {
9393
assertFile("two/src/main/java/test1.java").sameAsResource("java/eclipse/JavaCodeFormatted.test");
9494
assertFile("two/src/test/java/test2.java").sameAsResource("java/eclipse/JavaCodeFormatted.test");
9595

96-
assertFile("three/src/main/scala/test1.scala").sameAsResource("scala/scalafmt/basic.cleanWithCustomConf_2.0.1");
97-
assertFile("three/src/test/scala/test2.scala").sameAsResource("scala/scalafmt/basic.cleanWithCustomConf_2.0.1");
96+
assertFile("three/src/main/scala/test1.scala").sameAsResource("scala/scalafmt/basic.cleanWithCustomConf_3.0.0");
97+
assertFile("three/src/test/scala/test2.scala").sameAsResource("scala/scalafmt/basic.cleanWithCustomConf_3.0.0");
9898
}
9999
}

Diff for: plugin-maven/src/test/java/com/diffplug/spotless/maven/scala/ScalafmtTest.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public class ScalafmtTest extends MavenIntegrationHarness {
2424
public void testScalafmtWithDefaultConfig() throws Exception {
2525
writePomWithScalaSteps("<scalafmt/>");
2626

27-
runTest("scala/scalafmt/basic.clean_2.0.1");
27+
runTest("scala/scalafmt/basic.clean_3.0.0");
2828
}
2929

3030
@Test
@@ -36,7 +36,7 @@ public void testScalafmtWithCustomConfig() throws Exception {
3636
" <file>${project.basedir}/scalafmt.conf</file>",
3737
"</scalafmt>");
3838

39-
runTest("scala/scalafmt/basic.cleanWithCustomConf_2.0.1");
39+
runTest("scala/scalafmt/basic.cleanWithCustomConf_3.0.0");
4040
}
4141

4242
private void runTest(String s) throws Exception {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
@foobar(
2+
"annot", {
3+
val x = 2
4+
val y = 2 // y=2
5+
x + y
6+
}
7+
)
8+
object a
9+
extends b
10+
with c {
11+
def foo[
12+
T: Int#Double#Triple,
13+
R <% String
14+
](
15+
@annot1
16+
x: Int @annot2 =
17+
2,
18+
y: Int = 3
19+
): Int = {
20+
"match" match {
21+
case 1 | 2 =>
22+
3
23+
case <A>2</A> =>
24+
2
25+
}
26+
}
27+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
@foobar(
2+
"annot", {
3+
val x = 2
4+
val y = 2 // y=2
5+
x + y
6+
}
7+
)
8+
object a extends b with c {
9+
def foo[T: Int#Double#Triple, R <% String](
10+
@annot1
11+
x: Int @annot2 = 2,
12+
y: Int = 3
13+
): Int = {
14+
"match" match {
15+
case 1 | 2 =>
16+
3
17+
case <A>2</A> => 2
18+
}
19+
}
20+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
@foobar(
2+
"annot", {
3+
val x = 2
4+
val y = 2 // y=2
5+
x + y
6+
}
7+
)
8+
object a extends b with c {
9+
def foo[T: Int#Double#Triple, R <% String](
10+
@annot1
11+
x: Int @annot2 = 2,
12+
y: Int = 3
13+
): Int = {
14+
"match" match {
15+
case 1 | 2 =>
16+
3
17+
case <A>2</A> => 2
18+
}
19+
}
20+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
@foobar(
2+
"annot", {
3+
val x = 2
4+
val y = 2 // y=2
5+
x + y
6+
}
7+
)
8+
object a
9+
extends b
10+
with c {
11+
def foo[
12+
T: Int#Double#Triple,
13+
R <% String
14+
](
15+
@annot1
16+
x: Int @annot2 =
17+
2,
18+
y: Int = 3
19+
): Int = {
20+
"match" match {
21+
case 1 | 2 =>
22+
3
23+
case <A>2</A> =>
24+
2
25+
}
26+
}
27+
}

Diff for: testlib/src/test/java/com/diffplug/spotless/scala/ScalaFmtStepTest.java

+22
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ public void behaviorDefaultConfig() throws Exception {
3939
.testResource("scala/scalafmt/basic.dirty", "scala/scalafmt/basic.clean_1.1.0");
4040
StepHarness.forStep(ScalaFmtStep.create("2.0.1", TestProvisioner.mavenCentral(), null))
4141
.testResource("scala/scalafmt/basic.dirty", "scala/scalafmt/basic.clean_2.0.1");
42+
StepHarness.forStep(ScalaFmtStep.create("3.0.0", TestProvisioner.mavenCentral(), null))
43+
.testResource("scala/scalafmt/basic.dirty", "scala/scalafmt/basic.clean_3.0.0");
4244
}
4345

4446
@Test
@@ -47,6 +49,8 @@ public void behaviorCustomConfig() throws Exception {
4749
.testResource("scala/scalafmt/basic.dirty", "scala/scalafmt/basic.cleanWithCustomConf_1.1.0");
4850
StepHarness.forStep(ScalaFmtStep.create("2.0.1", TestProvisioner.mavenCentral(), createTestFile("scala/scalafmt/scalafmt.conf")))
4951
.testResource("scala/scalafmt/basic.dirty", "scala/scalafmt/basic.cleanWithCustomConf_2.0.1");
52+
StepHarness.forStep(ScalaFmtStep.create("3.0.0", TestProvisioner.mavenCentral(), createTestFile("scala/scalafmt/scalafmt.conf")))
53+
.testResource("scala/scalafmt/basic.dirty", "scala/scalafmt/basic.cleanWithCustomConf_3.0.0");
5054
}
5155

5256
@Test
@@ -63,6 +67,20 @@ public void behaviorCustomConfigVersion_2_0_0() throws Exception {
6367
.testResource("scala/scalafmt/basic.dirty", "scala/scalafmt/basicPost2.0.0.cleanWithCustomConf");
6468
}
6569

70+
@Test
71+
public void behaviorDefaultConfigVersion_3_0_0() throws Exception {
72+
FormatterStep step = ScalaFmtStep.create("3.0.0", TestProvisioner.mavenCentral(), null);
73+
StepHarness.forStep(step)
74+
.testResource("scala/scalafmt/basic.dirty", "scala/scalafmt/basicPost3.0.0.clean");
75+
}
76+
77+
@Test
78+
public void behaviorCustomConfigVersion_3_0_0() throws Exception {
79+
FormatterStep step = ScalaFmtStep.create("3.0.0", TestProvisioner.mavenCentral(), createTestFile("scala/scalafmt/scalafmt.conf"));
80+
StepHarness.forStep(step)
81+
.testResource("scala/scalafmt/basic.dirty", "scala/scalafmt/basicPost3.0.0.cleanWithCustomConf");
82+
}
83+
6684
@Test
6785
public void equality() throws Exception {
6886
new SerializableEqualityTester() {
@@ -106,5 +124,9 @@ public void invalidConfiguration() throws Exception {
106124
exception = assertThrows(InvocationTargetException.class,
107125
() -> StepHarness.forStep(ScalaFmtStep.create("2.0.1", provisioner, invalidConfFile)).test("", ""));
108126
assertThat(exception.getTargetException().getMessage(), containsString("Invalid field: invalidScalaFmtConfigField"));
127+
128+
exception = assertThrows(InvocationTargetException.class,
129+
() -> StepHarness.forStep(ScalaFmtStep.create("3.0.0", provisioner, invalidConfFile)).test("", ""));
130+
assertThat(exception.getTargetException().getMessage(), containsString("found option 'invalidScalaFmtConfigField' which wasn't expected"));
109131
}
110132
}

0 commit comments

Comments
 (0)