From 51f33e43d036b85435d4d904fb9267fc37b07d8a Mon Sep 17 00:00:00 2001 From: Ryan Nett Date: Thu, 9 Oct 2025 17:40:52 -0700 Subject: [PATCH 1/6] [PowerAssert] KT-81448 Add support for regex-based function selection ^KT-81448 Fixed --- .../gradle/PowerAssertGradleExtension.kt | 14 +++++++++ .../gradle/PowerAssertGradlePlugin.kt | 5 +++- .../powerassert/PowerAssertCallTransformer.kt | 4 ++- .../powerassert/PowerAssertConfiguration.kt | 1 + .../PowerAssertCommandLineProcessor.kt | 13 +++++++++ .../PowerAssertCompilerPluginRegistrar.kt | 10 +++++-- .../regex/junitAssertionsRegex.box.txt | 16 ++++++++++ .../codegen/regex/junitAssertionsRegex.kt | 29 +++++++++++++++++++ .../codegen/regex/kotlinTestRegex.box.txt | 16 ++++++++++ .../testData/codegen/regex/kotlinTestRegex.kt | 28 ++++++++++++++++++ .../PowerAssertConfigurationDirectives.kt | 4 +++ .../kotlin/powerassert/PowerAssertTests.kt | 4 ++- 12 files changed, 138 insertions(+), 6 deletions(-) create mode 100644 plugins/power-assert/testData/codegen/regex/junitAssertionsRegex.box.txt create mode 100644 plugins/power-assert/testData/codegen/regex/junitAssertionsRegex.kt create mode 100644 plugins/power-assert/testData/codegen/regex/kotlinTestRegex.box.txt create mode 100644 plugins/power-assert/testData/codegen/regex/kotlinTestRegex.kt diff --git a/libraries/tools/kotlin-power-assert/src/common/kotlin/org/jetbrains/kotlin/powerassert/gradle/PowerAssertGradleExtension.kt b/libraries/tools/kotlin-power-assert/src/common/kotlin/org/jetbrains/kotlin/powerassert/gradle/PowerAssertGradleExtension.kt index 6462047b5064c..1eb45465c4e56 100644 --- a/libraries/tools/kotlin-power-assert/src/common/kotlin/org/jetbrains/kotlin/powerassert/gradle/PowerAssertGradleExtension.kt +++ b/libraries/tools/kotlin-power-assert/src/common/kotlin/org/jetbrains/kotlin/powerassert/gradle/PowerAssertGradleExtension.kt @@ -22,6 +22,7 @@ package org.jetbrains.kotlin.powerassert.gradle import org.gradle.api.model.ObjectFactory import org.gradle.api.provider.SetProperty import org.jetbrains.kotlin.gradle.ExperimentalKotlinGradlePluginApi +import java.util.regex.Pattern import javax.inject.Inject @ExperimentalKotlinGradlePluginApi @@ -34,6 +35,19 @@ abstract class PowerAssertGradleExtension @Inject constructor( */ val functions: SetProperty = objectFactory.setProperty(String::class.java).convention(setOf("kotlin.assert")) + /** + * Defines regexes that are used to match functions to transform in addition to those in [functions]. + * Regexes are applied to the fully-qualified path of the function, as used in [functions]. + * Any function whose fully-qualified path entirely matches a regex in this set will be transformed. + * + * Some examples of common patterns include + * `kotlin\.test\.assert.*` (kotlin-test), + * `org\.junit\.Assert\.assert.*` (Junit 4), and + * `org\.junit\.jupiter\.api\.Assertions\.assert.*` (Junit platform). + */ + // Java's Pattern is used here instead of Kotlin's Regex for Groovy compatability + val functionRegexes: SetProperty = objectFactory.setProperty(Pattern::class.java).convention(setOf()) + /** * Defines the Kotlin SourceSets by name which will be transformed by the Power-Assert compiler plugin. * When the provider returns `null` - which is the default - all test SourceSets will be transformed. diff --git a/libraries/tools/kotlin-power-assert/src/common/kotlin/org/jetbrains/kotlin/powerassert/gradle/PowerAssertGradlePlugin.kt b/libraries/tools/kotlin-power-assert/src/common/kotlin/org/jetbrains/kotlin/powerassert/gradle/PowerAssertGradlePlugin.kt index 7526a92623615..0b3b40f9f954c 100644 --- a/libraries/tools/kotlin-power-assert/src/common/kotlin/org/jetbrains/kotlin/powerassert/gradle/PowerAssertGradlePlugin.kt +++ b/libraries/tools/kotlin-power-assert/src/common/kotlin/org/jetbrains/kotlin/powerassert/gradle/PowerAssertGradlePlugin.kt @@ -30,6 +30,7 @@ class PowerAssertGradlePlugin : KotlinCompilerPluginSupportPlugin { private const val POWER_ASSERT_ARTIFACT_NAME = "kotlin-power-assert-compiler-plugin-embeddable" private const val FUNCTION_ARG_NAME = "function" + private const val FUNCTION_REGEX_ARG_NAME = "functionRegex" } override fun apply(target: Project) { @@ -52,9 +53,11 @@ class PowerAssertGradlePlugin : KotlinCompilerPluginSupportPlugin { ): Provider> { val project = kotlinCompilation.target.project val extension = project.extensions.getByType(PowerAssertGradleExtension::class.java) - return extension.functions.map { functions -> + return extension.functions.zip(extension.functionRegexes) { functions, patterns -> functions.map { SubpluginOption(key = FUNCTION_ARG_NAME, value = it) + } + patterns.map { + SubpluginOption(key = FUNCTION_REGEX_ARG_NAME, value = "${it.flags()}:${it.pattern()}") } } } diff --git a/plugins/power-assert/power-assert.backend/src/org/jetbrains/kotlin/powerassert/PowerAssertCallTransformer.kt b/plugins/power-assert/power-assert.backend/src/org/jetbrains/kotlin/powerassert/PowerAssertCallTransformer.kt index dcaa23681bcdb..8d95a993d475d 100644 --- a/plugins/power-assert/power-assert.backend/src/org/jetbrains/kotlin/powerassert/PowerAssertCallTransformer.kt +++ b/plugins/power-assert/power-assert.backend/src/org/jetbrains/kotlin/powerassert/PowerAssertCallTransformer.kt @@ -59,7 +59,9 @@ class PowerAssertCallTransformer( override fun visitCall(expression: IrCall): IrExpression { val function = expression.symbol.owner val fqName = function.kotlinFqName - if (function.parameters.isEmpty() || configuration.functions.none { fqName == it }) { + val matchesDirectly = configuration.functions.any { fqName == it } + val matchesRegex = configuration.functionRegexes.any { it.matches(fqName.asString()) } + if (function.parameters.isEmpty() || !(matchesDirectly || matchesRegex)) { return super.visitCall(expression) } diff --git a/plugins/power-assert/power-assert.backend/src/org/jetbrains/kotlin/powerassert/PowerAssertConfiguration.kt b/plugins/power-assert/power-assert.backend/src/org/jetbrains/kotlin/powerassert/PowerAssertConfiguration.kt index e4364312bcdcb..bf949754ca4e2 100644 --- a/plugins/power-assert/power-assert.backend/src/org/jetbrains/kotlin/powerassert/PowerAssertConfiguration.kt +++ b/plugins/power-assert/power-assert.backend/src/org/jetbrains/kotlin/powerassert/PowerAssertConfiguration.kt @@ -15,6 +15,7 @@ import org.jetbrains.kotlin.name.FqName class PowerAssertConfiguration( private val configuration: CompilerConfiguration, val functions: Set, + val functionRegexes: Set ) { val constTracker: EvaluatedConstTracker? get() = configuration[CommonConfigurationKeys.EVALUATED_CONST_TRACKER] val messageCollector: MessageCollector get() = configuration.messageCollector diff --git a/plugins/power-assert/power-assert.cli/src/org/jetbrains/kotlin/powerassert/PowerAssertCommandLineProcessor.kt b/plugins/power-assert/power-assert.cli/src/org/jetbrains/kotlin/powerassert/PowerAssertCommandLineProcessor.kt index f96e91317d01d..86673a25ac686 100644 --- a/plugins/power-assert/power-assert.cli/src/org/jetbrains/kotlin/powerassert/PowerAssertCommandLineProcessor.kt +++ b/plugins/power-assert/power-assert.cli/src/org/jetbrains/kotlin/powerassert/PowerAssertCommandLineProcessor.kt @@ -24,6 +24,7 @@ import org.jetbrains.kotlin.compiler.plugin.CliOption import org.jetbrains.kotlin.compiler.plugin.CommandLineProcessor import org.jetbrains.kotlin.config.CompilerConfiguration import org.jetbrains.kotlin.powerassert.PowerAssertPluginNames.PLUGIN_ID +import java.util.regex.Pattern class PowerAssertCommandLineProcessor : CommandLineProcessor { override val pluginId: String get() = PLUGIN_ID @@ -36,6 +37,13 @@ class PowerAssertCommandLineProcessor : CommandLineProcessor { required = false, // TODO required for Kotlin/JS allowMultipleOccurrences = true, ), + CliOption( + optionName = "functionRegex", + valueDescription = "regex matched against a function full-qualified name. Format is '\$flagsInt:\$pattern'.", + description = "regex matched against the fully qualified path of function to intercept", + required = false, // TODO required for Kotlin/JS + allowMultipleOccurrences = true, + ), ) override fun processOption( @@ -45,6 +53,11 @@ class PowerAssertCommandLineProcessor : CommandLineProcessor { ) { return when (option.optionName) { "function" -> configuration.add(KEY_FUNCTIONS, value) + "functionRegex" -> { + val flags = value.substringBefore(':', "").toIntOrNull() ?: 0 + val pattern = value.substringAfter(':') + configuration.add(KEY_FUNCTION_REGEXES, Pattern.compile(pattern, flags).toRegex()) + } else -> error("Unexpected config option ${option.optionName}") } } diff --git a/plugins/power-assert/power-assert.cli/src/org/jetbrains/kotlin/powerassert/PowerAssertCompilerPluginRegistrar.kt b/plugins/power-assert/power-assert.cli/src/org/jetbrains/kotlin/powerassert/PowerAssertCompilerPluginRegistrar.kt index 913f8d8c23213..c8f5df605eb33 100644 --- a/plugins/power-assert/power-assert.cli/src/org/jetbrains/kotlin/powerassert/PowerAssertCompilerPluginRegistrar.kt +++ b/plugins/power-assert/power-assert.cli/src/org/jetbrains/kotlin/powerassert/PowerAssertCompilerPluginRegistrar.kt @@ -27,12 +27,14 @@ import org.jetbrains.kotlin.name.FqName import org.jetbrains.kotlin.powerassert.PowerAssertPluginNames.PLUGIN_ID val KEY_FUNCTIONS = CompilerConfigurationKey>("fully-qualified function names") +val KEY_FUNCTION_REGEXES = CompilerConfigurationKey>("function fqn regexes") class PowerAssertCompilerPluginRegistrar( private val functions: Set, + private val functionRegexs: Set, ) : CompilerPluginRegistrar() { @Suppress("unused") - constructor() : this(emptySet()) // Used by service loader + constructor() : this(emptySet(), emptySet()) // Used by service loader override val pluginId: String get() = PLUGIN_ID @@ -40,13 +42,15 @@ class PowerAssertCompilerPluginRegistrar( override fun ExtensionStorage.registerExtensions(configuration: CompilerConfiguration) { val functions = configuration[KEY_FUNCTIONS]?.map { FqName(it) } ?: functions - if (functions.isEmpty()) return + val functionRegexs = configuration[KEY_FUNCTION_REGEXES] ?: functionRegexs + if (functions.isEmpty() && functionRegexs.isEmpty()) return IrGenerationExtension.registerExtension( PowerAssertIrGenerationExtension( PowerAssertConfiguration( configuration, - functions.toSet() + functions.toSet(), + functionRegexs.toSet() ) ) ) diff --git a/plugins/power-assert/testData/codegen/regex/junitAssertionsRegex.box.txt b/plugins/power-assert/testData/codegen/regex/junitAssertionsRegex.box.txt new file mode 100644 index 0000000000000..6e01ac2189e74 --- /dev/null +++ b/plugins/power-assert/testData/codegen/regex/junitAssertionsRegex.box.txt @@ -0,0 +1,16 @@ +assertTrue: --- +assertTrue(booleanValue) + | + false + ==> expected: but was: --- +assertEquals: --- +assertEquals(a, b) + | | + | 5 + 3 + ==> expected: <3> but was: <5>--- +assertFalse: --- +assertFalse(booleanValue) + | + true + ==> expected: but was: --- diff --git a/plugins/power-assert/testData/codegen/regex/junitAssertionsRegex.kt b/plugins/power-assert/testData/codegen/regex/junitAssertionsRegex.kt new file mode 100644 index 0000000000000..1f369c413102e --- /dev/null +++ b/plugins/power-assert/testData/codegen/regex/junitAssertionsRegex.kt @@ -0,0 +1,29 @@ +// FUNCTION_REGEX: org\.junit\.jupiter\.api\.Assertions\.assert.* +// WITH_JUNIT5 +// IGNORE_BACKEND_K1: ANY +// LANGUAGE: +ContextParameters + +import org.junit.jupiter.api.Assertions + +fun box(): String = runAll( + "assertTrue" to { test1() }, + "assertEquals" to { test2() }, + "assertFalse" to { test3() }, +) + +fun test1() { + val booleanValue = false + Assertions.assertTrue(booleanValue) +} + + +fun test2() { + val a = 3 + val b = 5 + Assertions.assertEquals(a, b) +} + +fun test3() { + val booleanValue = true + Assertions.assertFalse(booleanValue) +} diff --git a/plugins/power-assert/testData/codegen/regex/kotlinTestRegex.box.txt b/plugins/power-assert/testData/codegen/regex/kotlinTestRegex.box.txt new file mode 100644 index 0000000000000..ad6c3417098c0 --- /dev/null +++ b/plugins/power-assert/testData/codegen/regex/kotlinTestRegex.box.txt @@ -0,0 +1,16 @@ +assertTrue: --- +assertTrue(booleanValue) + | + false +--- +assertEquals: --- +assertEquals(a, b) + | | + | 5 + 3 +. Expected <3>, actual <5>.--- +assertFalse: --- +assertFalse(booleanValue) + | + true +--- diff --git a/plugins/power-assert/testData/codegen/regex/kotlinTestRegex.kt b/plugins/power-assert/testData/codegen/regex/kotlinTestRegex.kt new file mode 100644 index 0000000000000..9d73310e25a67 --- /dev/null +++ b/plugins/power-assert/testData/codegen/regex/kotlinTestRegex.kt @@ -0,0 +1,28 @@ +// FUNCTION_REGEX: kotlin\.test\.assert.* +// IGNORE_BACKEND_K1: ANY +// LANGUAGE: +ContextParameters + +import kotlin.test.* + +fun box(): String = runAll( + "assertTrue" to { test1() }, + "assertEquals" to { test2() }, + "assertFalse" to { test3() }, +) + +fun test1() { + val booleanValue = false + assertTrue(booleanValue) +} + + +fun test2() { + val a = 3 + val b = 5 + assertEquals(a, b) +} + +fun test3() { + val booleanValue = true + assertFalse(booleanValue) +} diff --git a/plugins/power-assert/testFixtures/org/jetbrains/kotlin/powerassert/PowerAssertConfigurationDirectives.kt b/plugins/power-assert/testFixtures/org/jetbrains/kotlin/powerassert/PowerAssertConfigurationDirectives.kt index 744e13c025df7..67447a75f6f3c 100644 --- a/plugins/power-assert/testFixtures/org/jetbrains/kotlin/powerassert/PowerAssertConfigurationDirectives.kt +++ b/plugins/power-assert/testFixtures/org/jetbrains/kotlin/powerassert/PowerAssertConfigurationDirectives.kt @@ -12,6 +12,10 @@ object PowerAssertConfigurationDirectives : SimpleDirectivesContainer() { description = "Functions targeted by Power-Assert transformation", multiLine = true, ) + val FUNCTION_REGEX by stringDirective( + description = "Regexes for functions targeted by Power-Assert transformation", + multiLine = true, + ) val WITH_JUNIT5 by directive("Add JUnit5 to classpath") } diff --git a/plugins/power-assert/testFixtures/org/jetbrains/kotlin/powerassert/PowerAssertTests.kt b/plugins/power-assert/testFixtures/org/jetbrains/kotlin/powerassert/PowerAssertTests.kt index dd3194b5ffff4..b26d133b26750 100644 --- a/plugins/power-assert/testFixtures/org/jetbrains/kotlin/powerassert/PowerAssertTests.kt +++ b/plugins/power-assert/testFixtures/org/jetbrains/kotlin/powerassert/PowerAssertTests.kt @@ -74,8 +74,10 @@ class PowerAssertEnvironmentConfigurator(testServices: TestServices) : Environme val functions = moduleStructure.allDirectives[PowerAssertConfigurationDirectives.FUNCTION] .ifEmpty { listOf("kotlin.assert") } .mapTo(mutableSetOf()) { FqName(it) } + val functionRegexs = moduleStructure.allDirectives[PowerAssertConfigurationDirectives.FUNCTION_REGEX] + .mapTo(mutableSetOf()) { Regex(it) } - IrGenerationExtension.registerExtension(PowerAssertIrGenerationExtension(PowerAssertConfiguration(configuration, functions))) + IrGenerationExtension.registerExtension(PowerAssertIrGenerationExtension(PowerAssertConfiguration(configuration, functions, functionRegexs))) } } From 74b666a4e865fdb1af84ae61c0609b1fe0153bdb Mon Sep 17 00:00:00 2001 From: Ryan Nett Date: Sat, 11 Oct 2025 11:42:00 -0700 Subject: [PATCH 2/6] Update example patterns --- .../powerassert/gradle/PowerAssertGradleExtension.kt | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/libraries/tools/kotlin-power-assert/src/common/kotlin/org/jetbrains/kotlin/powerassert/gradle/PowerAssertGradleExtension.kt b/libraries/tools/kotlin-power-assert/src/common/kotlin/org/jetbrains/kotlin/powerassert/gradle/PowerAssertGradleExtension.kt index 1eb45465c4e56..99a5008d8cf8c 100644 --- a/libraries/tools/kotlin-power-assert/src/common/kotlin/org/jetbrains/kotlin/powerassert/gradle/PowerAssertGradleExtension.kt +++ b/libraries/tools/kotlin-power-assert/src/common/kotlin/org/jetbrains/kotlin/powerassert/gradle/PowerAssertGradleExtension.kt @@ -21,6 +21,7 @@ package org.jetbrains.kotlin.powerassert.gradle import org.gradle.api.model.ObjectFactory import org.gradle.api.provider.SetProperty +import org.intellij.lang.annotations.Language import org.jetbrains.kotlin.gradle.ExperimentalKotlinGradlePluginApi import java.util.regex.Pattern import javax.inject.Inject @@ -41,9 +42,9 @@ abstract class PowerAssertGradleExtension @Inject constructor( * Any function whose fully-qualified path entirely matches a regex in this set will be transformed. * * Some examples of common patterns include - * `kotlin\.test\.assert.*` (kotlin-test), - * `org\.junit\.Assert\.assert.*` (Junit 4), and - * `org\.junit\.jupiter\.api\.Assertions\.assert.*` (Junit platform). + * * `kotlin\.test\.assert.*` (kotlin-test) + * * `org\.junit\.jupiter\.api\.Assertions\.assert.*` (Junit platform) + * * `my\.test\.framework.+\.assert.*` (custom framework) */ // Java's Pattern is used here instead of Kotlin's Regex for Groovy compatability val functionRegexes: SetProperty = objectFactory.setProperty(Pattern::class.java).convention(setOf()) From 82f96f604f8a7d406650c42b4cb8fa6889134b36 Mon Sep 17 00:00:00 2001 From: Ryan Nett Date: Sat, 11 Oct 2025 11:46:49 -0700 Subject: [PATCH 3/6] Refactor property combination --- .../powerassert/gradle/PowerAssertGradlePlugin.kt | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/libraries/tools/kotlin-power-assert/src/common/kotlin/org/jetbrains/kotlin/powerassert/gradle/PowerAssertGradlePlugin.kt b/libraries/tools/kotlin-power-assert/src/common/kotlin/org/jetbrains/kotlin/powerassert/gradle/PowerAssertGradlePlugin.kt index 0b3b40f9f954c..484e04270b903 100644 --- a/libraries/tools/kotlin-power-assert/src/common/kotlin/org/jetbrains/kotlin/powerassert/gradle/PowerAssertGradlePlugin.kt +++ b/libraries/tools/kotlin-power-assert/src/common/kotlin/org/jetbrains/kotlin/powerassert/gradle/PowerAssertGradlePlugin.kt @@ -53,13 +53,16 @@ class PowerAssertGradlePlugin : KotlinCompilerPluginSupportPlugin { ): Provider> { val project = kotlinCompilation.target.project val extension = project.extensions.getByType(PowerAssertGradleExtension::class.java) - return extension.functions.zip(extension.functionRegexes) { functions, patterns -> - functions.map { - SubpluginOption(key = FUNCTION_ARG_NAME, value = it) - } + patterns.map { - SubpluginOption(key = FUNCTION_REGEX_ARG_NAME, value = "${it.flags()}:${it.pattern()}") - } + + val functionOptions = extension.functions.map { + it.map { SubpluginOption(key = FUNCTION_ARG_NAME, value = it) } + } + + val patternOptions = extension.functionRegexes.map { + it.map { SubpluginOption(key = FUNCTION_REGEX_ARG_NAME, value = "${it.flags()}:${it.pattern()}") } } + + return functionOptions.zip(patternOptions) { a, b -> a + b } } override fun getCompilerPluginId(): String = "org.jetbrains.kotlin.powerassert" From 96847dba727df910884d576a37d9c45caddaf35b Mon Sep 17 00:00:00 2001 From: Ryan Nett Date: Sat, 11 Oct 2025 11:49:45 -0700 Subject: [PATCH 4/6] Add trailing comma --- .../kotlin/powerassert/PowerAssertCompilerPluginRegistrar.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/power-assert/power-assert.cli/src/org/jetbrains/kotlin/powerassert/PowerAssertCompilerPluginRegistrar.kt b/plugins/power-assert/power-assert.cli/src/org/jetbrains/kotlin/powerassert/PowerAssertCompilerPluginRegistrar.kt index c8f5df605eb33..db2cba549f0b1 100644 --- a/plugins/power-assert/power-assert.cli/src/org/jetbrains/kotlin/powerassert/PowerAssertCompilerPluginRegistrar.kt +++ b/plugins/power-assert/power-assert.cli/src/org/jetbrains/kotlin/powerassert/PowerAssertCompilerPluginRegistrar.kt @@ -50,7 +50,7 @@ class PowerAssertCompilerPluginRegistrar( PowerAssertConfiguration( configuration, functions.toSet(), - functionRegexs.toSet() + functionRegexs.toSet(), ) ) ) From 66906ca9330758ec92e4543868bda092b7f7427b Mon Sep 17 00:00:00 2001 From: Ryan Nett Date: Sat, 11 Oct 2025 11:53:00 -0700 Subject: [PATCH 5/6] Remove unnecessary test directives --- .../power-assert/testData/codegen/regex/junitAssertionsRegex.kt | 2 -- plugins/power-assert/testData/codegen/regex/kotlinTestRegex.kt | 2 -- 2 files changed, 4 deletions(-) diff --git a/plugins/power-assert/testData/codegen/regex/junitAssertionsRegex.kt b/plugins/power-assert/testData/codegen/regex/junitAssertionsRegex.kt index 1f369c413102e..3248a60ded5dc 100644 --- a/plugins/power-assert/testData/codegen/regex/junitAssertionsRegex.kt +++ b/plugins/power-assert/testData/codegen/regex/junitAssertionsRegex.kt @@ -1,7 +1,5 @@ // FUNCTION_REGEX: org\.junit\.jupiter\.api\.Assertions\.assert.* // WITH_JUNIT5 -// IGNORE_BACKEND_K1: ANY -// LANGUAGE: +ContextParameters import org.junit.jupiter.api.Assertions diff --git a/plugins/power-assert/testData/codegen/regex/kotlinTestRegex.kt b/plugins/power-assert/testData/codegen/regex/kotlinTestRegex.kt index 9d73310e25a67..8ecd5124d64bd 100644 --- a/plugins/power-assert/testData/codegen/regex/kotlinTestRegex.kt +++ b/plugins/power-assert/testData/codegen/regex/kotlinTestRegex.kt @@ -1,6 +1,4 @@ // FUNCTION_REGEX: kotlin\.test\.assert.* -// IGNORE_BACKEND_K1: ANY -// LANGUAGE: +ContextParameters import kotlin.test.* From 88790b48711203dcec0a122a42aad063ac0fa621 Mon Sep 17 00:00:00 2001 From: Ryan Nett Date: Sat, 11 Oct 2025 11:56:38 -0700 Subject: [PATCH 6/6] Make the check for exact or regex matches more lazy --- .../kotlin/powerassert/PowerAssertCallTransformer.kt | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/plugins/power-assert/power-assert.backend/src/org/jetbrains/kotlin/powerassert/PowerAssertCallTransformer.kt b/plugins/power-assert/power-assert.backend/src/org/jetbrains/kotlin/powerassert/PowerAssertCallTransformer.kt index 8d95a993d475d..16c27a25bd887 100644 --- a/plugins/power-assert/power-assert.backend/src/org/jetbrains/kotlin/powerassert/PowerAssertCallTransformer.kt +++ b/plugins/power-assert/power-assert.backend/src/org/jetbrains/kotlin/powerassert/PowerAssertCallTransformer.kt @@ -59,9 +59,7 @@ class PowerAssertCallTransformer( override fun visitCall(expression: IrCall): IrExpression { val function = expression.symbol.owner val fqName = function.kotlinFqName - val matchesDirectly = configuration.functions.any { fqName == it } - val matchesRegex = configuration.functionRegexes.any { it.matches(fqName.asString()) } - if (function.parameters.isEmpty() || !(matchesDirectly || matchesRegex)) { + if (function.parameters.isEmpty() || !configuration.isTransformEnabledFor(fqName)) { return super.visitCall(expression) } @@ -295,3 +293,7 @@ val IrFunction.callableId: CallableId CallableId(parent.kotlinFqName, name) } } + +private fun PowerAssertConfiguration.isTransformEnabledFor(fqName: FqName): Boolean { + return functions.any { fqName == it } || functionRegexes.any { it.matches(fqName.asString()) } +}