/
SuppressorsSpec.kt
89 lines (73 loc) · 3.06 KB
/
SuppressorsSpec.kt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
package io.gitlab.arturbosch.detekt.core.suppressors
import io.github.detekt.test.utils.compileContentForTest
import io.gitlab.arturbosch.detekt.api.CodeSmell
import io.gitlab.arturbosch.detekt.api.Config
import io.gitlab.arturbosch.detekt.api.Debt
import io.gitlab.arturbosch.detekt.api.Entity
import io.gitlab.arturbosch.detekt.api.Issue
import io.gitlab.arturbosch.detekt.api.Rule
import io.gitlab.arturbosch.detekt.api.Severity
import io.gitlab.arturbosch.detekt.test.TestConfig
import org.assertj.core.api.Assertions.assertThat
import org.jetbrains.kotlin.resolve.BindingContext
import org.junit.jupiter.api.Nested
import org.junit.jupiter.api.Test
class SuppressorsSpec {
val noIgnorableCodeSmell = CodeSmell(
issue = ARule().issue,
entity = Entity.from(compileContentForTest("""fun foo() = Unit""".trimIndent())),
message = ""
)
val ignorableCodeSmell = CodeSmell(
issue = ARule().issue,
entity = Entity.from(
compileContentForTest(
"""
@file:Composable
import androidx.compose.runtime.Composable
fun foo() = Unit
""".trimIndent()
)
),
message = ""
)
@Test
fun `A finding that should be suppressed`() {
val rule = ARule(TestConfig("ignoreAnnotated" to listOf("Composable")))
val suppress = getSuppressors(rule, BindingContext.EMPTY)
.fold(false) { acc, suppressor -> acc || suppressor.shouldSuppress(noIgnorableCodeSmell) }
assertThat(suppress).isFalse()
}
@Test
fun `A finding that should not be suppressed`() {
val rule = ARule(TestConfig("ignoreAnnotated" to listOf("Composable")))
val suppress = getSuppressors(rule, BindingContext.EMPTY)
.fold(false) { acc, suppressor -> acc || suppressor.shouldSuppress(ignorableCodeSmell) }
assertThat(suppress).isTrue()
}
@Nested
inner class `MultiRule` {
@Test
fun `A finding that should be suppressed`() {
val rule = AMultiRule(TestConfig("ignoreAnnotated" to listOf("Composable")))
val suppress = getSuppressors(rule, BindingContext.EMPTY)
.fold(false) { acc, suppressor -> acc || suppressor.shouldSuppress(noIgnorableCodeSmell) }
assertThat(suppress).isFalse()
}
@Test
fun `A finding that should not be suppressed`() {
val rule = AMultiRule(TestConfig("ignoreAnnotated" to listOf("Composable")))
val suppress = getSuppressors(rule, BindingContext.EMPTY)
.fold(false) { acc, suppressor -> acc || suppressor.shouldSuppress(ignorableCodeSmell) }
assertThat(suppress).isTrue()
}
}
}
private class AMultiRule(config: Config) :
@Suppress("DEPRECATION")
io.gitlab.arturbosch.detekt.api.MultiRule() {
override val rules: List<Rule> = listOf(ARule(config))
}
private class ARule(config: Config = Config.empty) : Rule(config) {
override val issue = Issue("IssueId", Severity.CodeSmell, "", Debt.TWENTY_MINS)
}