Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Validate yaml configurations by comparing their structure - #516
- Loading branch information
1 parent
8daf49e
commit 05e6df8
Showing
8 changed files
with
191 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
60 changes: 60 additions & 0 deletions
60
detekt-api/src/test/kotlin/io/gitlab/arturbosch/detekt/api/internal/ConfigValidationSpec.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package io.gitlab.arturbosch.detekt.api.internal | ||
|
||
import io.gitlab.arturbosch.detekt.test.yamlConfig | ||
import org.assertj.core.api.Assertions.assertThat | ||
import org.spekframework.spek2.Spek | ||
import org.spekframework.spek2.style.specification.describe | ||
|
||
internal class ConfigValidationSpec : Spek({ | ||
|
||
describe("validate configuration file") { | ||
|
||
val baseline = yamlConfig("config_validation/baseline.yml") | ||
|
||
it("passes for same config test") { | ||
verifyConfig(baseline, baseline) | ||
} | ||
|
||
it("reports different rule set name") { | ||
val result = verifyConfig( | ||
yamlConfig("config_validation/other-ruleset-name.yml"), | ||
baseline | ||
) | ||
assertThat(result).contains(doesNotExistsMessage("code-smell")) | ||
} | ||
|
||
it("reports different nested property names") { | ||
val result = verifyConfig( | ||
yamlConfig("config_validation/other-nested-property-names.yml"), | ||
baseline | ||
) | ||
assertThat(result).contains( | ||
doesNotExistsMessage("complexity>LongLongMethod"), | ||
doesNotExistsMessage("complexity>LongParameterList>enabled"), | ||
doesNotExistsMessage("complexity>LargeClass>howMany"), | ||
doesNotExistsMessage("complexity>InnerMap>InnerKey"), | ||
doesNotExistsMessage("complexity>InnerMap>Inner2>nestedActive") | ||
) | ||
} | ||
|
||
it("reports different rule set name") { | ||
val result = verifyConfig( | ||
yamlConfig("config_validation/no-nested-config.yml"), | ||
baseline | ||
) | ||
assertThat(result).contains( | ||
nestedConfigExpectedMessage("complexity"), | ||
nestedConfigExpectedMessage("style>WildcardImport") | ||
) | ||
} | ||
|
||
it("reports unexpected nested configs") { | ||
// note that the baseline config is now the first argument | ||
val result = verifyConfig(baseline, yamlConfig("config_validation/no-value.yml")) | ||
assertThat(result).contains( | ||
unexpectedNestedConfigMessage("style"), | ||
unexpectedNestedConfigMessage("comments") | ||
) | ||
} | ||
} | ||
}) |
27 changes: 27 additions & 0 deletions
27
detekt-api/src/test/resources/config_validation/baseline.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
complexity: | ||
LongMethod: | ||
active: true | ||
threshold: 20 | ||
LongParameterList: | ||
active: false | ||
threshold: 5 | ||
LargeClass: | ||
active: false | ||
threshold: 70 | ||
InnerMap: | ||
Inner1: | ||
active: true | ||
Inner2: | ||
active: true | ||
|
||
style: | ||
WildcardImport: | ||
active: true | ||
NoElseInWhenExpression: | ||
active: true | ||
MagicNumber: | ||
active: true | ||
ignoreNumbers: '-1,0,1,2' | ||
|
||
comments: | ||
active: false |
4 changes: 4 additions & 0 deletions
4
detekt-api/src/test/resources/config_validation/no-nested-config.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
complexity: false | ||
|
||
style: | ||
WildcardImport: false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
complexity: | ||
style: | ||
comments: |
15 changes: 15 additions & 0 deletions
15
detekt-api/src/test/resources/config_validation/other-nested-property-names.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
complexity: | ||
LongLongMethod: | ||
active: true | ||
threshold: 20 | ||
LongParameterList: | ||
enabled: false | ||
threshold: 5 | ||
LargeClass: | ||
active: false | ||
howMany: 70 | ||
InnerMap: | ||
InnerKey: | ||
active: true | ||
Inner2: | ||
nestedActive: true |
15 changes: 15 additions & 0 deletions
15
detekt-api/src/test/resources/config_validation/other-ruleset-name.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
code-smell: | ||
LongMethod: | ||
active: true | ||
threshold: 20 | ||
LongParameterList: | ||
active: false | ||
threshold: 5 | ||
LargeClass: | ||
active: false | ||
threshold: 70 | ||
InnerMap: | ||
Inner1: | ||
active: true | ||
Inner2: | ||
active: true |
19 changes: 19 additions & 0 deletions
19
detekt-cli/src/test/kotlin/io/gitlab/arturbosch/detekt/cli/DefaultConfigValidationSpec.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package io.gitlab.arturbosch.detekt.cli | ||
|
||
import io.gitlab.arturbosch.detekt.api.internal.verifyConfig | ||
import io.gitlab.arturbosch.detekt.test.yamlConfig | ||
import org.assertj.core.api.Assertions.assertThat | ||
import org.spekframework.spek2.Spek | ||
import org.spekframework.spek2.style.specification.describe | ||
|
||
class DefaultConfigValidationSpec : Spek({ | ||
|
||
describe("default configuration is valid") { | ||
|
||
it("is valid comparing itself") { | ||
val baseline = yamlConfig("default-detekt-config.yml") | ||
val result = verifyConfig(baseline, baseline) | ||
assertThat(result).isEmpty() | ||
} | ||
} | ||
}) |