Skip to content

Commit

Permalink
Debug filtered paths for easier bug tracing - Closes #869 (#3022)
Browse files Browse the repository at this point in the history
  • Loading branch information
arturbosch committed Aug 29, 2020
1 parent 085adf0 commit 33bdaf4
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,5 +57,11 @@ class KtTreeCompiler(
return kotlinEnding in KT_ENDINGS
}

private fun isIgnored(path: Path): Boolean = pathFilters?.isIgnored(path) ?: false
private fun isIgnored(path: Path): Boolean {
val ignored = pathFilters?.isIgnored(path)
if (ignored == true) {
settings.debug { "Ignoring file '$path'" }
}
return ignored ?: false
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package io.gitlab.arturbosch.detekt.core

import io.github.detekt.test.utils.resource
import io.github.detekt.test.utils.NullPrintStream
import io.github.detekt.test.utils.resourceAsPath
import io.gitlab.arturbosch.detekt.core.tooling.withSettings
import org.assertj.core.api.Assertions.assertThat
import org.assertj.core.api.Assertions.assertThatIllegalArgumentException
Expand All @@ -20,7 +21,7 @@ class KtTreeCompilerSpec : Spek({
}

it("should filter the file 'Default.kt'") {
val ktFiles = fixture("**/Default.kt") { compile(path) }
val ktFiles = fixture("**/Default.kt", assertIgnoreMessage = true) { compile(path) }
val ktFile = ktFiles.find { it.name == "Default.kt" }
assertThat(ktFile).describedAs("It should have no Default.kt file").isNull()
}
Expand All @@ -47,13 +48,13 @@ class KtTreeCompilerSpec : Spek({
}

it("does not compile a folder with a css file") {
val cssPath = Paths.get(resource("css"))
val cssPath = resourceAsPath("css")
val ktFiles = fixture { compile(cssPath) }
assertThat(ktFiles).isEmpty()
}

it("does not compile a css file") {
val cssPath = Paths.get(resource("css")).resolve("test.css")
val cssPath = resourceAsPath("css").resolve("test.css")
val ktFiles = fixture { compile(cssPath) }
assertThat(ktFiles).isEmpty()
}
Expand All @@ -62,13 +63,25 @@ class KtTreeCompilerSpec : Spek({

internal inline fun <reified T> fixture(
vararg filters: String,
assertIgnoreMessage: Boolean = false,
crossinline block: KtTreeCompiler.() -> T
): T {
val channel = if (assertIgnoreMessage) StringBuilder() else NullPrintStream()
val spec = createNullLoggingSpec {
project {
inputPaths = listOf(path)
excludes = filters.toList()
}
logging {
debug = assertIgnoreMessage
outputChannel = channel
}
}
val result = spec.withSettings { block(KtTreeCompiler(this, spec.projectSpec)) }

if (assertIgnoreMessage) {
assertThat(channel.toString()).contains("Ignoring file ")
}
return spec.withSettings { block(KtTreeCompiler(this, spec.projectSpec)) }

return result
}

0 comments on commit 33bdaf4

Please sign in to comment.