diff --git a/core/src/main/kotlin/com/tschuchort/compiletesting/AbstractKotlinCompilation.kt b/core/src/main/kotlin/com/tschuchort/compiletesting/AbstractKotlinCompilation.kt index 60fcc732..0c3bfaf7 100644 --- a/core/src/main/kotlin/com/tschuchort/compiletesting/AbstractKotlinCompilation.kt +++ b/core/src/main/kotlin/com/tschuchort/compiletesting/AbstractKotlinCompilation.kt @@ -289,7 +289,9 @@ abstract class AbstractKotlinCompilation internal c override fun close() = messageOutputStream.close() }, internalMessageBuffer.outputStream() - ) + ), + /* autoFlush = */ false, + /* encoding = */ "UTF-8", ) protected fun log(s: String) { diff --git a/ksp/src/test/kotlin/com/tschuchort/compiletesting/KspTest.kt b/ksp/src/test/kotlin/com/tschuchort/compiletesting/KspTest.kt index 9ff4cc89..8b1cbd3a 100644 --- a/ksp/src/test/kotlin/com/tschuchort/compiletesting/KspTest.kt +++ b/ksp/src/test/kotlin/com/tschuchort/compiletesting/KspTest.kt @@ -14,6 +14,7 @@ import org.junit.runner.RunWith import org.junit.runners.JUnit4 import org.mockito.Mockito.`when` import java.util.concurrent.atomic.AtomicInteger +import kotlin.text.Typography.ellipsis @RunWith(JUnit4::class) class KspTest { @@ -322,6 +323,40 @@ class KspTest { assertThat(result.messages).contains("This is a failure") } + @Test + fun messagesAreEncodedAndDecodedWithUtf8() { + val annotation = SourceFile.kotlin( + "TestAnnotation.kt", """ + package foo.bar + annotation class TestAnnotation + """.trimIndent() + ) + val targetClass = SourceFile.kotlin( + "AppCode.kt", """ + package foo.bar + @TestAnnotation + class AppCode + """.trimIndent() + ) + val result = KotlinCompilation().apply { + sources = listOf(annotation, targetClass) + symbolProcessorProviders = listOf(processorProviderOf { env -> + object : AbstractTestSymbolProcessor(env.codeGenerator) { + override fun process(resolver: Resolver): List { + env.logger.logging("This is a log message with ellipsis $ellipsis") + env.logger.info("This is an info message with unicode \uD83D\uDCAB") + env.logger.warn("This is an warn message with emoji 🔥") + return emptyList() + } + } + }) + }.compile() + assertThat(result.exitCode).isEqualTo(ExitCode.OK) + assertThat(result.messages).contains("This is a log message with ellipsis $ellipsis") + assertThat(result.messages).contains("This is an info message with unicode \uD83D\uDCAB") + assertThat(result.messages).contains("This is an warn message with emoji 🔥") + } + companion object { private val DUMMY_KOTLIN_SRC = SourceFile.kotlin( "foo.bar.Dummy.kt", """