diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index ec70ac61..c123c4f2 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -12,7 +12,7 @@ detekt-formatting = { module = "io.gitlab.arturbosch.detekt:detekt-formatting", ksp = { module = "com.google.devtools.ksp:symbol-processing-api", version.ref = "ksp" } kotlin-reflect = { module = "org.jetbrains.kotlin:kotlin-reflect", version.ref = "kotlin" } kotlin-test = { module = "org.jetbrains.kotlin:kotlin-test", version.ref = "kotlin" } -kotlin-compile-testing = { module = "dev.zacsweers.kctfork:ksp", version = "0.5.0" } +kotlin-compile-testing = { module = "dev.zacsweers.kctfork:ksp", version = "0.5.1" } kotlin-metadata-jvm = { module = "org.jetbrains.kotlin:kotlin-metadata-jvm", version.ref = "kotlin" } kotlinx-coroutines = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-core", version = "1.8.0" } kotlinx-atomicfu = { module = "org.jetbrains.kotlinx:atomicfu", version = "0.23.2" } diff --git a/kotlin-inject-compiler/test/src/main/kotlin/me/tatarka/inject/ProjectCompiler.kt b/kotlin-inject-compiler/test/src/main/kotlin/me/tatarka/inject/ProjectCompiler.kt index a136ea11..8284b9b4 100644 --- a/kotlin-inject-compiler/test/src/main/kotlin/me/tatarka/inject/ProjectCompiler.kt +++ b/kotlin-inject-compiler/test/src/main/kotlin/me/tatarka/inject/ProjectCompiler.kt @@ -4,6 +4,7 @@ package me.tatarka.inject import com.google.devtools.ksp.processing.SymbolProcessorProvider import com.tschuchort.compiletesting.CompilationResult +import com.tschuchort.compiletesting.DiagnosticSeverity import com.tschuchort.compiletesting.KotlinCompilation import com.tschuchort.compiletesting.SourceFile import com.tschuchort.compiletesting.kspProcessorOptions @@ -14,7 +15,6 @@ import me.tatarka.inject.compiler.ksp.InjectProcessorProvider import org.intellij.lang.annotations.Language import org.jetbrains.kotlin.compiler.plugin.ExperimentalCompilerApi import java.io.File -import javax.tools.Diagnostic class ProjectCompiler( private val target: Target, @@ -63,42 +63,12 @@ class ProjectCompiler( if (!result.success) { @Suppress("TooGenericExceptionThrown") - throw Exception(result.output(Diagnostic.Kind.ERROR)) + throw Exception(result.output(DiagnosticSeverity.ERROR)) } return result } } -private fun String.filterByKind(kind: Diagnostic.Kind): String = buildString { - var currentKind: Diagnostic.Kind? = null - for (line in this@filterByKind.lineSequence()) { - val lineKind = line.matchLine() - if (lineKind != null) { - currentKind = lineKind - } - if (currentKind == kind) { - append(line) - append('\n') - } - } -} - -private fun String.matchLine(): Diagnostic.Kind? { - if (length < 2) return null - val matchedKind = when (get(0)) { - 'e' -> Diagnostic.Kind.ERROR - 'w' -> Diagnostic.Kind.WARNING - 'v' -> Diagnostic.Kind.NOTE - else -> null - } ?: return null - - return if (get(1) == ':') { - matchedKind - } else { - null - } -} - enum class Target { KSP } @@ -108,5 +78,8 @@ class TestCompilationResult(private val result: CompilationResult) { get() = result.exitCode == KotlinCompilation.ExitCode.OK @OptIn(ExperimentalCompilerApi::class) - fun output(kind: Diagnostic.Kind): String = result.messages.filterByKind(kind) -} \ No newline at end of file + fun output(vararg severities: DiagnosticSeverity): String = when { + severities.isEmpty() -> result.messages + else -> result.messagesWithSeverity(*severities) + } +} diff --git a/kotlin-inject-compiler/test/src/test/kotlin/me/tatarka/inject/test/Utils.kt b/kotlin-inject-compiler/test/src/test/kotlin/me/tatarka/inject/test/Utils.kt index 7ed4abe5..04b7c81e 100644 --- a/kotlin-inject-compiler/test/src/test/kotlin/me/tatarka/inject/test/Utils.kt +++ b/kotlin-inject-compiler/test/src/test/kotlin/me/tatarka/inject/test/Utils.kt @@ -4,10 +4,10 @@ import assertk.Assert import assertk.assertions.isNotNull import assertk.assertions.message import assertk.assertions.prop +import com.tschuchort.compiletesting.DiagnosticSeverity import me.tatarka.inject.TestCompilationResult -import javax.tools.Diagnostic fun Assert.output(): Assert = message().isNotNull() fun Assert.warnings(): Assert = - prop("warnings") { it.output(Diagnostic.Kind.WARNING) } \ No newline at end of file + prop("warnings") { it.output(DiagnosticSeverity.WARNING) }