Skip to content

Commit

Permalink
trim values when parsing the baseline (#4335)
Browse files Browse the repository at this point in the history
* Improve BaselineFilteredResultSpec

* Improve tests

* trim content so formatted baseline doesn't fails
  • Loading branch information
BraisGabin committed Nov 26, 2021
1 parent cb4772f commit 26fd459
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 13 deletions.
Expand Up @@ -33,8 +33,8 @@ internal class BaselineHandler : DefaultHandler() {
ID -> {
check(content.isNotBlank()) { "The content of the ID element must not be empty" }
when (current) {
MANUALLY_SUPPRESSED_ISSUES -> manuallySuppressedIssues.add(content)
CURRENT_ISSUES -> currentIssues.add(content)
MANUALLY_SUPPRESSED_ISSUES -> manuallySuppressedIssues.add(content.trim())
CURRENT_ISSUES -> currentIssues.add(content.trim())
}
content = ""
}
Expand Down
@@ -1,7 +1,6 @@
package io.gitlab.arturbosch.detekt.core.baseline

import io.github.detekt.test.utils.resourceAsPath
import io.gitlab.arturbosch.detekt.api.Finding
import io.gitlab.arturbosch.detekt.test.TestDetektion
import io.mockk.every
import io.mockk.mockk
Expand All @@ -15,26 +14,34 @@ class BaselineFilteredResultSpec : Spek({

val baselineFile = resourceAsPath("/baseline_feature/valid-baseline.xml")

val finding by memoized {
val issue = mockk<Finding>()
every { issue.id }.returns("LongParameterList")
every { issue.signature }.returns("Signature")
issue
val result by memoized {
TestDetektion(
mockk {
every { id }.returns("LongParameterList")
every { signature }.returns("Signature")
},
mockk {
every { id }.returns("LongMethod")
every { signature }.returns("Signature")
},
mockk {
every { id }.returns("FeatureEnvy")
every { signature }.returns("Signature")
},
)
}

val result by memoized { TestDetektion(finding) }

it("does return the same finding on empty baseline") {
val actual = BaselineFilteredResult(result, Baseline(emptySet(), emptySet()))
assertThat(actual.findings).hasSize(1)
assertThat(actual.findings).hasSize(3)
}

it("filters with an existing baseline file") {
val baseline = Baseline.load(baselineFile)
val actual = BaselineFilteredResult(result, baseline)
// Note: Detektion works with Map<RuleSetId, List<Finding>
// but the TestDetektion maps the RuleId as RuleSetId
assertThat(actual.findings["LongParameterList"]).isEmpty()
actual.findings.forEach { (_, value) -> assertThat(value).isEmpty() }
}
}
})
Expand Up @@ -5,6 +5,8 @@
<ID>LongMethod:Signature</ID>
</ManuallySuppressedIssues>
<CurrentIssues>
<ID>FeatureEnvy:Signature</ID>
<ID>
FeatureEnvy:Signature
</ID>
</CurrentIssues>
</SmellBaseline>

0 comments on commit 26fd459

Please sign in to comment.