diff --git a/kotlin-power-assert-plugin/build.gradle.kts b/kotlin-power-assert-plugin/build.gradle.kts index a2afc707c67..73a2b43ab2a 100644 --- a/kotlin-power-assert-plugin/build.gradle.kts +++ b/kotlin-power-assert-plugin/build.gradle.kts @@ -18,6 +18,7 @@ dependencies { testImplementation(kotlin("test-junit5")) testImplementation("org.jetbrains.kotlin:kotlin-compiler-embeddable") testImplementation("com.github.tschuchortdev:kotlin-compile-testing:1.4.9") + testImplementation(enforcedPlatform("org.junit:junit-bom:5.9.1")) } tasks.withType { diff --git a/kotlin-power-assert-plugin/src/test/kotlin/com/bnorm/power/DebugFunctionTest.kt b/kotlin-power-assert-plugin/src/test/kotlin/com/bnorm/power/DebugFunctionTest.kt index bf2c63669ea..9ee7605cc41 100644 --- a/kotlin-power-assert-plugin/src/test/kotlin/com/bnorm/power/DebugFunctionTest.kt +++ b/kotlin-power-assert-plugin/src/test/kotlin/com/bnorm/power/DebugFunctionTest.kt @@ -19,11 +19,11 @@ package com.bnorm.power import com.tschuchort.compiletesting.KotlinCompilation import com.tschuchort.compiletesting.SourceFile import org.jetbrains.kotlin.name.FqName -import java.io.ByteArrayOutputStream -import java.io.PrintStream import java.lang.reflect.InvocationTargetException +import java.lang.reflect.Method import kotlin.test.Test import kotlin.test.assertEquals +import kotlin.test.fail class DebugFunctionTest { @Test @@ -71,7 +71,7 @@ private fun executeMainDebug(mainBody: String): String { fun dbg(value: T): T = value fun dbg(value: T, msg: String): T { - println(msg) + throw RuntimeException("result:"+msg) return value } @@ -87,15 +87,18 @@ fun main() { val kClazz = result.classLoader.loadClass("MainKt") val main = kClazz.declaredMethods.single { it.name == "main" && it.parameterCount == 0 } - val prevOut = System.out + return getMainResult(main) +} + +fun getMainResult(main: Method): String { try { - val out = ByteArrayOutputStream() - System.setOut(PrintStream(out)) main.invoke(null) - return out.toString("UTF-8") + fail("main did not throw expected exception") } catch (t: InvocationTargetException) { + with(t.cause) { + if (this is RuntimeException && message != null && message!!.startsWith("result:")) + return message!!.substringAfter("result:") + } throw t.cause!! - } finally { - System.setOut(prevOut) } } diff --git a/kotlin-power-assert-plugin/src/test/kotlin/com/bnorm/power/InfixFunctionTest.kt b/kotlin-power-assert-plugin/src/test/kotlin/com/bnorm/power/InfixFunctionTest.kt index 2adc69020c1..ae7dc8573f7 100644 --- a/kotlin-power-assert-plugin/src/test/kotlin/com/bnorm/power/InfixFunctionTest.kt +++ b/kotlin-power-assert-plugin/src/test/kotlin/com/bnorm/power/InfixFunctionTest.kt @@ -349,11 +349,11 @@ class InfixFunctionTest { ) } - private fun run(file: SourceFile, fqNames: Set): String { + private fun run(file: SourceFile, fqNames: Set, main: String = "MainKt"): String { val result = compile(listOf(file), PowerAssertComponentRegistrar(fqNames)) assertEquals(KotlinCompilation.ExitCode.OK, result.exitCode, "Failed with messages: " + result.messages) - val kClazz = result.classLoader.loadClass("MainKt") + val kClazz = result.classLoader.loadClass(main) val main = kClazz.declaredMethods.single { it.name == "main" && it.parameterCount == 0 } try { try { diff --git a/kotlin-power-assert-plugin/src/test/kotlin/com/bnorm/power/MultiParameterFunctionTest.kt b/kotlin-power-assert-plugin/src/test/kotlin/com/bnorm/power/MultiParameterFunctionTest.kt index 88072af6064..3900b7c0b28 100644 --- a/kotlin-power-assert-plugin/src/test/kotlin/com/bnorm/power/MultiParameterFunctionTest.kt +++ b/kotlin-power-assert-plugin/src/test/kotlin/com/bnorm/power/MultiParameterFunctionTest.kt @@ -19,9 +19,6 @@ package com.bnorm.power import com.tschuchort.compiletesting.KotlinCompilation import com.tschuchort.compiletesting.SourceFile import org.jetbrains.kotlin.name.FqName -import java.io.ByteArrayOutputStream -import java.io.PrintStream -import java.lang.reflect.InvocationTargetException import kotlin.test.Test import kotlin.test.assertEquals @@ -140,7 +137,7 @@ private fun executeMainDebug(mainBody: String): String { fun dbg(key: Any, value: T): T = value fun dbg(key: Any, value: T, msg: String): T { - println(key.toString() + "=" + value + "\n" + msg) + throw RuntimeException("result:"+key.toString() + "=" + value + "\n" + msg) return value } @@ -156,15 +153,5 @@ fun main() { val kClazz = result.classLoader.loadClass("MainKt") val main = kClazz.declaredMethods.single { it.name == "main" && it.parameterCount == 0 } - val prevOut = System.out - try { - val out = ByteArrayOutputStream() - System.setOut(PrintStream(out)) - main.invoke(null) - return out.toString("UTF-8") - } catch (t: InvocationTargetException) { - throw t.cause!! - } finally { - System.setOut(prevOut) - } + return getMainResult(main) } diff --git a/kotlin-power-assert-plugin/src/test/resources/junit-platform.properties b/kotlin-power-assert-plugin/src/test/resources/junit-platform.properties new file mode 100644 index 00000000000..cac17ac9c5d --- /dev/null +++ b/kotlin-power-assert-plugin/src/test/resources/junit-platform.properties @@ -0,0 +1,3 @@ +# suppress inspection "UnusedProperty" for whole file +junit.jupiter.execution.parallel.enabled = true +junit.jupiter.execution.parallel.mode.default = concurrent