Skip to content
This repository has been archived by the owner on Mar 21, 2023. It is now read-only.

Commit

Permalink
fixed filenames with pascalCase convention in 0.46
Browse files Browse the repository at this point in the history
  • Loading branch information
fukusaka committed Dec 30, 2022
1 parent e1213d4 commit b2bcb6f
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,32 +30,32 @@ abstract class AbstractPluginTest {

protected
fun File.withCleanSources() = createSourceFile(
"src/main/kotlin/clean-source.kt",
"src/main/kotlin/$CLEAN_SOURCES_FILE",
"""
val foo = "bar"
""".trimIndent()
)

protected fun File.withCleanKotlinScript() = createSourceFile(
"kotlin-script.kts",
KOTLIN_SCRIPT_FILE,
"""
println("zzz")
""".trimIndent()
)

protected fun File.withFailingKotlinScript() = createSourceFile(
"kotlin-script-fail.kts",
KOTLIN_SCRIPT_FAIL_FILE,
"""
println("zzz")
println("zzz")
""".trimIndent()
)

protected
fun File.withAlternativeFailingSources(baseDir: String) =
createSourceFile("$baseDir/fail-source.kt", """val foo = "bar"""")
createSourceFile("$baseDir/$FAIL_SOURCE_FILE", """val foo = "bar"""")

protected
fun File.createSourceFile(sourceFilePath: String, contents: String) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class ConfigurationCacheTest : AbstractPluginTest() {
internal fun configurationCacheForCheckTask(gradleVersion: GradleVersion) {
project(gradleVersion) {
createSourceFile(
"src/main/kotlin/clean-source.kt",
"src/main/kotlin/$CLEAN_SOURCES_FILE",
"""
val foo = "bar"
Expand Down Expand Up @@ -51,7 +51,7 @@ class ConfigurationCacheTest : AbstractPluginTest() {
fun configurationCacheForFormatTasks(gradleVersion: GradleVersion) {
project(gradleVersion) {
createSourceFile(
"src/main/kotlin/clean-source.kt",
"src/main/kotlin/$CLEAN_SOURCES_FILE",
"""
val foo = "bar"
""".trimIndent()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class DisabledRulesTest : AbstractPluginTest() {
)

createSourceFile(
"src/main/kotlin/clean-source.kt",
"src/main/kotlin/$CLEAN_SOURCES_FILE",
"""
val foo = "bar"
""".trimIndent()
Expand All @@ -52,7 +52,7 @@ class DisabledRulesTest : AbstractPluginTest() {
)

createSourceFile(
"src/main/kotlin/clean-source.kt",
"src/main/kotlin/$CLEAN_SOURCES_FILE",
"""
fun some() {
print("Wait a minute!")
Expand All @@ -76,7 +76,7 @@ class DisabledRulesTest : AbstractPluginTest() {
fun lintRuleDisabledInTheCode(gradleVersion: GradleVersion) {
project(gradleVersion) {
createSourceFile(
"src/main/kotlin/clean-source.kt",
"src/main/kotlin/$CLEAN_SOURCES_FILE",
"""
/* ktlint-disable no-consecutive-blank-lines */
fun some() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import org.gradle.util.GradleVersion
import org.jlleitschuh.gradle.ktlint.tasks.GenerateBaselineTask
import org.jlleitschuh.gradle.ktlint.testdsl.CommonTest
import org.jlleitschuh.gradle.ktlint.testdsl.GradleTestVersions
import org.jlleitschuh.gradle.ktlint.testdsl.TestProject.Companion.FAIL_SOURCE_FILE
import org.jlleitschuh.gradle.ktlint.testdsl.build
import org.jlleitschuh.gradle.ktlint.testdsl.buildAndFail
import org.jlleitschuh.gradle.ktlint.testdsl.project
Expand Down Expand Up @@ -54,10 +53,11 @@ class KtlintBaselineSupportTest : AbstractPluginTest() {
"""
|<?xml version="1.0" encoding="utf-8"?>
|<baseline version="1.0">
| <file name="kotlin-script-fail.kts">
| <file name="$KOTLIN_SCRIPT_FAIL_FILE">
| <error line="1" column="15" source="no-trailing-spaces" />
| <error line="1" column="16" source="no-multi-spaces" />
| </file>
| <file name="src/main/kotlin/fail-source.kt">
| <file name="src/main/kotlin/$FAIL_SOURCE_FILE">
| <error line="1" column="5" source="no-multi-spaces" />
| <error line="1" column="10" source="no-multi-spaces" />
| <error line="1" column="15" source="no-multi-spaces" />
Expand All @@ -78,7 +78,7 @@ class KtlintBaselineSupportTest : AbstractPluginTest() {

build(GenerateBaselineTask.NAME)

removeSourceFile(FAIL_SOURCE_FILE)
removeSourceFile("src/main/kotlin/$FAIL_SOURCE_FILE")

build(GenerateBaselineTask.NAME) {
assertThat(task(":${GenerateBaselineTask.NAME}")?.outcome).isEqualTo(TaskOutcome.SUCCESS)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import org.jlleitschuh.gradle.ktlint.tasks.GenerateReportsTask
import org.jlleitschuh.gradle.ktlint.tasks.KtLintFormatTask
import org.jlleitschuh.gradle.ktlint.testdsl.CommonTest
import org.jlleitschuh.gradle.ktlint.testdsl.GradleTestVersions
import org.jlleitschuh.gradle.ktlint.testdsl.TestProject.Companion.FAIL_SOURCE_FILE
import org.jlleitschuh.gradle.ktlint.testdsl.build
import org.jlleitschuh.gradle.ktlint.testdsl.buildAndFail
import org.jlleitschuh.gradle.ktlint.testdsl.project
Expand Down Expand Up @@ -133,7 +132,7 @@ class KtlintPluginTest : AbstractPluginTest() {
buildGradle.appendText(
"""
ktlint.filter { exclude("**/fail-source.kt") }
ktlint.filter { exclude("**/$FAIL_SOURCE_FILE") }
""".trimIndent()
)

Expand Down Expand Up @@ -182,7 +181,7 @@ class KtlintPluginTest : AbstractPluginTest() {

build(FORMAT_PARENT_TASK_NAME) {
assertThat(task(":$formatTaskName")?.outcome).isEqualTo(TaskOutcome.SUCCESS)
assertThat(projectPath.resolve(FAIL_SOURCE_FILE)).exists()
assertThat(projectPath.resolve("src/main/kotlin/$FAIL_SOURCE_FILE")).exists()
}

build(CHECK_PARENT_TASK_NAME)
Expand Down Expand Up @@ -313,7 +312,7 @@ class KtlintPluginTest : AbstractPluginTest() {

build(
":$CHECK_PARENT_TASK_NAME",
"-P$FILTER_INCLUDE_PROPERTY_NAME=src/main/kotlin/clean-source.kt"
"-P$FILTER_INCLUDE_PROPERTY_NAME=src/main/kotlin/$CLEAN_SOURCES_FILE"
) {
assertThat(task(":$mainSourceSetCheckTaskName")?.outcome).isEqualTo(TaskOutcome.SUCCESS)
}
Expand All @@ -330,7 +329,7 @@ class KtlintPluginTest : AbstractPluginTest() {

build(
":$CHECK_PARENT_TASK_NAME",
"-P$FILTER_INCLUDE_PROPERTY_NAME=src\\main\\kotlin\\clean-source.kt"
"-P$FILTER_INCLUDE_PROPERTY_NAME=src\\main\\kotlin\\$CLEAN_SOURCES_FILE"
) {
assertThat(task(":$mainSourceSetCheckTaskName")?.outcome).isEqualTo(TaskOutcome.SUCCESS)
}
Expand All @@ -346,13 +345,13 @@ class KtlintPluginTest : AbstractPluginTest() {
buildGradle.appendText(
"""
ktlint.filter { exclude("**/fail-source.kt") }
ktlint.filter { exclude("**/$FAIL_SOURCE_FILE") }
""".trimIndent()
)

build(
":$CHECK_PARENT_TASK_NAME",
"-P$FILTER_INCLUDE_PROPERTY_NAME=src/main/kotlin/fail-source.kt"
"-P$FILTER_INCLUDE_PROPERTY_NAME=src/main/kotlin/$FAIL_SOURCE_FILE"
) {
assertThat(task(":$mainSourceSetCheckTaskName")?.outcome).isEqualTo(TaskOutcome.SKIPPED)
}
Expand All @@ -367,7 +366,7 @@ class KtlintPluginTest : AbstractPluginTest() {

build(
":$CHECK_PARENT_TASK_NAME",
"-P$FILTER_INCLUDE_PROPERTY_NAME=src/main/kotlin/failing-sources.kt"
"-P$FILTER_INCLUDE_PROPERTY_NAME=src/main/kotlin/$FAIL_SOURCE_FILE"
) {
assertThat(task(":$mainSourceSetCheckTaskName")?.outcome).isEqualTo(TaskOutcome.SKIPPED)
}
Expand Down Expand Up @@ -412,7 +411,7 @@ class KtlintPluginTest : AbstractPluginTest() {
@CommonTest
fun checkIsIncremental(gradleVersion: GradleVersion) {
project(gradleVersion) {
val initialSourceFile = "src/main/kotlin/initial.kt"
val initialSourceFile = "src/main/kotlin/initial.kt".toPascalCaseFilename()
createSourceFile(
initialSourceFile,
"""
Expand All @@ -425,7 +424,7 @@ class KtlintPluginTest : AbstractPluginTest() {
assertThat(task(":$mainSourceSetCheckTaskName")?.outcome).isEqualTo(TaskOutcome.SUCCESS)
}

val additionalSourceFile = "src/main/kotlin/another-file.kt"
val additionalSourceFile = "src/main/kotlin/another-file.kt".toPascalCaseFilename()
createSourceFile(
additionalSourceFile,
"""
Expand Down Expand Up @@ -474,13 +473,13 @@ class KtlintPluginTest : AbstractPluginTest() {
""".trimIndent()

val initialSourceFile = "src/main/kotlin/initial.kt"
val initialSourceFile = "src/main/kotlin/initial.kt".toPascalCaseFilename()
createSourceFile(initialSourceFile, passingContents)

val additionalSourceFile = "src/main/kotlin/another-file.kt"
val additionalSourceFile = "src/main/kotlin/another-file.kt".toPascalCaseFilename()
createSourceFile(additionalSourceFile, passingContents)

val testSourceFile = "src/test/kotlin/another-file.kt"
val testSourceFile = "src/test/kotlin/another-file.kt".toPascalCaseFilename()
createSourceFile(testSourceFile, failingContents)

build(mainSourceSetCheckTaskName) {
Expand Down Expand Up @@ -632,7 +631,7 @@ class KtlintPluginTest : AbstractPluginTest() {
val foo = "bar"
"""
)
val destinationFile = projectPath.resolve("src/main/kotlin/renamed-file.kt")
val destinationFile = projectPath.resolve("src/main/kotlin/renamed-file.kt".toPascalCaseFilename())
sourceFile.renameTo(destinationFile)

build(FORMAT_PARENT_TASK_NAME) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,12 @@ internal fun File.initGitWithoutHooksDir(): File {
assert(repo.directory.resolve("hooks").delete())
return repo.directory
}

private val snakeCaseFilenameRegex = "(?=[a-zA-Z-.]+\\Z)(?:\\A|(?<=/)|[_-])([a-zA-Z])".toRegex()

internal val CLEAN_SOURCES_FILE = "clean-source.kt".toPascalCaseFilename()
internal val FAIL_SOURCE_FILE = "fail-source.kt".toPascalCaseFilename()
internal val KOTLIN_SCRIPT_FILE = "kotlin-script.kts".toPascalCaseFilename()
internal val KOTLIN_SCRIPT_FAIL_FILE = "kotlin-script-fail.kts".toPascalCaseFilename()

internal fun String.toPascalCaseFilename(): String = replace(snakeCaseFilenameRegex) { it.groups[1]?.value?.toUpperCase() ?: "" }
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ import org.gradle.testkit.runner.BuildResult
import org.gradle.testkit.runner.GradleRunner
import org.gradle.util.GradleVersion
import org.jlleitschuh.gradle.ktlint.AbstractPluginTest
import org.jlleitschuh.gradle.ktlint.CLEAN_SOURCES_FILE
import org.jlleitschuh.gradle.ktlint.FAIL_SOURCE_FILE
import org.jlleitschuh.gradle.ktlint.KOTLIN_SCRIPT_FAIL_FILE
import org.jlleitschuh.gradle.ktlint.KOTLIN_SCRIPT_FILE
import java.io.File

fun AbstractPluginTest.project(
Expand Down Expand Up @@ -40,7 +44,7 @@ class TestProject(

fun withCleanSources() {
createSourceFile(
CLEAN_SOURCES_FILE,
"src/main/kotlin/$CLEAN_SOURCES_FILE",
"""
|val foo = "bar"
|
Expand All @@ -50,7 +54,7 @@ class TestProject(

fun withFailingSources() {
createSourceFile(
FAIL_SOURCE_FILE,
"src/main/kotlin/$FAIL_SOURCE_FILE",
"""
|val foo = "bar"
|
Expand All @@ -60,7 +64,7 @@ class TestProject(

fun withCleanKotlinScript() {
createSourceFile(
"kotlin-script.kts",
KOTLIN_SCRIPT_FILE,
"""
|println("zzz")
|
Expand All @@ -70,7 +74,7 @@ class TestProject(

fun withFailingKotlinScript() {
createSourceFile(
"kotlin-script-fail.kts",
KOTLIN_SCRIPT_FAIL_FILE,
"""
|println("zzz")@
|
Expand All @@ -89,7 +93,7 @@ class TestProject(
}

fun restoreFailingSources() {
val sourceFile = projectPath.resolve(FAIL_SOURCE_FILE)
val sourceFile = projectPath.resolve("src/main/kotlin/$FAIL_SOURCE_FILE")
sourceFile.delete()
withFailingSources()
}
Expand All @@ -98,11 +102,6 @@ class TestProject(
val sourceFile = projectPath.resolve(sourceFilePath)
sourceFile.delete()
}

companion object {
const val CLEAN_SOURCES_FILE = "src/main/kotlin/clean-source.kt"
const val FAIL_SOURCE_FILE = "src/main/kotlin/fail-source.kt"
}
}

fun TestProject.build(
Expand Down

0 comments on commit b2bcb6f

Please sign in to comment.