|
30 | 30 | import com.diffplug.spotless.TestProvisioner;
|
31 | 31 | import com.diffplug.spotless.antlr4.Antlr4FormatterStep;
|
32 | 32 |
|
33 |
| -public class Antlr4TaskTest extends ResourceHarness { |
| 33 | +public class Antlr4TaskTest extends GradleIntegrationHarness { |
34 | 34 |
|
35 | 35 | private Provisioner provisioner = TestProvisioner.mavenCentral();
|
36 | 36 |
|
37 |
| - private SpotlessTask checkTask; |
38 |
| - private SpotlessTask applyTask; |
39 |
| - |
40 |
| - @Before |
41 |
| - public void createTask() { |
42 |
| - Project project = ProjectBuilder.builder().build(); |
43 |
| - checkTask = project.getTasks().create("checkTaskUnderTest", SpotlessTask.class); |
44 |
| - checkTask.setCheck(); |
45 |
| - applyTask = project.getTasks().create("applyTaskUnderTest", SpotlessTask.class); |
46 |
| - applyTask.setApply(); |
47 |
| - } |
48 |
| - |
49 | 37 | @Test(expected = GradleException.class)
|
50 | 38 | public void testFormatCheckFail() throws Exception {
|
51 |
| - String unformatted = getTestResource("antlr4/Hello.unformatted.g4"); |
| 39 | + setFile("build.gradle").toLines( |
| 40 | + "buildscript { repositories { mavenCentral() } }", |
| 41 | + "plugins {", |
| 42 | + " id 'com.diffplug.gradle.spotless'", |
| 43 | + "}", |
| 44 | + "spotless {", |
| 45 | + " antlr4 {", |
| 46 | + " antlr4Formatter()", |
| 47 | + " }", |
| 48 | + "}"); |
52 | 49 |
|
53 |
| - checkTask.addStep(Antlr4FormatterStep.create(provisioner)); |
54 |
| - checkTask.setTarget(Collections.singleton(setFile("testFile.g4").toContent(unformatted))); |
55 |
| - execute(checkTask); |
| 50 | + setFile("src/main/antlr/Hello.g4").toResource("antlr4/Hello.unformatted.g4"); |
| 51 | + gradleRunner().withArguments("spotlessCheck").build(); |
56 | 52 | }
|
57 | 53 |
|
58 | 54 | @Test
|
59 | 55 | public void testFormatedCheckPass() throws Exception {
|
60 |
| - String formatted = getTestResource("antlr4/Hello.formatted.g4"); |
| 56 | + setFile("build.gradle").toLines( |
| 57 | + "buildscript { repositories { mavenCentral() } }", |
| 58 | + "plugins {", |
| 59 | + " id 'com.diffplug.gradle.spotless'", |
| 60 | + "}", |
| 61 | + "spotless {", |
| 62 | + " antlr4 {", |
| 63 | + " antlr4Formatter()", |
| 64 | + " }", |
| 65 | + "}"); |
61 | 66 |
|
62 |
| - checkTask.addStep(Antlr4FormatterStep.create(provisioner)); |
63 |
| - checkTask.setTarget(Collections.singleton(setFile("testFile.g4").toContent(formatted))); |
64 |
| - execute(checkTask); |
| 67 | + setFile("src/main/antlr/Hello.g4").toResource("antlr4/Hello.formatted.g4"); |
| 68 | + gradleRunner().withArguments("spotlessCheck").build(); |
65 | 69 | }
|
66 | 70 |
|
67 | 71 | @Test
|
68 | 72 | public void testFormatApplyPass() throws Exception {
|
69 |
| - String unformatted = getTestResource("antlr4/Hello.unformatted.g4"); |
70 |
| - String formatted = getTestResource("antlr4/Hello.formatted.g4"); |
71 |
| - String testFile = "testFile.g4"; |
72 |
| - |
73 |
| - applyTask.addStep(Antlr4FormatterStep.create(provisioner)); |
74 |
| - applyTask.setTarget(Collections.singleton(setFile(testFile).toContent(unformatted))); |
75 |
| - execute(applyTask); |
| 73 | + setFile("build.gradle").toLines( |
| 74 | + "buildscript { repositories { mavenCentral() } }", |
| 75 | + "plugins {", |
| 76 | + " id 'com.diffplug.gradle.spotless'", |
| 77 | + "}", |
| 78 | + "spotless {", |
| 79 | + " antlr4 {", |
| 80 | + " antlr4Formatter()", |
| 81 | + " }", |
| 82 | + "}"); |
76 | 83 |
|
77 |
| - assertFile(testFile).hasContent(formatted); |
| 84 | + setFile("src/main/antlr/Hello.g4").toResource("antlr4/Hello.unformatted.g4"); |
| 85 | + gradleRunner().withArguments("spotlessApply").build(); |
| 86 | + assertFile("src/main/antlr/Hello.g4").sameAsResource("antlr4/Hello.formatted.g4"); |
78 | 87 | }
|
79 | 88 | }
|
0 commit comments