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:
Matthew Haughton
2022-04-10 18:36:09 +10:00
committed by GitHub
parent 2a513c4ef4
commit 2f959783c6
11 changed files with 101 additions and 77 deletions

View File

@@ -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

View File

@@ -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)

View File

@@ -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")
}
}
}
}
}

View File

@@ -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")
}
}
}
}
}