Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add config generator for custom rules (#5080)
* [WIP] Add config generator for custom rules * [WIP] Add config generator for custom rules * [WIP] Add config generator for custom rules * Fix tests for Windows * WIP * Fix handling filenames Co-authored-by: Brais Gabín <braisgabin@gmail.com> * Update tests Co-authored-by: Brais Gabín <braisgabin@gmail.com>
- Loading branch information
1 parent
0b9ff32
commit 1c3e62b
Showing
6 changed files
with
108 additions
and
3 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
59 changes: 59 additions & 0 deletions
59
...-generator/src/test/kotlin/io/gitlab/arturbosch/detekt/generator/printer/GeneratorSpec.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,59 @@ | ||
package io.gitlab.arturbosch.detekt.generator.printer | ||
|
||
import org.assertj.core.api.Assertions.assertThat | ||
import org.junit.jupiter.api.AfterAll | ||
import org.junit.jupiter.api.BeforeAll | ||
import org.junit.jupiter.api.Test | ||
import java.io.File | ||
import java.nio.file.Files | ||
import java.nio.file.Paths | ||
import kotlin.io.path.readText | ||
|
||
class GeneratorSpec { | ||
@Test | ||
fun `config files generated successfully`() { | ||
assertThat(Paths.get(tempDir1.toString(), configPath)).exists() | ||
assertThat(Paths.get(tempDir2.toString(), configPath)).exists() | ||
} | ||
|
||
@Test | ||
fun `config files have their own content`() { | ||
assertThat(Paths.get(tempDir1.toString(), configPath).readText()) | ||
.contains("complexity:") | ||
.doesNotContain("coroutines:") | ||
|
||
assertThat(Paths.get(tempDir2.toString(), configPath).readText()) | ||
.contains("coroutines:") | ||
.doesNotContain("complexity:") | ||
} | ||
|
||
companion object { | ||
private const val sourceDir1 = "../detekt-rules-complexity" | ||
private const val sourceDir2 = "../detekt-rules-coroutines" | ||
private const val configPath = "/src/main/resources/config/config.yml" | ||
|
||
private val tempDir1: File = Files.createTempDirectory(null).toFile() | ||
private val tempDir2: File = Files.createTempDirectory(null).toFile() | ||
|
||
@JvmStatic | ||
@BeforeAll | ||
fun init() { | ||
File(Paths.get(sourceDir1).toString()).copyRecursively(tempDir1) | ||
File(Paths.get(sourceDir2).toString()).copyRecursively(tempDir2) | ||
|
||
val args = arrayOf( | ||
"--generate-custom-rule-config", | ||
"--input", | ||
"$tempDir1, $tempDir2", | ||
) | ||
io.gitlab.arturbosch.detekt.generator.main(args) | ||
} | ||
|
||
@JvmStatic | ||
@AfterAll | ||
fun tearDown() { | ||
tempDir1.deleteRecursively() | ||
tempDir2.deleteRecursively() | ||
} | ||
} | ||
} |