Skip to content

Commit

Permalink
Add more tests for Annotation Suppressor (#4774)
Browse files Browse the repository at this point in the history
* Add more tests for Annotation Suppressor

* Update detekt-core/src/test/kotlin/io/gitlab/arturbosch/detekt/core/suppressors/AnnotationSuppressorSpec.kt

Co-authored-by: Nicola Corti <corti.nico@gmail.com>

* Update detekt-core/src/test/kotlin/io/gitlab/arturbosch/detekt/core/suppressors/AnnotationSuppressorSpec.kt

Co-authored-by: Nicola Corti <corti.nico@gmail.com>

Co-authored-by: Nicola Corti <corti.nico@gmail.com>
  • Loading branch information
BraisGabin and cortinico committed Apr 25, 2022
1 parent ebe7b79 commit 6462745
Showing 1 changed file with 55 additions and 0 deletions.
Expand Up @@ -466,4 +466,59 @@ class AnnotationSuppressorSpec(private val env: KotlinCoreEnvironment) {
assertThat(suppressor.shouldSuppress(buildFinding(ktFunction))).isTrue()
}
}

@Nested
inner class `Annotation with parameters` {
val composableFiles = arrayOf(
compileContentForTest(
"""
package androidx.compose.runtime
annotation class Composable
""".trimIndent()
),
compileContentForTest(
"""
package androidx.compose.ui.tooling.preview
annotation class Preview(showBackground: Boolean = true)
""".trimIndent()
),
)

val root = compileContentForTest(
"""
import androidx.compose.runtime.Composable
import androidx.compose.ui.tooling.preview.Preview
@Composable
@Preview(showBackground = true)
fun function() = Unit
""".trimIndent()
)

@Test
fun `suppress if it has parameters with type solving`() {
val suppressor = annotationSuppressorFactory(
buildConfigAware("ignoreAnnotated" to listOf("Preview")),
env.getContextForPaths(listOf(root, *composableFiles)),
)!!

val ktFunction = root.findChildByClass(KtFunction::class.java)!!

assertThat(suppressor.shouldSuppress(buildFinding(ktFunction))).isTrue()
}

@Test
fun `suppress if it has parameters without type solving`() {
val suppressor = annotationSuppressorFactory(
buildConfigAware("ignoreAnnotated" to listOf("Preview")),
BindingContext.EMPTY,
)!!

val ktFunction = root.findChildByClass(KtFunction::class.java)!!

assertThat(suppressor.shouldSuppress(buildFinding(ktFunction))).isTrue()
}
}
}

0 comments on commit 6462745

Please sign in to comment.