mirror of
https://github.com/jlengrand/detekt.git
synced 2026-03-10 08:11:23 +00:00
Move tests requiring TestKit to functionalTest source set (#4700)
* Move ConfigurationCacheSpec to functionalTest * Move DetektAndroidSpec to functionalTest * Move DetektMultiplatformSpec to functionalTest * Move DetektPlainSpec to functionalTest * Move GradleVersionSpec to functionalTest * Move ReportMergeSpec to functionalTest * Move DetektTaskDslSpec to functionalTest * Move DetektJvmSpec tests that rely on TestKit to functionalTest * Don't make TestKit available to `test` source set * Exclude functionalTest sources from detekt rules that exclude test sources There are TooManyFunctions and SpreadOperator violations in functionalTest source set after the migration of rules from test source set in detekt-gradle-plugin, so exclusions were added to align with existing behavior.
This commit is contained in:
@@ -43,6 +43,8 @@ complexity:
|
||||
excludes: ['**/test/**', '**/*.Test.kt', '**/*.Spec.kt']
|
||||
MethodOverloading:
|
||||
active: true
|
||||
TooManyFunctions:
|
||||
excludes: ['**/test/**', '**/functionalTest/**']
|
||||
|
||||
coroutines:
|
||||
active: true
|
||||
@@ -129,6 +131,10 @@ naming:
|
||||
VariableMinLength:
|
||||
active: true
|
||||
|
||||
performance:
|
||||
SpreadOperator:
|
||||
excludes: ['**/test/**', '**/functionalTest/**']
|
||||
|
||||
potential-bugs:
|
||||
AvoidReferentialEquality:
|
||||
active: true
|
||||
|
||||
@@ -90,10 +90,15 @@ gradlePlugin {
|
||||
testSourceSets(
|
||||
sourceSets["testFixtures"],
|
||||
sourceSets["functionalTest"],
|
||||
sourceSets["test"]
|
||||
)
|
||||
}
|
||||
|
||||
// Some functional tests reference internal functions in the Gradle plugin. This should become unnecessary as further
|
||||
// updates are made to the functional test suite.
|
||||
kotlin.target.compilations.getByName("functionalTest") {
|
||||
associateWith(target.compilations.getByName("main"))
|
||||
}
|
||||
|
||||
// Manually inject dependency to gradle-testkit since the default injected plugin classpath is from `main.runtime`.
|
||||
tasks.pluginUnderTestMetadata {
|
||||
pluginClasspath.from(pluginCompileOnly)
|
||||
|
||||
@@ -0,0 +1,89 @@
|
||||
package io.gitlab.arturbosch.detekt
|
||||
|
||||
import io.gitlab.arturbosch.detekt.testkit.DslGradleRunner
|
||||
import io.gitlab.arturbosch.detekt.testkit.ProjectLayout
|
||||
import org.assertj.core.api.Assertions.assertThat
|
||||
import org.junit.jupiter.api.Nested
|
||||
import org.junit.jupiter.api.Test
|
||||
|
||||
class DetektJvmSpec {
|
||||
@Nested
|
||||
inner class `When applying detekt in a JVM project` {
|
||||
|
||||
@Nested
|
||||
inner class `report location set on extension & task` {
|
||||
val gradleRunner = DslGradleRunner(
|
||||
projectLayout = ProjectLayout(numberOfSourceFilesInRootPerSourceDir = 1),
|
||||
buildFileName = "build.gradle.kts",
|
||||
mainBuildFileContent = """
|
||||
plugins {
|
||||
kotlin("jvm")
|
||||
id("io.gitlab.arturbosch.detekt")
|
||||
}
|
||||
|
||||
repositories {
|
||||
mavenCentral()
|
||||
mavenLocal()
|
||||
}
|
||||
|
||||
detekt {
|
||||
reports {
|
||||
txt.destination = file("output-path.txt")
|
||||
}
|
||||
}
|
||||
|
||||
tasks.withType<io.gitlab.arturbosch.detekt.Detekt>().configureEach {
|
||||
reports {
|
||||
txt.destination = file("output-path2.txt")
|
||||
}
|
||||
}
|
||||
""".trimIndent(),
|
||||
dryRun = false
|
||||
).also {
|
||||
it.setupProject()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `logs a warning`() {
|
||||
gradleRunner.runTasksAndCheckResult(":detektMain") { buildResult ->
|
||||
assertThat(buildResult.output).contains("TXT report location set on detekt {} extension will be ignored for detektMain task.")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Nested
|
||||
inner class `report location set on task only` {
|
||||
val gradleRunner = DslGradleRunner(
|
||||
projectLayout = ProjectLayout(numberOfSourceFilesInRootPerSourceDir = 1),
|
||||
buildFileName = "build.gradle.kts",
|
||||
mainBuildFileContent = """
|
||||
plugins {
|
||||
kotlin("jvm")
|
||||
id("io.gitlab.arturbosch.detekt")
|
||||
}
|
||||
|
||||
repositories {
|
||||
mavenCentral()
|
||||
mavenLocal()
|
||||
}
|
||||
|
||||
tasks.withType<io.gitlab.arturbosch.detekt.Detekt>().configureEach {
|
||||
reports {
|
||||
txt.destination = file("output-path2.txt")
|
||||
}
|
||||
}
|
||||
""".trimIndent(),
|
||||
dryRun = false
|
||||
).also {
|
||||
it.setupProject()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `logs a warning`() {
|
||||
gradleRunner.runTasksAndCheckResult(":detektMain") { buildResult ->
|
||||
assertThat(buildResult.output).doesNotContain("report location set on detekt {} extension will be ignored")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -64,81 +64,5 @@ class DetektJvmSpec {
|
||||
assertThat(argumentString).contains("--classpath")
|
||||
}
|
||||
}
|
||||
|
||||
@Nested
|
||||
inner class `report location set on extension & task` {
|
||||
val gradleRunner = DslGradleRunner(
|
||||
projectLayout = ProjectLayout(numberOfSourceFilesInRootPerSourceDir = 1),
|
||||
buildFileName = "build.gradle.kts",
|
||||
mainBuildFileContent = """
|
||||
plugins {
|
||||
kotlin("jvm")
|
||||
id("io.gitlab.arturbosch.detekt")
|
||||
}
|
||||
|
||||
repositories {
|
||||
mavenCentral()
|
||||
mavenLocal()
|
||||
}
|
||||
|
||||
detekt {
|
||||
reports {
|
||||
txt.destination = file("output-path.txt")
|
||||
}
|
||||
}
|
||||
|
||||
tasks.withType<io.gitlab.arturbosch.detekt.Detekt>().configureEach {
|
||||
reports {
|
||||
txt.destination = file("output-path2.txt")
|
||||
}
|
||||
}
|
||||
""".trimIndent(),
|
||||
dryRun = false
|
||||
).also {
|
||||
it.setupProject()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `logs a warning`() {
|
||||
gradleRunner.runTasksAndCheckResult(":detektMain") { buildResult ->
|
||||
assertThat(buildResult.output).contains("TXT report location set on detekt {} extension will be ignored for detektMain task.")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Nested
|
||||
inner class `report location set on task only` {
|
||||
val gradleRunner = DslGradleRunner(
|
||||
projectLayout = ProjectLayout(numberOfSourceFilesInRootPerSourceDir = 1),
|
||||
buildFileName = "build.gradle.kts",
|
||||
mainBuildFileContent = """
|
||||
plugins {
|
||||
kotlin("jvm")
|
||||
id("io.gitlab.arturbosch.detekt")
|
||||
}
|
||||
|
||||
repositories {
|
||||
mavenCentral()
|
||||
mavenLocal()
|
||||
}
|
||||
|
||||
tasks.withType<io.gitlab.arturbosch.detekt.Detekt>().configureEach {
|
||||
reports {
|
||||
txt.destination = file("output-path2.txt")
|
||||
}
|
||||
}
|
||||
""".trimIndent(),
|
||||
dryRun = false
|
||||
).also {
|
||||
it.setupProject()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `logs a warning`() {
|
||||
gradleRunner.runTasksAndCheckResult(":detektMain") { buildResult ->
|
||||
assertThat(buildResult.output).doesNotContain("report location set on detekt {} extension will be ignored")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user