Initial support for K2 compiler frontend (#92)
This commit is contained in:
+29
-1
@@ -1,3 +1,8 @@
|
|||||||
|
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
|
||||||
|
import org.jmailen.gradle.kotlinter.KotlinterPlugin
|
||||||
|
import org.jmailen.gradle.kotlinter.tasks.FormatTask
|
||||||
|
import org.jmailen.gradle.kotlinter.tasks.LintTask
|
||||||
|
|
||||||
plugins {
|
plugins {
|
||||||
kotlin("jvm") version "1.8.20" apply false
|
kotlin("jvm") version "1.8.20" apply false
|
||||||
id("org.jetbrains.dokka") version "1.8.10" apply false
|
id("org.jetbrains.dokka") version "1.8.10" apply false
|
||||||
@@ -11,8 +16,31 @@ allprojects {
|
|||||||
version = "0.13.0-SNAPSHOT"
|
version = "0.13.0-SNAPSHOT"
|
||||||
}
|
}
|
||||||
|
|
||||||
subprojects {
|
allprojects {
|
||||||
repositories {
|
repositories {
|
||||||
mavenCentral()
|
mavenCentral()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
tasks.withType<JavaCompile> {
|
||||||
|
sourceCompatibility = "1.8"
|
||||||
|
targetCompatibility = "1.8"
|
||||||
|
}
|
||||||
|
|
||||||
|
tasks.withType<KotlinCompile> {
|
||||||
|
kotlinOptions.jvmTarget = "1.8"
|
||||||
|
}
|
||||||
|
|
||||||
|
plugins.withType<KotlinterPlugin> {
|
||||||
|
val formatBuildscripts = tasks.register<FormatTask>("formatBuildscripts") {
|
||||||
|
group = "verification"
|
||||||
|
source(layout.projectDirectory.asFileTree.matching { include("**.kts") })
|
||||||
|
}
|
||||||
|
tasks.named("formatKotlin") { dependsOn(formatBuildscripts) }
|
||||||
|
|
||||||
|
val lintBuildscripts = tasks.register<LintTask>("lintBuildscripts") {
|
||||||
|
group = "verification"
|
||||||
|
source(layout.projectDirectory.asFileTree.matching { include("**.kts") })
|
||||||
|
}
|
||||||
|
tasks.named("lintKotlin") { dependsOn(lintBuildscripts) }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,3 @@
|
|||||||
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
|
|
||||||
import org.jmailen.gradle.kotlinter.tasks.FormatTask
|
|
||||||
import org.jmailen.gradle.kotlinter.tasks.LintTask
|
|
||||||
|
|
||||||
plugins {
|
plugins {
|
||||||
id("java-gradle-plugin")
|
id("java-gradle-plugin")
|
||||||
kotlin("jvm")
|
kotlin("jvm")
|
||||||
@@ -36,14 +32,6 @@ gradlePlugin {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
tasks.withType<JavaCompile> {
|
|
||||||
sourceCompatibility = "1.8"
|
|
||||||
targetCompatibility = "1.8"
|
|
||||||
}
|
|
||||||
|
|
||||||
tasks.withType<KotlinCompile> {
|
|
||||||
kotlinOptions.jvmTarget = "1.8"
|
|
||||||
}
|
|
||||||
|
|
||||||
tasks.named("publish") {
|
tasks.named("publish") {
|
||||||
dependsOn("publishPlugins")
|
dependsOn("publishPlugins")
|
||||||
@@ -57,14 +45,3 @@ publishing {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
tasks.register<FormatTask>("formatBuildscripts") {
|
|
||||||
group = "verification"
|
|
||||||
source(layout.projectDirectory.asFileTree.matching { include("**.kts") })
|
|
||||||
}
|
|
||||||
tasks.register<LintTask>("lintBuildscripts") {
|
|
||||||
group = "verification"
|
|
||||||
source(layout.projectDirectory.asFileTree.matching { include("**.kts") })
|
|
||||||
}
|
|
||||||
|
|
||||||
tasks.named("lintKotlin") { dependsOn("lintBuildscripts") }
|
|
||||||
tasks.named("formatKotlin") { dependsOn("formatBuildscripts") }
|
|
||||||
|
|||||||
@@ -1,6 +1,4 @@
|
|||||||
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
|
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
|
||||||
import org.jmailen.gradle.kotlinter.tasks.FormatTask
|
|
||||||
import org.jmailen.gradle.kotlinter.tasks.LintTask
|
|
||||||
|
|
||||||
plugins {
|
plugins {
|
||||||
kotlin("jvm")
|
kotlin("jvm")
|
||||||
@@ -25,12 +23,9 @@ dependencies {
|
|||||||
}
|
}
|
||||||
|
|
||||||
tasks.withType<KotlinCompile> {
|
tasks.withType<KotlinCompile> {
|
||||||
kotlinOptions.jvmTarget = "1.8"
|
kotlinOptions.freeCompilerArgs += listOf(
|
||||||
kotlinOptions.freeCompilerArgs = listOf("-opt-in=org.jetbrains.kotlin.backend.common.extensions.FirIncompatiblePluginAPI", "-opt-in=org.jetbrains.kotlin.compiler.plugin.ExperimentalCompilerApi")
|
"-opt-in=org.jetbrains.kotlin.compiler.plugin.ExperimentalCompilerApi",
|
||||||
}
|
)
|
||||||
tasks.withType<JavaCompile> {
|
|
||||||
sourceCompatibility = "1.8"
|
|
||||||
targetCompatibility = "1.8"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
tasks.withType<Test> {
|
tasks.withType<Test> {
|
||||||
@@ -117,14 +112,3 @@ publishing {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
tasks.register<FormatTask>("formatBuildscripts") {
|
|
||||||
group = "verification"
|
|
||||||
source(layout.projectDirectory.asFileTree.matching { include("**.kts") })
|
|
||||||
}
|
|
||||||
tasks.register<LintTask>("lintBuildscripts") {
|
|
||||||
group = "verification"
|
|
||||||
source(layout.projectDirectory.asFileTree.matching { include("**.kts") })
|
|
||||||
}
|
|
||||||
|
|
||||||
tasks.named("lintKotlin") { dependsOn("lintBuildscripts") }
|
|
||||||
tasks.named("formatKotlin") { dependsOn("formatBuildscripts") }
|
|
||||||
|
|||||||
+21
-5
@@ -30,6 +30,7 @@ import com.bnorm.power.diagram.irDiagramString
|
|||||||
import org.jetbrains.kotlin.backend.common.IrElementTransformerVoidWithContext
|
import org.jetbrains.kotlin.backend.common.IrElementTransformerVoidWithContext
|
||||||
import org.jetbrains.kotlin.backend.common.extensions.IrPluginContext
|
import org.jetbrains.kotlin.backend.common.extensions.IrPluginContext
|
||||||
import org.jetbrains.kotlin.backend.common.lower.DeclarationIrBuilder
|
import org.jetbrains.kotlin.backend.common.lower.DeclarationIrBuilder
|
||||||
|
import org.jetbrains.kotlin.backend.jvm.ir.parentClassId
|
||||||
import org.jetbrains.kotlin.cli.common.messages.CompilerMessageSeverity
|
import org.jetbrains.kotlin.cli.common.messages.CompilerMessageSeverity
|
||||||
import org.jetbrains.kotlin.cli.common.messages.MessageCollector
|
import org.jetbrains.kotlin.cli.common.messages.MessageCollector
|
||||||
import org.jetbrains.kotlin.ir.IrElement
|
import org.jetbrains.kotlin.ir.IrElement
|
||||||
@@ -37,6 +38,7 @@ import org.jetbrains.kotlin.ir.backend.js.utils.asString
|
|||||||
import org.jetbrains.kotlin.ir.builders.irCall
|
import org.jetbrains.kotlin.ir.builders.irCall
|
||||||
import org.jetbrains.kotlin.ir.builders.irString
|
import org.jetbrains.kotlin.ir.builders.irString
|
||||||
import org.jetbrains.kotlin.ir.builders.parent
|
import org.jetbrains.kotlin.ir.builders.parent
|
||||||
|
import org.jetbrains.kotlin.ir.declarations.IrClass
|
||||||
import org.jetbrains.kotlin.ir.declarations.IrFunction
|
import org.jetbrains.kotlin.ir.declarations.IrFunction
|
||||||
import org.jetbrains.kotlin.ir.declarations.IrValueParameter
|
import org.jetbrains.kotlin.ir.declarations.IrValueParameter
|
||||||
import org.jetbrains.kotlin.ir.expressions.IrCall
|
import org.jetbrains.kotlin.ir.expressions.IrCall
|
||||||
@@ -57,11 +59,14 @@ import org.jetbrains.kotlin.ir.types.classifierOrNull
|
|||||||
import org.jetbrains.kotlin.ir.types.isBoolean
|
import org.jetbrains.kotlin.ir.types.isBoolean
|
||||||
import org.jetbrains.kotlin.ir.types.isSubtypeOf
|
import org.jetbrains.kotlin.ir.types.isSubtypeOf
|
||||||
import org.jetbrains.kotlin.ir.types.isSubtypeOfClass
|
import org.jetbrains.kotlin.ir.types.isSubtypeOfClass
|
||||||
|
import org.jetbrains.kotlin.ir.util.classId
|
||||||
import org.jetbrains.kotlin.ir.util.deepCopyWithSymbols
|
import org.jetbrains.kotlin.ir.util.deepCopyWithSymbols
|
||||||
import org.jetbrains.kotlin.ir.util.functions
|
import org.jetbrains.kotlin.ir.util.functions
|
||||||
|
import org.jetbrains.kotlin.ir.util.isFileClass
|
||||||
import org.jetbrains.kotlin.ir.util.isFunctionOrKFunction
|
import org.jetbrains.kotlin.ir.util.isFunctionOrKFunction
|
||||||
import org.jetbrains.kotlin.ir.util.kotlinFqName
|
import org.jetbrains.kotlin.ir.util.kotlinFqName
|
||||||
import org.jetbrains.kotlin.ir.util.parentClassOrNull
|
import org.jetbrains.kotlin.name.CallableId
|
||||||
|
import org.jetbrains.kotlin.name.ClassId
|
||||||
import org.jetbrains.kotlin.name.FqName
|
import org.jetbrains.kotlin.name.FqName
|
||||||
|
|
||||||
class PowerAssertCallTransformer(
|
class PowerAssertCallTransformer(
|
||||||
@@ -215,13 +220,13 @@ class PowerAssertCallTransformer(
|
|||||||
|
|
||||||
// Java static functions require searching by class
|
// Java static functions require searching by class
|
||||||
val parentClassFunctions = (
|
val parentClassFunctions = (
|
||||||
function.parentClassOrNull
|
function.parentClassId
|
||||||
?.let { context.referenceClass(it.kotlinFqName) }
|
?.let { context.referenceClass(it) }
|
||||||
?.functions ?: emptySequence()
|
?.functions ?: emptySequence()
|
||||||
)
|
)
|
||||||
.filter { it.owner.kotlinFqName == function.kotlinFqName }
|
.filter { it.owner.kotlinFqName == function.kotlinFqName }
|
||||||
.toList()
|
.toList()
|
||||||
val possible = (context.referenceFunctions(function.kotlinFqName) + parentClassFunctions)
|
val possible = (context.referenceFunctions(function.callableId) + parentClassFunctions)
|
||||||
.distinct()
|
.distinct()
|
||||||
|
|
||||||
return possible.mapNotNull { overload ->
|
return possible.mapNotNull { overload ->
|
||||||
@@ -256,7 +261,7 @@ class PowerAssertCallTransformer(
|
|||||||
type.isFunctionOrKFunction() && type is IrSimpleType && (type.arguments.size == 1 && isStringSupertype(type.arguments.first()))
|
type.isFunctionOrKFunction() && type is IrSimpleType && (type.arguments.size == 1 && isStringSupertype(type.arguments.first()))
|
||||||
|
|
||||||
private fun isStringJavaSupplierFunction(type: IrType): Boolean {
|
private fun isStringJavaSupplierFunction(type: IrType): Boolean {
|
||||||
val javaSupplier = context.referenceClass(FqName("java.util.function.Supplier"))
|
val javaSupplier = context.referenceClass(ClassId.topLevel(FqName("java.util.function.Supplier")))
|
||||||
return javaSupplier != null && type.isSubtypeOfClass(javaSupplier) &&
|
return javaSupplier != null && type.isSubtypeOfClass(javaSupplier) &&
|
||||||
type is IrSimpleType && (type.arguments.size == 1 && isStringSupertype(type.arguments.first()))
|
type is IrSimpleType && (type.arguments.size == 1 && isStringSupertype(type.arguments.first()))
|
||||||
}
|
}
|
||||||
@@ -289,3 +294,14 @@ class PowerAssertCallTransformer(
|
|||||||
report(severity, message, sourceFile.getCompilerMessageLocation(expression))
|
report(severity, message, sourceFile.getCompilerMessageLocation(expression))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
val IrFunction.callableId: CallableId
|
||||||
|
get() {
|
||||||
|
val parentClass = parent as? IrClass
|
||||||
|
val classId = parentClass?.classId
|
||||||
|
return if (classId != null && !parentClass.isFileClass) {
|
||||||
|
CallableId(classId, name)
|
||||||
|
} else {
|
||||||
|
CallableId(parent.kotlinFqName, name)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
+8
-10
@@ -20,29 +20,27 @@ import com.google.auto.service.AutoService
|
|||||||
import org.jetbrains.kotlin.backend.common.extensions.IrGenerationExtension
|
import org.jetbrains.kotlin.backend.common.extensions.IrGenerationExtension
|
||||||
import org.jetbrains.kotlin.cli.common.CLIConfigurationKeys
|
import org.jetbrains.kotlin.cli.common.CLIConfigurationKeys
|
||||||
import org.jetbrains.kotlin.cli.common.messages.MessageCollector
|
import org.jetbrains.kotlin.cli.common.messages.MessageCollector
|
||||||
import org.jetbrains.kotlin.com.intellij.mock.MockProject
|
import org.jetbrains.kotlin.compiler.plugin.CompilerPluginRegistrar
|
||||||
import org.jetbrains.kotlin.compiler.plugin.ComponentRegistrar
|
|
||||||
import org.jetbrains.kotlin.config.CompilerConfiguration
|
import org.jetbrains.kotlin.config.CompilerConfiguration
|
||||||
import org.jetbrains.kotlin.config.CompilerConfigurationKey
|
import org.jetbrains.kotlin.config.CompilerConfigurationKey
|
||||||
import org.jetbrains.kotlin.name.FqName
|
import org.jetbrains.kotlin.name.FqName
|
||||||
|
|
||||||
val KEY_FUNCTIONS = CompilerConfigurationKey<List<String>>("fully-qualified function names")
|
val KEY_FUNCTIONS = CompilerConfigurationKey<List<String>>("fully-qualified function names")
|
||||||
|
|
||||||
@AutoService(ComponentRegistrar::class)
|
@AutoService(CompilerPluginRegistrar::class)
|
||||||
class PowerAssertComponentRegistrar(
|
class PowerAssertCompilerPluginRegistrar(
|
||||||
private val functions: Set<FqName>,
|
private val functions: Set<FqName>,
|
||||||
) : ComponentRegistrar {
|
) : CompilerPluginRegistrar() {
|
||||||
@Suppress("unused")
|
@Suppress("unused")
|
||||||
constructor() : this(emptySet()) // Used by service loader
|
constructor() : this(emptySet()) // Used by service loader
|
||||||
|
|
||||||
override fun registerProjectComponents(
|
override val supportsK2: Boolean = true
|
||||||
project: MockProject,
|
|
||||||
configuration: CompilerConfiguration,
|
override fun ExtensionStorage.registerExtensions(configuration: CompilerConfiguration) {
|
||||||
) {
|
|
||||||
val functions = configuration[KEY_FUNCTIONS]?.map { FqName(it) } ?: functions
|
val functions = configuration[KEY_FUNCTIONS]?.map { FqName(it) } ?: functions
|
||||||
if (functions.isEmpty()) return
|
if (functions.isEmpty()) return
|
||||||
|
|
||||||
val messageCollector = configuration.get(CLIConfigurationKeys.MESSAGE_COLLECTOR_KEY, MessageCollector.NONE)
|
val messageCollector = configuration.get(CLIConfigurationKeys.MESSAGE_COLLECTOR_KEY, MessageCollector.NONE)
|
||||||
IrGenerationExtension.registerExtension(project, PowerAssertIrGenerationExtension(messageCollector, functions.toSet()))
|
IrGenerationExtension.registerExtension(PowerAssertIrGenerationExtension(messageCollector, functions.toSet()))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -369,7 +369,7 @@ assertTrue(1 == 2, message = "${"$"}text, the world is broken")
|
|||||||
|
|
|
|
||||||
false
|
false
|
||||||
""".trimIndent(),
|
""".trimIndent(),
|
||||||
PowerAssertComponentRegistrar(setOf(FqName("kotlin.test.assertTrue"))),
|
PowerAssertCompilerPluginRegistrar(setOf(FqName("kotlin.test.assertTrue"))),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -386,7 +386,7 @@ require(1 == 2) { "the world is broken" }
|
|||||||
|
|
|
|
||||||
false
|
false
|
||||||
""".trimIndent(),
|
""".trimIndent(),
|
||||||
PowerAssertComponentRegistrar(setOf(FqName("kotlin.require"))),
|
PowerAssertCompilerPluginRegistrar(setOf(FqName("kotlin.require"))),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -403,7 +403,7 @@ check(1 == 2) { "the world is broken" }
|
|||||||
|
|
|
|
||||||
false
|
false
|
||||||
""".trimIndent(),
|
""".trimIndent(),
|
||||||
PowerAssertComponentRegistrar(setOf(FqName("kotlin.check"))),
|
PowerAssertCompilerPluginRegistrar(setOf(FqName("kotlin.check"))),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -19,24 +19,23 @@ package com.bnorm.power
|
|||||||
import com.tschuchort.compiletesting.KotlinCompilation
|
import com.tschuchort.compiletesting.KotlinCompilation
|
||||||
import com.tschuchort.compiletesting.SourceFile
|
import com.tschuchort.compiletesting.SourceFile
|
||||||
import org.intellij.lang.annotations.Language
|
import org.intellij.lang.annotations.Language
|
||||||
import org.jetbrains.kotlin.compiler.plugin.ComponentRegistrar
|
import org.jetbrains.kotlin.compiler.plugin.CompilerPluginRegistrar
|
||||||
import org.jetbrains.kotlin.name.FqName
|
import org.jetbrains.kotlin.name.FqName
|
||||||
import java.io.OutputStream
|
import java.io.OutputStream
|
||||||
import java.lang.reflect.InvocationTargetException
|
import java.lang.reflect.InvocationTargetException
|
||||||
import kotlin.test.assertEquals
|
import kotlin.test.assertEquals
|
||||||
import kotlin.test.fail
|
import kotlin.test.fail
|
||||||
|
|
||||||
private val DEFAULT_COMPONENT_REGISTRARS = arrayOf(
|
private val DEFAULT_COMPILER_PLUGIN_REGISTRARS = arrayOf(
|
||||||
PowerAssertComponentRegistrar(setOf(FqName("kotlin.assert"))),
|
PowerAssertCompilerPluginRegistrar(setOf(FqName("kotlin.assert"))),
|
||||||
)
|
)
|
||||||
|
|
||||||
fun compile(
|
fun compile(
|
||||||
list: List<SourceFile>,
|
list: List<SourceFile>,
|
||||||
vararg componentRegistrars: ComponentRegistrar = DEFAULT_COMPONENT_REGISTRARS,
|
vararg compilerPluginRegistrars: CompilerPluginRegistrar = DEFAULT_COMPILER_PLUGIN_REGISTRARS,
|
||||||
): KotlinCompilation.Result {
|
): KotlinCompilation.Result {
|
||||||
return KotlinCompilation().apply {
|
return KotlinCompilation().apply {
|
||||||
sources = list
|
sources = list
|
||||||
useIR = true
|
|
||||||
messageOutputStream = object : OutputStream() {
|
messageOutputStream = object : OutputStream() {
|
||||||
override fun write(b: Int) {
|
override fun write(b: Int) {
|
||||||
// black hole all writes
|
// black hole all writes
|
||||||
@@ -46,18 +45,18 @@ fun compile(
|
|||||||
// black hole all writes
|
// black hole all writes
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
this.componentRegistrars = componentRegistrars.toList()
|
this.compilerPluginRegistrars = compilerPluginRegistrars.toList()
|
||||||
inheritClassPath = true
|
inheritClassPath = true
|
||||||
}.compile()
|
}.compile()
|
||||||
}
|
}
|
||||||
|
|
||||||
fun executeAssertion(
|
fun executeAssertion(
|
||||||
@Language("kotlin") source: String,
|
@Language("kotlin") source: String,
|
||||||
vararg plugins: ComponentRegistrar = DEFAULT_COMPONENT_REGISTRARS,
|
vararg compilerPluginRegistrars: CompilerPluginRegistrar = DEFAULT_COMPILER_PLUGIN_REGISTRARS,
|
||||||
): String {
|
): String {
|
||||||
val result = compile(
|
val result = compile(
|
||||||
listOf(SourceFile.kotlin("main.kt", source, trimIndent = false)),
|
listOf(SourceFile.kotlin("main.kt", source, trimIndent = false)),
|
||||||
*plugins,
|
*compilerPluginRegistrars,
|
||||||
)
|
)
|
||||||
assertEquals(KotlinCompilation.ExitCode.OK, result.exitCode, result.messages)
|
assertEquals(KotlinCompilation.ExitCode.OK, result.exitCode, result.messages)
|
||||||
|
|
||||||
@@ -86,8 +85,8 @@ fun main() {
|
|||||||
fun assertMessage(
|
fun assertMessage(
|
||||||
@Language("kotlin") source: String,
|
@Language("kotlin") source: String,
|
||||||
message: String,
|
message: String,
|
||||||
vararg plugins: ComponentRegistrar = DEFAULT_COMPONENT_REGISTRARS,
|
vararg compilerPluginRegistrars: CompilerPluginRegistrar = DEFAULT_COMPILER_PLUGIN_REGISTRARS,
|
||||||
) {
|
) {
|
||||||
val actual = executeAssertion(source, *plugins)
|
val actual = executeAssertion(source, *compilerPluginRegistrars)
|
||||||
assertEquals(message, actual)
|
assertEquals(message, actual)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -82,7 +82,7 @@ fun main() {
|
|||||||
trimIndent = false,
|
trimIndent = false,
|
||||||
)
|
)
|
||||||
|
|
||||||
val result = compile(listOf(file), PowerAssertComponentRegistrar(setOf(FqName("dbg"))))
|
val result = compile(listOf(file), PowerAssertCompilerPluginRegistrar(setOf(FqName("dbg"))))
|
||||||
assertEquals(KotlinCompilation.ExitCode.OK, result.exitCode)
|
assertEquals(KotlinCompilation.ExitCode.OK, result.exitCode)
|
||||||
|
|
||||||
val kClazz = result.classLoader.loadClass("MainKt")
|
val kClazz = result.classLoader.loadClass("MainKt")
|
||||||
|
|||||||
@@ -350,7 +350,7 @@ class InfixFunctionTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun run(file: SourceFile, fqNames: Set<FqName>, main: String = "MainKt"): String {
|
private fun run(file: SourceFile, fqNames: Set<FqName>, main: String = "MainKt"): String {
|
||||||
val result = compile(listOf(file), PowerAssertComponentRegistrar(fqNames))
|
val result = compile(listOf(file), PowerAssertCompilerPluginRegistrar(fqNames))
|
||||||
assertEquals(KotlinCompilation.ExitCode.OK, result.exitCode, "Failed with messages: " + result.messages)
|
assertEquals(KotlinCompilation.ExitCode.OK, result.exitCode, "Failed with messages: " + result.messages)
|
||||||
|
|
||||||
val kClazz = result.classLoader.loadClass(main)
|
val kClazz = result.classLoader.loadClass(main)
|
||||||
|
|||||||
+15
-15
@@ -35,7 +35,7 @@ class Junit5AssertionsTest {
|
|||||||
|
|
|
|
||||||
false ==> expected: <true> but was: <false>
|
false ==> expected: <true> but was: <false>
|
||||||
""".trimIndent(),
|
""".trimIndent(),
|
||||||
PowerAssertComponentRegistrar(setOf(FqName("org.junit.jupiter.api.Assertions.assertTrue"))),
|
PowerAssertCompilerPluginRegistrar(setOf(FqName("org.junit.jupiter.api.Assertions.assertTrue"))),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -54,7 +54,7 @@ class Junit5AssertionsTest {
|
|||||||
|
|
|
|
||||||
false ==> expected: <true> but was: <false>
|
false ==> expected: <true> but was: <false>
|
||||||
""".trimIndent(),
|
""".trimIndent(),
|
||||||
PowerAssertComponentRegistrar(setOf(FqName("org.junit.jupiter.api.Assertions.assertTrue"))),
|
PowerAssertCompilerPluginRegistrar(setOf(FqName("org.junit.jupiter.api.Assertions.assertTrue"))),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -74,7 +74,7 @@ class Junit5AssertionsTest {
|
|||||||
|
|
|
|
||||||
false ==> expected: <true> but was: <false>
|
false ==> expected: <true> but was: <false>
|
||||||
""".trimIndent(),
|
""".trimIndent(),
|
||||||
PowerAssertComponentRegistrar(setOf(FqName("org.junit.jupiter.api.Assertions.assertTrue"))),
|
PowerAssertCompilerPluginRegistrar(setOf(FqName("org.junit.jupiter.api.Assertions.assertTrue"))),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -93,7 +93,7 @@ class Junit5AssertionsTest {
|
|||||||
|
|
|
|
||||||
false ==> expected: <true> but was: <false>
|
false ==> expected: <true> but was: <false>
|
||||||
""".trimIndent(),
|
""".trimIndent(),
|
||||||
PowerAssertComponentRegistrar(setOf(FqName("org.junit.jupiter.api.Assertions.assertTrue"))),
|
PowerAssertCompilerPluginRegistrar(setOf(FqName("org.junit.jupiter.api.Assertions.assertTrue"))),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -114,7 +114,7 @@ class Junit5AssertionsTest {
|
|||||||
|
|
|
|
||||||
false ==> expected: <true> but was: <false>
|
false ==> expected: <true> but was: <false>
|
||||||
""".trimIndent(),
|
""".trimIndent(),
|
||||||
PowerAssertComponentRegistrar(setOf(FqName("org.junit.jupiter.api.Assertions.assertTrue"))),
|
PowerAssertCompilerPluginRegistrar(setOf(FqName("org.junit.jupiter.api.Assertions.assertTrue"))),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -133,7 +133,7 @@ class Junit5AssertionsTest {
|
|||||||
|
|
|
|
||||||
true ==> expected: <false> but was: <true>
|
true ==> expected: <false> but was: <true>
|
||||||
""".trimIndent(),
|
""".trimIndent(),
|
||||||
PowerAssertComponentRegistrar(setOf(FqName("org.junit.jupiter.api.Assertions.assertFalse"))),
|
PowerAssertCompilerPluginRegistrar(setOf(FqName("org.junit.jupiter.api.Assertions.assertFalse"))),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -152,7 +152,7 @@ class Junit5AssertionsTest {
|
|||||||
|
|
|
|
||||||
true ==> expected: <false> but was: <true>
|
true ==> expected: <false> but was: <true>
|
||||||
""".trimIndent(),
|
""".trimIndent(),
|
||||||
PowerAssertComponentRegistrar(setOf(FqName("org.junit.jupiter.api.Assertions.assertFalse"))),
|
PowerAssertCompilerPluginRegistrar(setOf(FqName("org.junit.jupiter.api.Assertions.assertFalse"))),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -172,7 +172,7 @@ class Junit5AssertionsTest {
|
|||||||
|
|
|
|
||||||
true ==> expected: <false> but was: <true>
|
true ==> expected: <false> but was: <true>
|
||||||
""".trimIndent(),
|
""".trimIndent(),
|
||||||
PowerAssertComponentRegistrar(setOf(FqName("org.junit.jupiter.api.Assertions.assertFalse"))),
|
PowerAssertCompilerPluginRegistrar(setOf(FqName("org.junit.jupiter.api.Assertions.assertFalse"))),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -191,7 +191,7 @@ class Junit5AssertionsTest {
|
|||||||
|
|
|
|
||||||
true ==> expected: <false> but was: <true>
|
true ==> expected: <false> but was: <true>
|
||||||
""".trimIndent(),
|
""".trimIndent(),
|
||||||
PowerAssertComponentRegistrar(setOf(FqName("org.junit.jupiter.api.Assertions.assertFalse"))),
|
PowerAssertCompilerPluginRegistrar(setOf(FqName("org.junit.jupiter.api.Assertions.assertFalse"))),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -212,7 +212,7 @@ class Junit5AssertionsTest {
|
|||||||
|
|
|
|
||||||
true ==> expected: <false> but was: <true>
|
true ==> expected: <false> but was: <true>
|
||||||
""".trimIndent(),
|
""".trimIndent(),
|
||||||
PowerAssertComponentRegistrar(setOf(FqName("org.junit.jupiter.api.Assertions.assertFalse"))),
|
PowerAssertCompilerPluginRegistrar(setOf(FqName("org.junit.jupiter.api.Assertions.assertFalse"))),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -233,7 +233,7 @@ class Junit5AssertionsTest {
|
|||||||
| World
|
| World
|
||||||
Hello ==> expected: <Hello> but was: <World>
|
Hello ==> expected: <Hello> but was: <World>
|
||||||
""".trimIndent(),
|
""".trimIndent(),
|
||||||
PowerAssertComponentRegistrar(setOf(FqName("org.junit.jupiter.api.Assertions.assertEquals"))),
|
PowerAssertCompilerPluginRegistrar(setOf(FqName("org.junit.jupiter.api.Assertions.assertEquals"))),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -255,7 +255,7 @@ class Junit5AssertionsTest {
|
|||||||
| World
|
| World
|
||||||
Hello ==> expected: <Hello> but was: <World>
|
Hello ==> expected: <Hello> but was: <World>
|
||||||
""".trimIndent(),
|
""".trimIndent(),
|
||||||
PowerAssertComponentRegistrar(setOf(FqName("org.junit.jupiter.api.Assertions.assertEquals"))),
|
PowerAssertCompilerPluginRegistrar(setOf(FqName("org.junit.jupiter.api.Assertions.assertEquals"))),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -278,7 +278,7 @@ class Junit5AssertionsTest {
|
|||||||
| World
|
| World
|
||||||
Hello ==> expected: <Hello> but was: <World>
|
Hello ==> expected: <Hello> but was: <World>
|
||||||
""".trimIndent(),
|
""".trimIndent(),
|
||||||
PowerAssertComponentRegistrar(setOf(FqName("org.junit.jupiter.api.Assertions.assertEquals"))),
|
PowerAssertCompilerPluginRegistrar(setOf(FqName("org.junit.jupiter.api.Assertions.assertEquals"))),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -300,7 +300,7 @@ class Junit5AssertionsTest {
|
|||||||
| World
|
| World
|
||||||
Hello ==> expected: <Hello> but was: <World>
|
Hello ==> expected: <Hello> but was: <World>
|
||||||
""".trimIndent(),
|
""".trimIndent(),
|
||||||
PowerAssertComponentRegistrar(setOf(FqName("org.junit.jupiter.api.Assertions.assertEquals"))),
|
PowerAssertCompilerPluginRegistrar(setOf(FqName("org.junit.jupiter.api.Assertions.assertEquals"))),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -324,7 +324,7 @@ class Junit5AssertionsTest {
|
|||||||
| World
|
| World
|
||||||
Hello ==> expected: <Hello> but was: <World>
|
Hello ==> expected: <Hello> but was: <World>
|
||||||
""".trimIndent(),
|
""".trimIndent(),
|
||||||
PowerAssertComponentRegistrar(setOf(FqName("org.junit.jupiter.api.Assertions.assertEquals"))),
|
PowerAssertCompilerPluginRegistrar(setOf(FqName("org.junit.jupiter.api.Assertions.assertEquals"))),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+12
-12
@@ -35,7 +35,7 @@ class KotlinTestAssertTest {
|
|||||||
|
|
|
|
||||||
false
|
false
|
||||||
""".trimIndent(),
|
""".trimIndent(),
|
||||||
PowerAssertComponentRegistrar(setOf(FqName("kotlin.test.assertTrue"))),
|
PowerAssertCompilerPluginRegistrar(setOf(FqName("kotlin.test.assertTrue"))),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -54,7 +54,7 @@ class KotlinTestAssertTest {
|
|||||||
|
|
|
|
||||||
false
|
false
|
||||||
""".trimIndent(),
|
""".trimIndent(),
|
||||||
PowerAssertComponentRegistrar(setOf(FqName("kotlin.test.assertTrue"))),
|
PowerAssertCompilerPluginRegistrar(setOf(FqName("kotlin.test.assertTrue"))),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -74,7 +74,7 @@ class KotlinTestAssertTest {
|
|||||||
|
|
|
|
||||||
false
|
false
|
||||||
""".trimIndent(),
|
""".trimIndent(),
|
||||||
PowerAssertComponentRegistrar(setOf(FqName("kotlin.test.assertTrue"))),
|
PowerAssertCompilerPluginRegistrar(setOf(FqName("kotlin.test.assertTrue"))),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -93,7 +93,7 @@ class KotlinTestAssertTest {
|
|||||||
|
|
|
|
||||||
true
|
true
|
||||||
""".trimIndent(),
|
""".trimIndent(),
|
||||||
PowerAssertComponentRegistrar(setOf(FqName("kotlin.test.assertFalse"))),
|
PowerAssertCompilerPluginRegistrar(setOf(FqName("kotlin.test.assertFalse"))),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -112,7 +112,7 @@ class KotlinTestAssertTest {
|
|||||||
|
|
|
|
||||||
true
|
true
|
||||||
""".trimIndent(),
|
""".trimIndent(),
|
||||||
PowerAssertComponentRegistrar(setOf(FqName("kotlin.test.assertFalse"))),
|
PowerAssertCompilerPluginRegistrar(setOf(FqName("kotlin.test.assertFalse"))),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -132,7 +132,7 @@ class KotlinTestAssertTest {
|
|||||||
|
|
|
|
||||||
true
|
true
|
||||||
""".trimIndent(),
|
""".trimIndent(),
|
||||||
PowerAssertComponentRegistrar(setOf(FqName("kotlin.test.assertFalse"))),
|
PowerAssertCompilerPluginRegistrar(setOf(FqName("kotlin.test.assertFalse"))),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -153,7 +153,7 @@ class KotlinTestAssertTest {
|
|||||||
| World
|
| World
|
||||||
Hello ==> expected: <Hello> but was: <World>
|
Hello ==> expected: <Hello> but was: <World>
|
||||||
""".trimIndent(),
|
""".trimIndent(),
|
||||||
PowerAssertComponentRegistrar(setOf(FqName("kotlin.test.assertEquals"))),
|
PowerAssertCompilerPluginRegistrar(setOf(FqName("kotlin.test.assertEquals"))),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -175,7 +175,7 @@ class KotlinTestAssertTest {
|
|||||||
| World
|
| World
|
||||||
Hello ==> expected: <Hello> but was: <World>
|
Hello ==> expected: <Hello> but was: <World>
|
||||||
""".trimIndent(),
|
""".trimIndent(),
|
||||||
PowerAssertComponentRegistrar(setOf(FqName("kotlin.test.assertEquals"))),
|
PowerAssertCompilerPluginRegistrar(setOf(FqName("kotlin.test.assertEquals"))),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -198,7 +198,7 @@ class KotlinTestAssertTest {
|
|||||||
| World
|
| World
|
||||||
Hello ==> expected: <Hello> but was: <World>
|
Hello ==> expected: <Hello> but was: <World>
|
||||||
""".trimIndent(),
|
""".trimIndent(),
|
||||||
PowerAssertComponentRegistrar(setOf(FqName("kotlin.test.assertEquals"))),
|
PowerAssertCompilerPluginRegistrar(setOf(FqName("kotlin.test.assertEquals"))),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -217,7 +217,7 @@ class KotlinTestAssertTest {
|
|||||||
|
|
|
|
||||||
null ==> expected: not <null>
|
null ==> expected: not <null>
|
||||||
""".trimIndent(),
|
""".trimIndent(),
|
||||||
PowerAssertComponentRegistrar(setOf(FqName("kotlin.test.assertNotNull"))),
|
PowerAssertCompilerPluginRegistrar(setOf(FqName("kotlin.test.assertNotNull"))),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -237,7 +237,7 @@ class KotlinTestAssertTest {
|
|||||||
|
|
|
|
||||||
null ==> expected: not <null>
|
null ==> expected: not <null>
|
||||||
""".trimIndent(),
|
""".trimIndent(),
|
||||||
PowerAssertComponentRegistrar(setOf(FqName("kotlin.test.assertNotNull"))),
|
PowerAssertCompilerPluginRegistrar(setOf(FqName("kotlin.test.assertNotNull"))),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -258,7 +258,7 @@ class KotlinTestAssertTest {
|
|||||||
|
|
|
|
||||||
null ==> expected: not <null>
|
null ==> expected: not <null>
|
||||||
""".trimIndent(),
|
""".trimIndent(),
|
||||||
PowerAssertComponentRegistrar(setOf(FqName("kotlin.test.assertNotNull"))),
|
PowerAssertCompilerPluginRegistrar(setOf(FqName("kotlin.test.assertNotNull"))),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -65,7 +65,7 @@ class LamdaTest {
|
|||||||
false
|
false
|
||||||
)
|
)
|
||||||
""".trimIndent(),
|
""".trimIndent(),
|
||||||
PowerAssertComponentRegistrar(setOf(FqName("kotlin.require"))),
|
PowerAssertCompilerPluginRegistrar(setOf(FqName("kotlin.require"))),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -148,7 +148,7 @@ fun main() {
|
|||||||
trimIndent = false,
|
trimIndent = false,
|
||||||
)
|
)
|
||||||
|
|
||||||
val result = compile(listOf(file), PowerAssertComponentRegistrar(setOf(FqName("dbg"))))
|
val result = compile(listOf(file), PowerAssertCompilerPluginRegistrar(setOf(FqName("dbg"))))
|
||||||
assertEquals(KotlinCompilation.ExitCode.OK, result.exitCode)
|
assertEquals(KotlinCompilation.ExitCode.OK, result.exitCode)
|
||||||
|
|
||||||
val kClazz = result.classLoader.loadClass("MainKt")
|
val kClazz = result.classLoader.loadClass("MainKt")
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
plugins {
|
plugins {
|
||||||
kotlin("multiplatform") version "1.7.0"
|
kotlin("multiplatform") version "1.8.20"
|
||||||
id("com.bnorm.power.kotlin-power-assert") version "0.12.1"
|
id("com.bnorm.power.kotlin-power-assert") version "0.12.1"
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -51,6 +51,13 @@ kotlin {
|
|||||||
dependsOn(commonTest)
|
dependsOn(commonTest)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO Kotlin/JS loses class information at the IR level -> Soft-assertion doesn't work
|
||||||
|
// targets.all {
|
||||||
|
// compilations.all {
|
||||||
|
// kotlinOptions.languageVersion = "2.0"
|
||||||
|
// }
|
||||||
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
tasks.withType<Test> {
|
tasks.withType<Test> {
|
||||||
|
|||||||
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
distributionBase=GRADLE_USER_HOME
|
distributionBase=GRADLE_USER_HOME
|
||||||
distributionPath=wrapper/dists
|
distributionPath=wrapper/dists
|
||||||
distributionUrl=https\://services.gradle.org/distributions/gradle-7.6.1-bin.zip
|
distributionUrl=https\://services.gradle.org/distributions/gradle-8.0.2-bin.zip
|
||||||
networkTimeout=10000
|
networkTimeout=10000
|
||||||
zipStoreBase=GRADLE_USER_HOME
|
zipStoreBase=GRADLE_USER_HOME
|
||||||
zipStorePath=wrapper/dists
|
zipStorePath=wrapper/dists
|
||||||
|
|||||||
Reference in New Issue
Block a user