|
| 1 | +/* |
| 2 | + * Copyright 2016 DiffPlug |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | +package com.diffplug.gradle.spotless; |
| 17 | + |
| 18 | +import java.io.IOException; |
| 19 | + |
| 20 | +import org.junit.Assert; |
| 21 | +import org.junit.Test; |
| 22 | + |
| 23 | +public class KotlinGradleExtensionTest extends GradleIntegrationTest { |
| 24 | + @Test |
| 25 | + public void integration() throws IOException { |
| 26 | + testInDirectory(null); |
| 27 | + } |
| 28 | + |
| 29 | + @Test |
| 30 | + public void integration_script_in_subdir() throws IOException { |
| 31 | + testInDirectory("companionScripts"); |
| 32 | + } |
| 33 | + |
| 34 | + private void testInDirectory(final String directory) throws IOException { |
| 35 | + write("build.gradle", |
| 36 | + "plugins {", |
| 37 | + " id 'nebula.kotlin' version '1.0.6'", |
| 38 | + " id 'com.diffplug.gradle.spotless'", |
| 39 | + "}", |
| 40 | + "repositories { mavenCentral() }", |
| 41 | + "spotless {", |
| 42 | + " kotlinGradle {", |
| 43 | + " ktlint()", |
| 44 | + " target '**/*.gradle.kts'", |
| 45 | + " }", |
| 46 | + "}"); |
| 47 | + String filePath = "configuration.gradle.kts"; |
| 48 | + if (directory != null) { |
| 49 | + filePath = directory + "/" + filePath; |
| 50 | + } |
| 51 | + write(filePath, |
| 52 | + getTestResource("kotlin/ktlint/basic.dirty")); |
| 53 | + gradleRunner().withArguments("spotlessApply").build(); |
| 54 | + String result = read(filePath); |
| 55 | + String formatted = getTestResource("kotlin/ktlint/basic.clean"); |
| 56 | + Assert.assertEquals(formatted, result); |
| 57 | + } |
| 58 | + |
| 59 | + @Test |
| 60 | + public void integration_default() throws IOException { |
| 61 | + write("build.gradle", |
| 62 | + "plugins {", |
| 63 | + " id 'nebula.kotlin' version '1.0.6'", |
| 64 | + " id 'com.diffplug.gradle.spotless'", |
| 65 | + "}", |
| 66 | + "repositories { mavenCentral() }", |
| 67 | + "spotless {", |
| 68 | + " kotlinGradle {", |
| 69 | + " ktlint()", |
| 70 | + " }", |
| 71 | + "}"); |
| 72 | + write("configuration.gradle.kts", |
| 73 | + getTestResource("kotlin/ktlint/basic.dirty")); |
| 74 | + gradleRunner().withArguments("spotlessApply").build(); |
| 75 | + String result = read("configuration.gradle.kts"); |
| 76 | + String formatted = getTestResource("kotlin/ktlint/basic.clean"); |
| 77 | + Assert.assertEquals(formatted, result); |
| 78 | + } |
| 79 | +} |
0 commit comments