-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Validate warning names in config file on startup (#396)
### What's done: * Added validation logic * Added tests
- Loading branch information
Showing
11 changed files
with
119 additions
and
33 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
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
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
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
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
70 changes: 70 additions & 0 deletions
70
diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/smoke/RulesConfigValidationTest.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,70 @@ | ||
package org.cqfn.diktat.ruleset.smoke | ||
|
||
import com.charleskorn.kaml.InvalidPropertyValueException | ||
import org.cqfn.diktat.ruleset.rules.DiktatRuleSetProvider | ||
import org.junit.jupiter.api.AfterEach | ||
import org.junit.jupiter.api.Assertions | ||
import org.junit.jupiter.api.BeforeEach | ||
import org.junit.jupiter.api.Disabled | ||
import org.junit.jupiter.api.Test | ||
import org.junit.jupiter.api.assertThrows | ||
import java.io.File | ||
import java.lang.IllegalArgumentException | ||
|
||
class RulesConfigValidationTest { | ||
private lateinit var file: File | ||
|
||
@BeforeEach | ||
fun `prepare temporary file`() { | ||
file = createTempFile() | ||
} | ||
|
||
@AfterEach | ||
fun `clear temporary file`() { | ||
file.delete() | ||
} | ||
|
||
@Test | ||
fun `should throw error if name is missing in Warnings`() { | ||
file.writeText( | ||
""" | ||
|- name: MISSING_DOC_TOP_LEVEL | ||
| enabled: true | ||
| configuration: {} | ||
""".trimMargin() | ||
) | ||
val e = assertThrows<IllegalArgumentException> { | ||
DiktatRuleSetProvider(file.absolutePath).get() | ||
} | ||
Assertions.assertEquals("Warning name <MISSING_DOC_TOP_LEVEL> in configuration file is invalid, did you mean <MISSING_KDOC_TOP_LEVEL>?", e.message) | ||
} | ||
|
||
@Test | ||
fun `should throw error on invalid yml config`() { | ||
file.writeText( | ||
""" | ||
|- name: PACKAGE_NAME_MISSING | ||
| enabled: true | ||
| configuration: | ||
""".trimMargin() | ||
) | ||
assertThrows<InvalidPropertyValueException> { | ||
DiktatRuleSetProvider(file.absolutePath).get() | ||
} | ||
} | ||
|
||
@Test | ||
@Disabled("https://github.com/cqfn/diKTat/issues/395") | ||
fun `should throw error on invalid configuration section`() { | ||
file.writeText( | ||
""" | ||
|- name: TOO_LONG_FUNCTION | ||
| enabled: true | ||
| configuration: | ||
| maxFunctionLength: 1o | ||
| isIncludeHeader: Fslse | ||
""".trimMargin() | ||
) | ||
DiktatRuleSetProvider(file.absolutePath).get() | ||
} | ||
} |
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
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
6 changes: 1 addition & 5 deletions
6
diktat-rules/src/test/resources/test/smoke/src/main/kotlin/Bug1Expected.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
6 changes: 1 addition & 5 deletions
6
diktat-rules/src/test/resources/test/smoke/src/main/kotlin/Example1Expected.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
6 changes: 1 addition & 5 deletions
6
diktat-rules/src/test/resources/test/smoke/src/main/kotlin/Example2Expected.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
a9e5a56
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wasn't able to retrieve PDD puzzles from the code base and submit them to GitHub. If you think that it's a bug on our side, please submit it to yegor256/0pdd:
Please, copy and paste this stack trace to GitHub: