-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6dc13a5
commit ef45db7
Showing
2 changed files
with
213 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
195 changes: 195 additions & 0 deletions
195
ktlint-gradle-plugin/src/test/kotlin/io/github/usefulness/functional/BaselineTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,195 @@ | ||
package io.github.usefulness.functional | ||
|
||
import io.github.usefulness.functional.utils.kotlinClass | ||
import io.github.usefulness.functional.utils.resolve | ||
import io.github.usefulness.functional.utils.settingsFile | ||
import org.assertj.core.api.Assertions.assertThat | ||
import org.junit.jupiter.api.BeforeEach | ||
import org.junit.jupiter.api.Test | ||
import java.io.File | ||
|
||
class BaselineTest : WithGradleTest.Kotlin() { | ||
lateinit var projectRoot: File | ||
|
||
@BeforeEach | ||
fun setup() { | ||
projectRoot = testProjectDir.apply { | ||
resolve("settings.gradle") { writeText(settingsFile) } | ||
resolve("build.gradle") { | ||
// language=groovy | ||
writeText( | ||
""" | ||
plugins { | ||
id 'org.jetbrains.kotlin.jvm' | ||
id 'io.github.usefulness.ktlint-gradle-plugin' | ||
} | ||
ktlint { | ||
baselineFile.set(file('config/baseline.xml')) | ||
} | ||
repositories.mavenCentral() | ||
""".trimIndent(), | ||
) | ||
} | ||
resolve("src/main/kotlin/ClassOne.kt") { | ||
writeText(kotlinClass("ClassOne")) | ||
} | ||
} | ||
} | ||
|
||
@Test | ||
fun `lintKotlin respects baseline`() { | ||
projectRoot.resolve("src/main/kotlin/WithOffence.kt") { | ||
writeText(kotlinClass("InvalidName")) | ||
} | ||
projectRoot.resolve("src/main/kotlin/CustomClass.kt") { | ||
// language=kotlin | ||
val validClass = | ||
""" | ||
class CustomClass { | ||
private fun go(){ | ||
println("go") | ||
} | ||
} | ||
""".trimIndent() | ||
writeText(validClass) | ||
} | ||
projectRoot.resolve("config/baseline.xml") { | ||
// language=xml | ||
writeText( | ||
""" | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<baseline version="1.0"> | ||
<file name="src/main/kotlin/WithOffence.kt"> | ||
<error line="1" column="1" source="filename" /> | ||
</file> | ||
<file name="src/main/kotlin/CustomClass.kt"> | ||
<error line="2" column="21" source="curly-spacing" /> | ||
</file> | ||
</baseline> | ||
""".trimIndent(), | ||
) | ||
} | ||
|
||
build("lintKotlin").apply { | ||
assertThat(output).doesNotContain("Lint error >") | ||
} | ||
|
||
projectRoot.resolve("src/main/kotlin/CustomClass.kt") { | ||
// language=kotlin | ||
val validClass = | ||
""" | ||
class CustomClass { | ||
private fun go() { | ||
println("go") | ||
} | ||
} | ||
""".trimIndent() | ||
writeText(validClass) | ||
} | ||
buildAndFail("lintKotlin").apply { | ||
assertThat(output).contains("CustomClass.kt:2:22: Lint error > [no-multi-spaces]") | ||
} | ||
|
||
projectRoot.resolve("config/baseline.xml") { | ||
// language=xml | ||
writeText( | ||
""" | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<baseline version="1.0"> | ||
<file name="src/main/kotlin/WithOffence.kt"> | ||
<error line="1" column="1" source="filename" /> | ||
</file> | ||
<file name="src/main/kotlin/CustomClass.kt"> | ||
<error line="2" column="22" source="no-multi-spaces" /> | ||
</file> | ||
</baseline> | ||
""".trimIndent(), | ||
) | ||
} | ||
build("lintKotlin").apply { | ||
assertThat(output).doesNotContain("Lint error") | ||
} | ||
} | ||
|
||
@Test | ||
fun `formatKotlin doesn't respect baseline`() { | ||
projectRoot.resolve("src/main/kotlin/WithOffence.kt") { | ||
writeText(kotlinClass("InvalidName")) | ||
} | ||
projectRoot.resolve("src/main/kotlin/CustomClass.kt") { | ||
// language=kotlin | ||
val validClass = | ||
""" | ||
class CustomClass { | ||
private fun go(){ | ||
println("go") | ||
} | ||
} | ||
""".trimIndent() | ||
writeText(validClass) | ||
} | ||
projectRoot.resolve("config/baseline.xml") { | ||
// language=xml | ||
writeText( | ||
""" | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<baseline version="1.0"> | ||
<file name="src/main/kotlin/WithOffence.kt"> | ||
<error line="1" column="1" source="filename" /> | ||
</file> | ||
<file name="src/main/kotlin/CustomClass.kt"> | ||
<error line="2" column="21" source="curly-spacing" /> | ||
</file> | ||
</baseline> | ||
""".trimIndent(), | ||
) | ||
} | ||
build("formatKotlin").apply { | ||
assertThat(output).contains("CustomClass.kt:2:21: Format fixed > [curly-spacing]") | ||
} | ||
|
||
projectRoot.resolve("src/main/kotlin/CustomClass.kt") { | ||
// language=kotlin | ||
val validClass = | ||
""" | ||
class CustomClass { | ||
private fun go() { | ||
println("go") | ||
} | ||
} | ||
""".trimIndent() | ||
writeText(validClass) | ||
} | ||
|
||
projectRoot.resolve("config/baseline.xml") { | ||
// language=xml | ||
writeText( | ||
""" | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<baseline version="1.0"> | ||
<file name="src/main/kotlin/WithOffence.kt"> | ||
<error line="1" column="1" source="filename" /> | ||
</file> | ||
<file name="src/main/kotlin/CustomClass.kt"> | ||
<error line="2" column="22" source="no-multi-spaces" /> | ||
</file> | ||
</baseline> | ||
""".trimIndent(), | ||
) | ||
} | ||
build("formatKotlin").apply { | ||
assertThat(output).contains("CustomClass.kt:2:22: Format fixed > [no-multi-spaces]") | ||
} | ||
} | ||
} |