From 87b209ab91ab509977832b7ed8aaf1e6896c8bf3 Mon Sep 17 00:00:00 2001 From: Christoph Sturm Date: Fri, 7 Apr 2023 14:42:43 +0200 Subject: [PATCH] bump kotlinter to 3.14 and ktlint action to 1.5.1 (#86) * add kotlinter 3.14 * force trailing commas * bump ktlint action to 1.5.1 * run ./gradlew formatKotlin * disable kotlinter plugin because it triggers a problem in the kotlin compiler --- .editorconfig | 2 + .github/workflows/build.yml | 2 +- build.gradle.kts | 1 + kotlin-power-assert-gradle/build.gradle.kts | 1 + .../bnorm/power/PowerAssertGradlePlugin.kt | 4 +- kotlin-power-assert-plugin/build.gradle.kts | 1 + .../bnorm/power/PowerAssertCallTransformer.kt | 12 +- .../power/PowerAssertCommandLineProcessor.kt | 6 +- .../power/PowerAssertComponentRegistrar.kt | 9 +- .../power/PowerAssertIrGenerationExtension.kt | 2 +- .../bnorm/power/delegate/FunctionDelegate.kt | 4 +- .../power/delegate/LambdaFunctionDelegate.kt | 4 +- .../SamConversionLambdaFunctionDelegate.kt | 4 +- .../power/delegate/SimpleFunctionDelegate.kt | 4 +- .../com/bnorm/power/diagram/DiagramBuilder.kt | 46 +++-- .../com/bnorm/power/diagram/ExpressionTree.kt | 173 +++++++++--------- .../com/bnorm/power/diagram/IrDiagram.kt | 16 +- .../power/diagram/IrTemporaryVariable.kt | 4 +- .../com/bnorm/power/diagram/SourceFile.kt | 2 +- .../main/kotlin/com/bnorm/power/irUtils.kt | 2 +- .../bnorm/power/ArithmeticExpressionTest.kt | 24 +-- .../test/kotlin/com/bnorm/power/AssertTest.kt | 47 ++--- .../com/bnorm/power/CastExpressionTest.kt | 8 +- .../com/bnorm/power/DebugFunctionTest.kt | 13 +- .../com/bnorm/power/InfixFunctionTest.kt | 72 ++++---- .../com/bnorm/power/Junit5AssertionsTest.kt | 30 +-- .../com/bnorm/power/KotlinTestAssertTest.kt | 24 +-- .../test/kotlin/com/bnorm/power/LamdaTest.kt | 4 +- .../bnorm/power/MultiParameterFunctionTest.kt | 18 +- .../kotlin/com/bnorm/power/RegexMatchTest.kt | 4 +- .../test/kotlin/com/bnorm/power/compiler.kt | 10 +- 31 files changed, 284 insertions(+), 269 deletions(-) diff --git a/.editorconfig b/.editorconfig index 78092e35a49..cc201fcdc78 100644 --- a/.editorconfig +++ b/.editorconfig @@ -14,3 +14,5 @@ ij_kotlin_imports_layout = *,java.**,javax.**,kotlin.**,^ ij_kotlin_name_count_to_use_star_import = 2147483647 ij_kotlin_name_count_to_use_star_import_for_members = 2147483647 ij_kotlin_packages_to_use_import_on_demand = unset +ij_kotlin_allow_trailing_comma_on_call_site = true +ij_kotlin_allow_trailing_comma = true diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 71ec8373357..93b6ba656d9 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -47,7 +47,7 @@ jobs: steps: - uses: actions/checkout@v3 - name: Run ktlint - uses: ScaCap/action-ktlint@1.4 + uses: ScaCap/action-ktlint@1.5.1 with: github_token: ${{ secrets.GITHUB_TOKEN }} reporter: github-pr-check diff --git a/build.gradle.kts b/build.gradle.kts index 8fd2b1d0bc7..f4075f1f5c6 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -3,6 +3,7 @@ plugins { id("org.jetbrains.dokka") version "1.7.0" apply false id("com.gradle.plugin-publish") version "1.1.0" apply false id("com.github.gmazzo.buildconfig") version "3.1.0" apply false +// id("org.jmailen.kotlinter") version "3.14.0" apply false } allprojects { diff --git a/kotlin-power-assert-gradle/build.gradle.kts b/kotlin-power-assert-gradle/build.gradle.kts index 2b60e448a6a..40306371f26 100644 --- a/kotlin-power-assert-gradle/build.gradle.kts +++ b/kotlin-power-assert-gradle/build.gradle.kts @@ -5,6 +5,7 @@ plugins { kotlin("jvm") id("com.gradle.plugin-publish") id("com.github.gmazzo.buildconfig") +// id("org.jmailen.kotlinter") } dependencies { diff --git a/kotlin-power-assert-gradle/src/main/kotlin/com/bnorm/power/PowerAssertGradlePlugin.kt b/kotlin-power-assert-gradle/src/main/kotlin/com/bnorm/power/PowerAssertGradlePlugin.kt index 79c0860e3ee..aa061a55b3c 100644 --- a/kotlin-power-assert-gradle/src/main/kotlin/com/bnorm/power/PowerAssertGradlePlugin.kt +++ b/kotlin-power-assert-gradle/src/main/kotlin/com/bnorm/power/PowerAssertGradlePlugin.kt @@ -39,11 +39,11 @@ class PowerAssertGradlePlugin : KotlinCompilerPluginSupportPlugin { override fun getPluginArtifact(): SubpluginArtifact = SubpluginArtifact( groupId = BuildConfig.PLUGIN_GROUP_ID, artifactId = BuildConfig.PLUGIN_ARTIFACT_ID, - version = BuildConfig.PLUGIN_VERSION + version = BuildConfig.PLUGIN_VERSION, ) override fun applyToCompilation( - kotlinCompilation: KotlinCompilation<*> + kotlinCompilation: KotlinCompilation<*>, ): Provider> { val project = kotlinCompilation.target.project val extension = project.extensions.getByType(PowerAssertGradleExtension::class.java) diff --git a/kotlin-power-assert-plugin/build.gradle.kts b/kotlin-power-assert-plugin/build.gradle.kts index 119acf30c9c..140962c2b11 100644 --- a/kotlin-power-assert-plugin/build.gradle.kts +++ b/kotlin-power-assert-plugin/build.gradle.kts @@ -7,6 +7,7 @@ plugins { signing `maven-publish` +// id("org.jmailen.kotlinter") } dependencies { diff --git a/kotlin-power-assert-plugin/src/main/kotlin/com/bnorm/power/PowerAssertCallTransformer.kt b/kotlin-power-assert-plugin/src/main/kotlin/com/bnorm/power/PowerAssertCallTransformer.kt index 6f56faae730..27c06d546cb 100644 --- a/kotlin-power-assert-plugin/src/main/kotlin/com/bnorm/power/PowerAssertCallTransformer.kt +++ b/kotlin-power-assert-plugin/src/main/kotlin/com/bnorm/power/PowerAssertCallTransformer.kt @@ -68,7 +68,7 @@ class PowerAssertCallTransformer( private val sourceFile: SourceFile, private val context: IrPluginContext, private val messageCollector: MessageCollector, - private val functions: Set + private val functions: Set, ) : IrElementTransformerVoidWithContext() { private val irTypeSystemContext = IrTypeSystemContextImpl(context.irBuiltIns) @@ -95,7 +95,7 @@ class PowerAssertCallTransformer( | - $fqName($valueTypesTruncated() -> String) | - $fqName(${valueTypesAll}String) | - $fqName($valueTypesAll() -> String) - """.trimMargin() + """.trimMargin(), ) return super.visitCall(expression) } @@ -132,7 +132,7 @@ class PowerAssertCallTransformer( messageArgument = messageArgument, roots = roots, dispatchRoot = dispatchRoot, - extensionRoot = extensionRoot + extensionRoot = extensionRoot, ) } @@ -142,14 +142,14 @@ class PowerAssertCallTransformer( messageArgument: IrExpression?, roots: List, dispatchRoot: Node? = null, - extensionRoot: Node? = null + extensionRoot: Node? = null, ): IrExpression { fun recursive( index: Int, dispatch: IrExpression?, extension: IrExpression?, arguments: List, - variables: List + variables: List, ): IrExpression { if (index >= roots.size) { val prefix = buildMessagePrefix(messageArgument, delegate.messageParameter, roots, call) @@ -181,7 +181,7 @@ class PowerAssertCallTransformer( messageArgument: IrExpression?, messageParameter: IrValueParameter, roots: List, - original: IrCall + original: IrCall, ): IrExpression? { return when { messageArgument is IrConst<*> -> messageArgument diff --git a/kotlin-power-assert-plugin/src/main/kotlin/com/bnorm/power/PowerAssertCommandLineProcessor.kt b/kotlin-power-assert-plugin/src/main/kotlin/com/bnorm/power/PowerAssertCommandLineProcessor.kt index a526f5e8e56..599d69a9111 100644 --- a/kotlin-power-assert-plugin/src/main/kotlin/com/bnorm/power/PowerAssertCommandLineProcessor.kt +++ b/kotlin-power-assert-plugin/src/main/kotlin/com/bnorm/power/PowerAssertCommandLineProcessor.kt @@ -32,14 +32,14 @@ class PowerAssertCommandLineProcessor : CommandLineProcessor { valueDescription = "function full-qualified name", description = "fully qualified path of function to intercept", required = false, // TODO required for Kotlin/JS - allowMultipleOccurrences = true - ) + allowMultipleOccurrences = true, + ), ) override fun processOption( option: AbstractCliOption, value: String, - configuration: CompilerConfiguration + configuration: CompilerConfiguration, ) { return when (option.optionName) { "function" -> configuration.add(KEY_FUNCTIONS, value) diff --git a/kotlin-power-assert-plugin/src/main/kotlin/com/bnorm/power/PowerAssertComponentRegistrar.kt b/kotlin-power-assert-plugin/src/main/kotlin/com/bnorm/power/PowerAssertComponentRegistrar.kt index 1cbd298ea12..1001a840c79 100644 --- a/kotlin-power-assert-plugin/src/main/kotlin/com/bnorm/power/PowerAssertComponentRegistrar.kt +++ b/kotlin-power-assert-plugin/src/main/kotlin/com/bnorm/power/PowerAssertComponentRegistrar.kt @@ -30,13 +30,14 @@ val KEY_FUNCTIONS = CompilerConfigurationKey>("fully-qualified func @AutoService(ComponentRegistrar::class) class PowerAssertComponentRegistrar( - private val functions: Set + private val functions: Set, ) : ComponentRegistrar { - @Suppress("unused") constructor() : this(emptySet()) // Used by service loader + @Suppress("unused") + constructor() : this(emptySet()) // Used by service loader override fun registerProjectComponents( project: MockProject, - configuration: CompilerConfiguration + configuration: CompilerConfiguration, ) { val functions = configuration[KEY_FUNCTIONS]?.map { FqName(it) } ?: functions if (functions.isEmpty()) return @@ -45,5 +46,3 @@ class PowerAssertComponentRegistrar( IrGenerationExtension.registerExtension(project, PowerAssertIrGenerationExtension(messageCollector, functions.toSet())) } } - - diff --git a/kotlin-power-assert-plugin/src/main/kotlin/com/bnorm/power/PowerAssertIrGenerationExtension.kt b/kotlin-power-assert-plugin/src/main/kotlin/com/bnorm/power/PowerAssertIrGenerationExtension.kt index 2aa7a2a2d33..f194d2120d9 100644 --- a/kotlin-power-assert-plugin/src/main/kotlin/com/bnorm/power/PowerAssertIrGenerationExtension.kt +++ b/kotlin-power-assert-plugin/src/main/kotlin/com/bnorm/power/PowerAssertIrGenerationExtension.kt @@ -25,7 +25,7 @@ import org.jetbrains.kotlin.name.FqName class PowerAssertIrGenerationExtension( private val messageCollector: MessageCollector, - private val functions: Set + private val functions: Set, ) : IrGenerationExtension { override fun generate(moduleFragment: IrModuleFragment, pluginContext: IrPluginContext) { for (file in moduleFragment.files) { diff --git a/kotlin-power-assert-plugin/src/main/kotlin/com/bnorm/power/delegate/FunctionDelegate.kt b/kotlin-power-assert-plugin/src/main/kotlin/com/bnorm/power/delegate/FunctionDelegate.kt index 8a806a5d629..d9980d3a551 100644 --- a/kotlin-power-assert-plugin/src/main/kotlin/com/bnorm/power/delegate/FunctionDelegate.kt +++ b/kotlin-power-assert-plugin/src/main/kotlin/com/bnorm/power/delegate/FunctionDelegate.kt @@ -36,7 +36,7 @@ interface FunctionDelegate { dispatchReceiver: IrExpression?, extensionReceiver: IrExpression?, valueArguments: List, - messageArgument: IrExpression + messageArgument: IrExpression, ): IrExpression fun IrBuilderWithScope.irCallCopy( @@ -45,7 +45,7 @@ interface FunctionDelegate { dispatchReceiver: IrExpression?, extensionReceiver: IrExpression?, valueArguments: List, - messageArgument: IrExpression + messageArgument: IrExpression, ): IrExpression { return irCall(overload, type = original.type).apply { this.dispatchReceiver = original.dispatchReceiver?.deepCopyWithSymbols(parent) diff --git a/kotlin-power-assert-plugin/src/main/kotlin/com/bnorm/power/delegate/LambdaFunctionDelegate.kt b/kotlin-power-assert-plugin/src/main/kotlin/com/bnorm/power/delegate/LambdaFunctionDelegate.kt index dccc644291f..d59f1bf2ff4 100644 --- a/kotlin-power-assert-plugin/src/main/kotlin/com/bnorm/power/delegate/LambdaFunctionDelegate.kt +++ b/kotlin-power-assert-plugin/src/main/kotlin/com/bnorm/power/delegate/LambdaFunctionDelegate.kt @@ -36,7 +36,7 @@ class LambdaFunctionDelegate( dispatchReceiver: IrExpression?, extensionReceiver: IrExpression?, valueArguments: List, - messageArgument: IrExpression + messageArgument: IrExpression, ): IrExpression = with(builder) { val expression = irLambda(context.irBuiltIns.stringType, messageParameter.type) { +irReturn(messageArgument) @@ -47,7 +47,7 @@ class LambdaFunctionDelegate( dispatchReceiver = dispatchReceiver, extensionReceiver = extensionReceiver, valueArguments = valueArguments, - messageArgument = expression + messageArgument = expression, ) } } diff --git a/kotlin-power-assert-plugin/src/main/kotlin/com/bnorm/power/delegate/SamConversionLambdaFunctionDelegate.kt b/kotlin-power-assert-plugin/src/main/kotlin/com/bnorm/power/delegate/SamConversionLambdaFunctionDelegate.kt index 902fedc9d8e..d3ecc484cff 100644 --- a/kotlin-power-assert-plugin/src/main/kotlin/com/bnorm/power/delegate/SamConversionLambdaFunctionDelegate.kt +++ b/kotlin-power-assert-plugin/src/main/kotlin/com/bnorm/power/delegate/SamConversionLambdaFunctionDelegate.kt @@ -37,7 +37,7 @@ class SamConversionLambdaFunctionDelegate( dispatchReceiver: IrExpression?, extensionReceiver: IrExpression?, valueArguments: List, - messageArgument: IrExpression + messageArgument: IrExpression, ): IrExpression = with(builder) { val lambda = irLambda(context.irBuiltIns.stringType, messageParameter.type) { +irReturn(messageArgument) @@ -49,7 +49,7 @@ class SamConversionLambdaFunctionDelegate( dispatchReceiver = dispatchReceiver, extensionReceiver = extensionReceiver, valueArguments = valueArguments, - messageArgument = expression + messageArgument = expression, ) } } diff --git a/kotlin-power-assert-plugin/src/main/kotlin/com/bnorm/power/delegate/SimpleFunctionDelegate.kt b/kotlin-power-assert-plugin/src/main/kotlin/com/bnorm/power/delegate/SimpleFunctionDelegate.kt index b1b9221c5cd..e78447696e9 100644 --- a/kotlin-power-assert-plugin/src/main/kotlin/com/bnorm/power/delegate/SimpleFunctionDelegate.kt +++ b/kotlin-power-assert-plugin/src/main/kotlin/com/bnorm/power/delegate/SimpleFunctionDelegate.kt @@ -34,13 +34,13 @@ class SimpleFunctionDelegate( dispatchReceiver: IrExpression?, extensionReceiver: IrExpression?, valueArguments: List, - messageArgument: IrExpression + messageArgument: IrExpression, ): IrExpression = builder.irCallCopy( overload = overload, original = original, dispatchReceiver = dispatchReceiver, extensionReceiver = extensionReceiver, valueArguments = valueArguments, - messageArgument = messageArgument + messageArgument = messageArgument, ) } diff --git a/kotlin-power-assert-plugin/src/main/kotlin/com/bnorm/power/diagram/DiagramBuilder.kt b/kotlin-power-assert-plugin/src/main/kotlin/com/bnorm/power/diagram/DiagramBuilder.kt index 70f38933972..875ef9d6d06 100644 --- a/kotlin-power-assert-plugin/src/main/kotlin/com/bnorm/power/diagram/DiagramBuilder.kt +++ b/kotlin-power-assert-plugin/src/main/kotlin/com/bnorm/power/diagram/DiagramBuilder.kt @@ -27,7 +27,7 @@ import org.jetbrains.kotlin.ir.util.deepCopyWithSymbols fun IrBuilderWithScope.buildDiagramNesting( root: Node, variables: List = emptyList(), - call: IrBuilderWithScope.(IrExpression, List) -> IrExpression + call: IrBuilderWithScope.(IrExpression, List) -> IrExpression, ): IrExpression { return buildExpression(root, variables) { argument, subStack -> call(argument, subStack) @@ -37,7 +37,7 @@ fun IrBuilderWithScope.buildDiagramNesting( fun IrBuilderWithScope.buildDiagramNestingNullable( root: Node?, variables: List = emptyList(), - call: IrBuilderWithScope.(IrExpression?, List) -> IrExpression + call: IrBuilderWithScope.(IrExpression?, List) -> IrExpression, ): IrExpression { return if (root != null) buildDiagramNesting(root, variables, call) else call(null, variables) } @@ -45,7 +45,7 @@ fun IrBuilderWithScope.buildDiagramNestingNullable( private fun IrBuilderWithScope.buildExpression( node: Node, variables: List, - call: IrBuilderWithScope.(IrExpression, List) -> IrExpression + call: IrBuilderWithScope.(IrExpression, List) -> IrExpression, ): IrExpression = when (node) { is ExpressionNode -> add(node, variables, call) is AndNode -> nest(node, 0, variables, call) @@ -69,7 +69,7 @@ private fun IrBuilderWithScope.buildExpression( private fun IrBuilderWithScope.add( node: ExpressionNode, variables: List, - call: IrBuilderWithScope.(IrExpression, List) -> IrExpression + call: IrBuilderWithScope.(IrExpression, List) -> IrExpression, ): IrExpression { return irBlock { val head = node.expressions.first().deepCopyWithSymbols(scope.getLocalDeclarationParent()) @@ -100,18 +100,21 @@ private fun IrBuilderWithScope.nest( node: AndNode, index: Int, variables: List, - call: IrBuilderWithScope.(IrExpression, List) -> IrExpression + call: IrBuilderWithScope.(IrExpression, List) -> IrExpression, ): IrExpression { val children = node.children val child = children[index] return buildExpression(child, variables) { argument, newVariables -> - if (index + 1 == children.size) call(argument, newVariables) // last expression, result is false - else irIfThenElse( - context.irBuiltIns.anyType, - argument, - nest(node, index + 1, newVariables, call), // more expressions, continue nesting - call(irFalse(), newVariables), // short-circuit result to false - ) + if (index + 1 == children.size) { + call(argument, newVariables) // last expression, result is false + } else { + irIfThenElse( + context.irBuiltIns.anyType, + argument, + nest(node, index + 1, newVariables, call), // more expressions, continue nesting + call(irFalse(), newVariables), // short-circuit result to false + ) + } } } @@ -135,17 +138,20 @@ private fun IrBuilderWithScope.nest( node: OrNode, index: Int, variables: List, - call: IrBuilderWithScope.(IrExpression, List) -> IrExpression + call: IrBuilderWithScope.(IrExpression, List) -> IrExpression, ): IrExpression { val children = node.children val child = children[index] return buildExpression(child, variables) { argument, newVariables -> - if (index + 1 == children.size) call(argument, newVariables) // last expression, result is false - else irIfThenElse( - context.irBuiltIns.anyType, - argument, - call(irTrue(), newVariables), // short-circuit result to true - nest(node, index + 1, newVariables, call), // more expressions, continue nesting - ) + if (index + 1 == children.size) { + call(argument, newVariables) // last expression, result is false + } else { + irIfThenElse( + context.irBuiltIns.anyType, + argument, + call(irTrue(), newVariables), // short-circuit result to true + nest(node, index + 1, newVariables, call), // more expressions, continue nesting + ) + } } } diff --git a/kotlin-power-assert-plugin/src/main/kotlin/com/bnorm/power/diagram/ExpressionTree.kt b/kotlin-power-assert-plugin/src/main/kotlin/com/bnorm/power/diagram/ExpressionTree.kt index 1dd5d4b4778..b5e735fd634 100644 --- a/kotlin-power-assert-plugin/src/main/kotlin/com/bnorm/power/diagram/ExpressionTree.kt +++ b/kotlin-power-assert-plugin/src/main/kotlin/com/bnorm/power/diagram/ExpressionTree.kt @@ -75,113 +75,116 @@ fun buildTree(expression: IrExpression): Node? { } val tree = RootNode() - expression.accept(object : IrElementVisitor { - override fun visitElement(element: IrElement, data: Node) { - element.acceptChildren(this, data) - } + expression.accept( + object : IrElementVisitor { + override fun visitElement(element: IrElement, data: Node) { + element.acceptChildren(this, data) + } - override fun visitExpression(expression: IrExpression, data: Node) { - if (expression is IrFunctionExpression) return // Do not transform lambda expressions, especially their body + override fun visitExpression(expression: IrExpression, data: Node) { + if (expression is IrFunctionExpression) return // Do not transform lambda expressions, especially their body - val node = data as? ExpressionNode ?: ExpressionNode().also { data.addChild(it) } - node.add(expression) - expression.acceptChildren(this, node) - } - - override fun visitContainerExpression(expression: IrContainerExpression, data: Node) { - if (expression.origin is IrStatementOrigin.SAFE_CALL) { - // Null safe expressions can be correctly navigated - super.visitContainerExpression(expression, data) - } else { - // Everything else is considered unsafe and terminates the expression tree val node = data as? ExpressionNode ?: ExpressionNode().also { data.addChild(it) } node.add(expression) - } - } - - override fun visitTypeOperator(expression: IrTypeOperatorCall, data: Node) { - val node = data as? ExpressionNode ?: ExpressionNode().also { data.addChild(it) } - if (expression.operator in setOf(IrTypeOperator.INSTANCEOF, IrTypeOperator.NOT_INSTANCEOF)) { - // Only include `is` and `!is` checks - node.add(expression) + expression.acceptChildren(this, node) } - expression.acceptChildren(this, node) - } + override fun visitContainerExpression(expression: IrContainerExpression, data: Node) { + if (expression.origin is IrStatementOrigin.SAFE_CALL) { + // Null safe expressions can be correctly navigated + super.visitContainerExpression(expression, data) + } else { + // Everything else is considered unsafe and terminates the expression tree + val node = data as? ExpressionNode ?: ExpressionNode().also { data.addChild(it) } + node.add(expression) + } + } - override fun visitCall(expression: IrCall, data: Node) { - if (expression.symbol.owner.name.asString() == "EQEQ" && expression.origin == IrStatementOrigin.EXCLEQ) { - // Skip the EQEQ part of a EXCLEQ call + override fun visitTypeOperator(expression: IrTypeOperatorCall, data: Node) { + val node = data as? ExpressionNode ?: ExpressionNode().also { data.addChild(it) } + if (expression.operator in setOf(IrTypeOperator.INSTANCEOF, IrTypeOperator.NOT_INSTANCEOF)) { + // Only include `is` and `!is` checks + node.add(expression) + } + + expression.acceptChildren(this, node) + } + + override fun visitCall(expression: IrCall, data: Node) { + if (expression.symbol.owner.name.asString() == "EQEQ" && expression.origin == IrStatementOrigin.EXCLEQ) { + // Skip the EQEQ part of a EXCLEQ call + expression.acceptChildren(this, data) + } else { + super.visitCall(expression, data) + } + } + + override fun visitVararg(expression: IrVararg, data: Node) { + // Skip processing of vararg array expression.acceptChildren(this, data) - } else { - super.visitCall(expression, data) } - } - override fun visitVararg(expression: IrVararg, data: Node) { - // Skip processing of vararg array - expression.acceptChildren(this, data) - } + override fun visitConst(expression: IrConst<*>, data: Node) { + // Do not include constants + } - override fun visitConst(expression: IrConst<*>, data: Node) { - // Do not include constants - } + override fun visitWhen(expression: IrWhen, data: Node) { + when (expression.origin) { + IrStatementOrigin.ANDAND -> { + // flatten `&&` expressions to be at the same level + val node = data as? AndNode ?: AndNode().also { data.addChild(it) } - override fun visitWhen(expression: IrWhen, data: Node) { - when (expression.origin) { - IrStatementOrigin.ANDAND -> { - // flatten `&&` expressions to be at the same level - val node = data as? AndNode ?: AndNode().also { data.addChild(it) } + require(expression.branches.size == 2) + val thenBranch = expression.branches[0] - require(expression.branches.size == 2) - val thenBranch = expression.branches[0] + thenBranch.condition.accept(this, node) + thenBranch.result.accept(this, node) - thenBranch.condition.accept(this, node) - thenBranch.result.accept(this, node) + val elseBranchCondition = expression.branches[1].condition + val elseBranchResult = expression.branches[1].result - val elseBranchCondition = expression.branches[1].condition - val elseBranchResult = expression.branches[1].result + if (elseBranchCondition !is IrConst<*> || elseBranchCondition.value != true) { + elseBranchCondition.accept(this, node) + } - if (elseBranchCondition !is IrConst<*> || elseBranchCondition.value != true) { - elseBranchCondition.accept(this, node) + if (elseBranchResult !is IrConst<*> || elseBranchResult.value != false) { + elseBranchResult.accept(this, node) + } } + IrStatementOrigin.OROR -> { + // flatten `||` expressions to be at the same level + val node = data as? OrNode ?: OrNode().also { data.addChild(it) } - if (elseBranchResult !is IrConst<*> || elseBranchResult.value != false) { - elseBranchResult.accept(this, node) + require(expression.branches.size == 2) + val thenBranchCondition = expression.branches[0].condition + val thenBranchResult = expression.branches[0].result + val elseBranchCondition = expression.branches[1].condition + val elseBranchResult = expression.branches[1].result + + thenBranchCondition.accept(this, node) + + if (thenBranchResult !is IrConst<*> || thenBranchResult.value != true) { + thenBranchResult.accept(this, node) + } + + if (elseBranchCondition !is IrConst<*> || elseBranchCondition.value != true) { + elseBranchCondition.accept(this, node) + } + + if (elseBranchResult !is IrConst<*> || elseBranchResult.value != false) { + elseBranchResult.accept(this, node) + } } - } - IrStatementOrigin.OROR -> { - // flatten `||` expressions to be at the same level - val node = data as? OrNode ?: OrNode().also { data.addChild(it) } - - require(expression.branches.size == 2) - val thenBranchCondition = expression.branches[0].condition - val thenBranchResult = expression.branches[0].result - val elseBranchCondition = expression.branches[1].condition - val elseBranchResult = expression.branches[1].result - - thenBranchCondition.accept(this, node) - - if (thenBranchResult !is IrConst<*> || thenBranchResult.value != true) { - thenBranchResult.accept(this, node) + else -> { + // Add as basic expression and terminate + // TODO this has to be broken and not work in all cases... + ExpressionNode().also { data.addChild(it) } } - - if (elseBranchCondition !is IrConst<*> || elseBranchCondition.value != true) { - elseBranchCondition.accept(this, node) - } - - if (elseBranchResult !is IrConst<*> || elseBranchResult.value != false) { - elseBranchResult.accept(this, node) - } - } - else -> { - // Add as basic expression and terminate - // TODO this has to be broken and not work in all cases... - ExpressionNode().also { data.addChild(it) } } } - } - }, tree) + }, + tree, + ) return tree.children.singleOrNull() } diff --git a/kotlin-power-assert-plugin/src/main/kotlin/com/bnorm/power/diagram/IrDiagram.kt b/kotlin-power-assert-plugin/src/main/kotlin/com/bnorm/power/diagram/IrDiagram.kt index 900941f8d4d..0fd1dfed5f8 100644 --- a/kotlin-power-assert-plugin/src/main/kotlin/com/bnorm/power/diagram/IrDiagram.kt +++ b/kotlin-power-assert-plugin/src/main/kotlin/com/bnorm/power/diagram/IrDiagram.kt @@ -38,7 +38,7 @@ fun IrBuilderWithScope.irDiagramString( sourceFile: SourceFile, prefix: IrExpression? = null, call: IrCall, - variables: List + variables: List, ): IrExpression { val callInfo = sourceFile.getSourceRangeInfo(call) val callIndent = callInfo.startColumnNumber @@ -69,7 +69,7 @@ fun IrBuilderWithScope.irDiagramString( last = i } } - } + }, ) for (tmp in rowValues.asReversed()) { @@ -83,7 +83,7 @@ fun IrBuilderWithScope.irDiagramString( last = i } indent(tmp.indent - last - 1) - } + }, ) addArgument(irGet(tmp.value)) } @@ -95,13 +95,13 @@ private data class ValueDisplay( val value: IrVariable, val indent: Int, val row: Int, - val source: String + val source: String, ) private fun IrTemporaryVariable.toValueDisplay( fileSource: SourceFile, callIndent: Int, - originalInfo: SourceRangeInfo + originalInfo: SourceRangeInfo, ): ValueDisplay { val info = fileSource.getSourceRangeInfo(original) var indent = info.startColumnNumber - callIndent @@ -158,7 +158,7 @@ private fun IrTemporaryVariable.toValueDisplay( private fun findDisplayOffset( sourceFile: SourceFile, expression: IrExpression, - source: String + source: String, ): Int { return when (expression) { is IrMemberAccessExpression<*> -> memberAccessOffset(sourceFile, expression, source) @@ -170,7 +170,7 @@ private fun findDisplayOffset( private fun memberAccessOffset( sourceFile: SourceFile, expression: IrMemberAccessExpression<*>, - source: String + source: String, ): Int { if (expression.origin == IrStatementOrigin.EXCLEQ || expression.origin == IrStatementOrigin.EXCLEQEQ) { // special case to handle `value != null` @@ -207,7 +207,7 @@ private fun memberAccessOffset( private fun typeOperatorOffset( expression: IrTypeOperatorCall, - source: String + source: String, ): Int { return when (expression.operator) { IrTypeOperator.INSTANCEOF -> source.indexOf(" is ") + 1 diff --git a/kotlin-power-assert-plugin/src/main/kotlin/com/bnorm/power/diagram/IrTemporaryVariable.kt b/kotlin-power-assert-plugin/src/main/kotlin/com/bnorm/power/diagram/IrTemporaryVariable.kt index 27f3ac3d270..710195c9f2a 100644 --- a/kotlin-power-assert-plugin/src/main/kotlin/com/bnorm/power/diagram/IrTemporaryVariable.kt +++ b/kotlin-power-assert-plugin/src/main/kotlin/com/bnorm/power/diagram/IrTemporaryVariable.kt @@ -26,12 +26,12 @@ import org.jetbrains.kotlin.ir.visitors.IrElementTransformerVoid data class IrTemporaryVariable( val temporary: IrVariable, - val original: IrExpression + val original: IrExpression, ) class IrTemporaryExtractionTransformer( private val builder: IrStatementsBuilder<*>, - private val transform: Set + private val transform: Set, ) : IrElementTransformerVoid() { private val _variables = mutableListOf() val variables: List = _variables diff --git a/kotlin-power-assert-plugin/src/main/kotlin/com/bnorm/power/diagram/SourceFile.kt b/kotlin-power-assert-plugin/src/main/kotlin/com/bnorm/power/diagram/SourceFile.kt index d9cb9e1a080..45387004d66 100644 --- a/kotlin-power-assert-plugin/src/main/kotlin/com/bnorm/power/diagram/SourceFile.kt +++ b/kotlin-power-assert-plugin/src/main/kotlin/com/bnorm/power/diagram/SourceFile.kt @@ -9,7 +9,7 @@ import org.jetbrains.kotlin.ir.expressions.IrCall import java.io.File data class SourceFile( - private val irFile: IrFile + private val irFile: IrFile, ) { private val source: String = File(irFile.path).readText() .replace("\r\n", "\n") // https://youtrack.jetbrains.com/issue/KT-41888 diff --git a/kotlin-power-assert-plugin/src/main/kotlin/com/bnorm/power/irUtils.kt b/kotlin-power-assert-plugin/src/main/kotlin/com/bnorm/power/irUtils.kt index f972ef451a2..6e1f201962d 100644 --- a/kotlin-power-assert-plugin/src/main/kotlin/com/bnorm/power/irUtils.kt +++ b/kotlin-power-assert-plugin/src/main/kotlin/com/bnorm/power/irUtils.kt @@ -39,7 +39,7 @@ fun IrBuilderWithScope.irLambda( lambdaType: IrType, startOffset: Int = this.startOffset, endOffset: Int = this.endOffset, - block: IrBlockBodyBuilder.() -> Unit + block: IrBlockBodyBuilder.() -> Unit, ): IrFunctionExpression { val scope = this val lambda = context.irFactory.buildFun { diff --git a/kotlin-power-assert-plugin/src/test/kotlin/com/bnorm/power/ArithmeticExpressionTest.kt b/kotlin-power-assert-plugin/src/test/kotlin/com/bnorm/power/ArithmeticExpressionTest.kt index 54adad9f94b..1ec3a311f20 100644 --- a/kotlin-power-assert-plugin/src/test/kotlin/com/bnorm/power/ArithmeticExpressionTest.kt +++ b/kotlin-power-assert-plugin/src/test/kotlin/com/bnorm/power/ArithmeticExpressionTest.kt @@ -31,7 +31,7 @@ class ArithmeticExpressionTest { | false 2 """.trimIndent(), - actual + actual, ) } @@ -46,7 +46,7 @@ class ArithmeticExpressionTest { | false 2 """.trimIndent(), - actual + actual, ) } @@ -61,7 +61,7 @@ class ArithmeticExpressionTest { | false 2 """.trimIndent(), - actual + actual, ) } @@ -76,7 +76,7 @@ class ArithmeticExpressionTest { | false 2 """.trimIndent(), - actual + actual, ) } @@ -86,7 +86,7 @@ class ArithmeticExpressionTest { """ var i = 1 assert(++i == 4) - """.trimIndent() + """.trimIndent(), ) assertEquals( """ @@ -96,7 +96,7 @@ class ArithmeticExpressionTest { | false 2 """.trimIndent(), - actual + actual, ) } @@ -106,7 +106,7 @@ class ArithmeticExpressionTest { """ var i = 1 assert(i++ == 4) - """.trimIndent() + """.trimIndent(), ) assertEquals( """ @@ -116,7 +116,7 @@ class ArithmeticExpressionTest { | false 1 """.trimIndent(), - actual + actual, ) } @@ -126,7 +126,7 @@ class ArithmeticExpressionTest { """ var i = 3 assert(--i == 4) - """.trimIndent() + """.trimIndent(), ) assertEquals( """ @@ -136,7 +136,7 @@ class ArithmeticExpressionTest { | false 2 """.trimIndent(), - actual + actual, ) } @@ -146,7 +146,7 @@ class ArithmeticExpressionTest { """ var i = 3 assert(i-- == 4) - """.trimIndent() + """.trimIndent(), ) assertEquals( """ @@ -156,7 +156,7 @@ class ArithmeticExpressionTest { | false 3 """.trimIndent(), - actual + actual, ) } } diff --git a/kotlin-power-assert-plugin/src/test/kotlin/com/bnorm/power/AssertTest.kt b/kotlin-power-assert-plugin/src/test/kotlin/com/bnorm/power/AssertTest.kt index a4726792610..076e4af961e 100644 --- a/kotlin-power-assert-plugin/src/test/kotlin/com/bnorm/power/AssertTest.kt +++ b/kotlin-power-assert-plugin/src/test/kotlin/com/bnorm/power/AssertTest.kt @@ -37,7 +37,7 @@ assert(hello.length == "World".substring(1, 4).length) | | false | 5 Hello -""".trimIndent() + """.trimIndent(), ) } @@ -57,7 +57,7 @@ assert(hello.reversed() == emptyList()) | | false | [World, Hello] [Hello, World] -""".trimIndent() + """.trimIndent(), ) } @@ -73,7 +73,7 @@ Not equal assert(1 == 2) { "Not equal" } | false -""".trimIndent() + """.trimIndent(), ) } @@ -90,7 +90,7 @@ fun main() { assert(1 == 2, lambda) | false - """.trimIndent() + """.trimIndent(), ) } @@ -108,7 +108,7 @@ assert(text != null && text.length == 1) | | | false null -""".trimIndent() + """.trimIndent(), ) } @@ -133,7 +133,7 @@ assert(text != null && text.length == 5 && text.toLowerCase() == text) | | Hello | true Hello -""".trimIndent() + """.trimIndent(), ) } @@ -158,7 +158,7 @@ assert(text == null || text.length == 1 || text.toLowerCase() == text) | | Hello | false Hello -""".trimIndent() + """.trimIndent(), ) } @@ -183,7 +183,7 @@ assert(text != null && (text.length == 1 || text.toLowerCase() == text)) | | Hello | true Hello -""".trimIndent() + """.trimIndent(), ) } @@ -206,7 +206,7 @@ assert((text.length == 1 || text.toLowerCase() == text) && text.length == 1) | | false | 5 Hello -""".trimIndent() + """.trimIndent(), ) } @@ -231,7 +231,7 @@ assert(text == null || (text.length == 5 && text.toLowerCase() == text)) | | Hello | false Hello -""".trimIndent() + """.trimIndent(), ) } @@ -257,7 +257,7 @@ assert((text.length == 5 && text.toLowerCase() == text) || text.length == 1) | | true | 5 Hello -""".trimIndent() + """.trimIndent(), ) } @@ -277,7 +277,7 @@ assert(text?.length?.minus(2) == 1) | | 3 | 5 Hello -""".trimIndent() + """.trimIndent(), ) } @@ -294,7 +294,7 @@ fun main() { | | | false 2 - """.trimIndent() + """.trimIndent(), ) assertMessage( @@ -308,7 +308,7 @@ assert(1 shl 1 == 4) | | | false 2 -""".trimIndent() + """.trimIndent(), ) } @@ -349,7 +349,7 @@ assert( Hello ) ) -""".trimIndent() + """.trimIndent(), ) } @@ -368,8 +368,8 @@ Hello, the world is broken assertTrue(1 == 2, message = "${"$"}text, the world is broken") | false -""".trimIndent(), - PowerAssertComponentRegistrar(setOf(FqName("kotlin.test.assertTrue"))) + """.trimIndent(), + PowerAssertComponentRegistrar(setOf(FqName("kotlin.test.assertTrue"))), ) } @@ -385,8 +385,8 @@ the world is broken require(1 == 2) { "the world is broken" } | false -""".trimIndent(), - PowerAssertComponentRegistrar(setOf(FqName("kotlin.require"))) + """.trimIndent(), + PowerAssertComponentRegistrar(setOf(FqName("kotlin.require"))), ) } @@ -402,8 +402,8 @@ the world is broken check(1 == 2) { "the world is broken" } | false -""".trimIndent(), - PowerAssertComponentRegistrar(setOf(FqName("kotlin.check"))) + """.trimIndent(), + PowerAssertComponentRegistrar(setOf(FqName("kotlin.check"))), ) } @@ -421,7 +421,8 @@ assert(a == 42) | | | false 0 -""".trimIndent()) + """.trimIndent(), + ) } @Test @@ -434,7 +435,7 @@ fun main() { }""", """ Assertion failed -""".trimIndent() + """.trimIndent(), ) } } diff --git a/kotlin-power-assert-plugin/src/test/kotlin/com/bnorm/power/CastExpressionTest.kt b/kotlin-power-assert-plugin/src/test/kotlin/com/bnorm/power/CastExpressionTest.kt index a871d45f9d3..546adbc739a 100644 --- a/kotlin-power-assert-plugin/src/test/kotlin/com/bnorm/power/CastExpressionTest.kt +++ b/kotlin-power-assert-plugin/src/test/kotlin/com/bnorm/power/CastExpressionTest.kt @@ -30,7 +30,7 @@ class CastExpressionTest { | false """.trimIndent(), - actual + actual, ) } @@ -44,7 +44,7 @@ class CastExpressionTest { | false """.trimIndent(), - actual + actual, ) } @@ -54,7 +54,7 @@ class CastExpressionTest { """ val greeting: Any = "hello" assert(greeting is String && greeting.length == 2) - """.trimIndent() + """.trimIndent(), ) assertEquals( """ @@ -67,7 +67,7 @@ class CastExpressionTest { | true hello """.trimIndent(), - actual + actual, ) } } 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 9ee7605cc41..c6b2906938c 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 @@ -31,7 +31,7 @@ class DebugFunctionTest { val actual = executeMainDebug( """ dbg(1 + 2 + 3) - """.trimIndent() + """.trimIndent(), ) assertEquals( """ @@ -40,7 +40,7 @@ class DebugFunctionTest { | 6 3 """.trimIndent(), - actual.trim() + actual.trim(), ) } @@ -49,7 +49,7 @@ class DebugFunctionTest { val actual = executeMainDebug( """ dbg(1 + 2 + 3, "Message:") - """.trimIndent() + """.trimIndent(), ) assertEquals( """ @@ -59,7 +59,7 @@ class DebugFunctionTest { | 6 3 """.trimIndent(), - actual.trim() + actual.trim(), ) } } @@ -79,7 +79,7 @@ fun main() { $mainBody } """, - trimIndent = false + trimIndent = false, ) val result = compile(listOf(file), PowerAssertComponentRegistrar(setOf(FqName("dbg")))) @@ -96,8 +96,9 @@ fun getMainResult(main: Method): String { fail("main did not throw expected exception") } catch (t: InvocationTargetException) { with(t.cause) { - if (this is RuntimeException && message != null && message!!.startsWith("result:")) + if (this is RuntimeException && message != null && message!!.startsWith("result:")) { return message!!.substringAfter("result:") + } } throw t.cause!! } 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 ab13d92a3f5..bee9cdb3bd8 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 @@ -30,7 +30,7 @@ class InfixFunctionTest { val actual = runExtensionInfix( """ (1 + 1) mustEqual (2 + 4) - """.trimIndent() + """.trimIndent(), ) assertEquals( """ @@ -39,7 +39,7 @@ class InfixFunctionTest { | 6 2 """.trimIndent(), - actual.trim() + actual.trim(), ) } @@ -48,7 +48,7 @@ class InfixFunctionTest { val actual = runExtensionInfix( """ 1 mustEqual (2 + 4) - """.trimIndent() + """.trimIndent(), ) assertEquals( """ @@ -56,7 +56,7 @@ class InfixFunctionTest { | 6 """.trimIndent(), - actual.trim() + actual.trim(), ) } @@ -65,7 +65,7 @@ class InfixFunctionTest { val actual = runExtensionInfix( """ (1 + 1) mustEqual 6 - """.trimIndent() + """.trimIndent(), ) assertEquals( """ @@ -73,7 +73,7 @@ class InfixFunctionTest { | 2 """.trimIndent(), - actual.trim() + actual.trim(), ) } @@ -82,13 +82,13 @@ class InfixFunctionTest { val actual = runExtensionInfix( """ 2 mustEqual 6 - """.trimIndent() + """.trimIndent(), ) assertEquals( """ Assertion failed """.trimIndent(), - actual.trim() + actual.trim(), ) } @@ -97,7 +97,7 @@ class InfixFunctionTest { val actual = runExtensionInfix( """ (1 + 1).mustEqual(2 + 4) - """.trimIndent() + """.trimIndent(), ) assertEquals( """ @@ -106,7 +106,7 @@ class InfixFunctionTest { | 6 2 """.trimIndent(), - actual.trim() + actual.trim(), ) } @@ -115,7 +115,7 @@ class InfixFunctionTest { val actual = runExtensionInfix( """ 1.mustEqual(2 + 4) - """.trimIndent() + """.trimIndent(), ) assertEquals( """ @@ -123,7 +123,7 @@ class InfixFunctionTest { | 6 """.trimIndent(), - actual.trim() + actual.trim(), ) } @@ -132,7 +132,7 @@ class InfixFunctionTest { val actual = runExtensionInfix( """ (1 + 1).mustEqual(6) - """.trimIndent() + """.trimIndent(), ) assertEquals( """ @@ -140,7 +140,7 @@ class InfixFunctionTest { | 2 """.trimIndent(), - actual.trim() + actual.trim(), ) } @@ -149,13 +149,13 @@ class InfixFunctionTest { val actual = runExtensionInfix( """ 2.mustEqual(6) - """.trimIndent() + """.trimIndent(), ) assertEquals( """ Assertion failed """.trimIndent(), - actual.trim() + actual.trim(), ) } @@ -164,7 +164,7 @@ class InfixFunctionTest { val actual = runDispatchInfix( """ Wrapper(1 + 1) mustEqual (2 + 4) - """.trimIndent() + """.trimIndent(), ) assertEquals( """ @@ -174,7 +174,7 @@ class InfixFunctionTest { | 2 Wrapper """.trimIndent(), - actual.trim() + actual.trim(), ) } @@ -183,7 +183,7 @@ class InfixFunctionTest { val actual = runDispatchInfix( """ Wrapper(1) mustEqual (2 + 4) - """.trimIndent() + """.trimIndent(), ) assertEquals( """ @@ -192,7 +192,7 @@ class InfixFunctionTest { | 6 Wrapper """.trimIndent(), - actual.trim() + actual.trim(), ) } @@ -201,7 +201,7 @@ class InfixFunctionTest { val actual = runDispatchInfix( """ Wrapper(1 + 1) mustEqual 6 - """.trimIndent() + """.trimIndent(), ) assertEquals( """ @@ -210,7 +210,7 @@ class InfixFunctionTest { | 2 Wrapper """.trimIndent(), - actual.trim() + actual.trim(), ) } @@ -219,7 +219,7 @@ class InfixFunctionTest { val actual = runDispatchInfix( """ Wrapper(2) mustEqual 6 - """.trimIndent() + """.trimIndent(), ) assertEquals( """ @@ -227,7 +227,7 @@ class InfixFunctionTest { | Wrapper """.trimIndent(), - actual.trim() + actual.trim(), ) } @@ -236,7 +236,7 @@ class InfixFunctionTest { val actual = runDispatchInfix( """ Wrapper(1 + 1).mustEqual(2 + 4) - """.trimIndent() + """.trimIndent(), ) assertEquals( """ @@ -246,7 +246,7 @@ class InfixFunctionTest { | 2 Wrapper """.trimIndent(), - actual.trim() + actual.trim(), ) } @@ -255,7 +255,7 @@ class InfixFunctionTest { val actual = runDispatchInfix( """ Wrapper(1).mustEqual(2 + 4) - """.trimIndent() + """.trimIndent(), ) assertEquals( """ @@ -264,7 +264,7 @@ class InfixFunctionTest { | 6 Wrapper """.trimIndent(), - actual.trim() + actual.trim(), ) } @@ -273,7 +273,7 @@ class InfixFunctionTest { val actual = runDispatchInfix( """ Wrapper(1 + 1).mustEqual(6) - """.trimIndent() + """.trimIndent(), ) assertEquals( """ @@ -282,7 +282,7 @@ class InfixFunctionTest { | 2 Wrapper """.trimIndent(), - actual.trim() + actual.trim(), ) } @@ -291,7 +291,7 @@ class InfixFunctionTest { val actual = runDispatchInfix( """ Wrapper(2).mustEqual(6) - """.trimIndent() + """.trimIndent(), ) assertEquals( """ @@ -299,7 +299,7 @@ class InfixFunctionTest { | Wrapper """.trimIndent(), - actual.trim() + actual.trim(), ) } @@ -317,9 +317,9 @@ class InfixFunctionTest { $mainBody } """.trimIndent(), - trimIndent = false + trimIndent = false, ), - setOf(FqName("mustEqual")) + setOf(FqName("mustEqual")), ) } @@ -343,9 +343,9 @@ class InfixFunctionTest { $mainBody } """.trimIndent(), - trimIndent = false + trimIndent = false, ), - setOf(FqName("Wrapper.mustEqual")) + setOf(FqName("Wrapper.mustEqual")), ) } diff --git a/kotlin-power-assert-plugin/src/test/kotlin/com/bnorm/power/Junit5AssertionsTest.kt b/kotlin-power-assert-plugin/src/test/kotlin/com/bnorm/power/Junit5AssertionsTest.kt index a95873a1073..c6d6707ae3f 100644 --- a/kotlin-power-assert-plugin/src/test/kotlin/com/bnorm/power/Junit5AssertionsTest.kt +++ b/kotlin-power-assert-plugin/src/test/kotlin/com/bnorm/power/Junit5AssertionsTest.kt @@ -35,7 +35,7 @@ class Junit5AssertionsTest { | false ==> expected: but was: """.trimIndent(), - PowerAssertComponentRegistrar(setOf(FqName("org.junit.jupiter.api.Assertions.assertTrue"))) + PowerAssertComponentRegistrar(setOf(FqName("org.junit.jupiter.api.Assertions.assertTrue"))), ) } @@ -54,7 +54,7 @@ class Junit5AssertionsTest { | false ==> expected: but was: """.trimIndent(), - PowerAssertComponentRegistrar(setOf(FqName("org.junit.jupiter.api.Assertions.assertTrue"))) + PowerAssertComponentRegistrar(setOf(FqName("org.junit.jupiter.api.Assertions.assertTrue"))), ) } @@ -74,7 +74,7 @@ class Junit5AssertionsTest { | false ==> expected: but was: """.trimIndent(), - PowerAssertComponentRegistrar(setOf(FqName("org.junit.jupiter.api.Assertions.assertTrue"))) + PowerAssertComponentRegistrar(setOf(FqName("org.junit.jupiter.api.Assertions.assertTrue"))), ) } @@ -93,7 +93,7 @@ class Junit5AssertionsTest { | false ==> expected: but was: """.trimIndent(), - PowerAssertComponentRegistrar(setOf(FqName("org.junit.jupiter.api.Assertions.assertTrue"))) + PowerAssertComponentRegistrar(setOf(FqName("org.junit.jupiter.api.Assertions.assertTrue"))), ) } @@ -114,7 +114,7 @@ class Junit5AssertionsTest { | false ==> expected: but was: """.trimIndent(), - PowerAssertComponentRegistrar(setOf(FqName("org.junit.jupiter.api.Assertions.assertTrue"))) + PowerAssertComponentRegistrar(setOf(FqName("org.junit.jupiter.api.Assertions.assertTrue"))), ) } @@ -133,7 +133,7 @@ class Junit5AssertionsTest { | true ==> expected: but was: """.trimIndent(), - PowerAssertComponentRegistrar(setOf(FqName("org.junit.jupiter.api.Assertions.assertFalse"))) + PowerAssertComponentRegistrar(setOf(FqName("org.junit.jupiter.api.Assertions.assertFalse"))), ) } @@ -152,7 +152,7 @@ class Junit5AssertionsTest { | true ==> expected: but was: """.trimIndent(), - PowerAssertComponentRegistrar(setOf(FqName("org.junit.jupiter.api.Assertions.assertFalse"))) + PowerAssertComponentRegistrar(setOf(FqName("org.junit.jupiter.api.Assertions.assertFalse"))), ) } @@ -172,7 +172,7 @@ class Junit5AssertionsTest { | true ==> expected: but was: """.trimIndent(), - PowerAssertComponentRegistrar(setOf(FqName("org.junit.jupiter.api.Assertions.assertFalse"))) + PowerAssertComponentRegistrar(setOf(FqName("org.junit.jupiter.api.Assertions.assertFalse"))), ) } @@ -191,7 +191,7 @@ class Junit5AssertionsTest { | true ==> expected: but was: """.trimIndent(), - PowerAssertComponentRegistrar(setOf(FqName("org.junit.jupiter.api.Assertions.assertFalse"))) + PowerAssertComponentRegistrar(setOf(FqName("org.junit.jupiter.api.Assertions.assertFalse"))), ) } @@ -212,7 +212,7 @@ class Junit5AssertionsTest { | true ==> expected: but was: """.trimIndent(), - PowerAssertComponentRegistrar(setOf(FqName("org.junit.jupiter.api.Assertions.assertFalse"))) + PowerAssertComponentRegistrar(setOf(FqName("org.junit.jupiter.api.Assertions.assertFalse"))), ) } @@ -233,7 +233,7 @@ class Junit5AssertionsTest { | World Hello ==> expected: but was: """.trimIndent(), - PowerAssertComponentRegistrar(setOf(FqName("org.junit.jupiter.api.Assertions.assertEquals"))) + PowerAssertComponentRegistrar(setOf(FqName("org.junit.jupiter.api.Assertions.assertEquals"))), ) } @@ -255,7 +255,7 @@ class Junit5AssertionsTest { | World Hello ==> expected: but was: """.trimIndent(), - PowerAssertComponentRegistrar(setOf(FqName("org.junit.jupiter.api.Assertions.assertEquals"))) + PowerAssertComponentRegistrar(setOf(FqName("org.junit.jupiter.api.Assertions.assertEquals"))), ) } @@ -278,7 +278,7 @@ class Junit5AssertionsTest { | World Hello ==> expected: but was: """.trimIndent(), - PowerAssertComponentRegistrar(setOf(FqName("org.junit.jupiter.api.Assertions.assertEquals"))) + PowerAssertComponentRegistrar(setOf(FqName("org.junit.jupiter.api.Assertions.assertEquals"))), ) } @@ -300,7 +300,7 @@ class Junit5AssertionsTest { | World Hello ==> expected: but was: """.trimIndent(), - PowerAssertComponentRegistrar(setOf(FqName("org.junit.jupiter.api.Assertions.assertEquals"))) + PowerAssertComponentRegistrar(setOf(FqName("org.junit.jupiter.api.Assertions.assertEquals"))), ) } @@ -324,7 +324,7 @@ class Junit5AssertionsTest { | World Hello ==> expected: but was: """.trimIndent(), - PowerAssertComponentRegistrar(setOf(FqName("org.junit.jupiter.api.Assertions.assertEquals"))) + PowerAssertComponentRegistrar(setOf(FqName("org.junit.jupiter.api.Assertions.assertEquals"))), ) } } diff --git a/kotlin-power-assert-plugin/src/test/kotlin/com/bnorm/power/KotlinTestAssertTest.kt b/kotlin-power-assert-plugin/src/test/kotlin/com/bnorm/power/KotlinTestAssertTest.kt index 5032dcee952..a306cc69457 100644 --- a/kotlin-power-assert-plugin/src/test/kotlin/com/bnorm/power/KotlinTestAssertTest.kt +++ b/kotlin-power-assert-plugin/src/test/kotlin/com/bnorm/power/KotlinTestAssertTest.kt @@ -35,7 +35,7 @@ class KotlinTestAssertTest { | false """.trimIndent(), - PowerAssertComponentRegistrar(setOf(FqName("kotlin.test.assertTrue"))) + PowerAssertComponentRegistrar(setOf(FqName("kotlin.test.assertTrue"))), ) } @@ -54,7 +54,7 @@ class KotlinTestAssertTest { | false """.trimIndent(), - PowerAssertComponentRegistrar(setOf(FqName("kotlin.test.assertTrue"))) + PowerAssertComponentRegistrar(setOf(FqName("kotlin.test.assertTrue"))), ) } @@ -74,7 +74,7 @@ class KotlinTestAssertTest { | false """.trimIndent(), - PowerAssertComponentRegistrar(setOf(FqName("kotlin.test.assertTrue"))) + PowerAssertComponentRegistrar(setOf(FqName("kotlin.test.assertTrue"))), ) } @@ -93,7 +93,7 @@ class KotlinTestAssertTest { | true """.trimIndent(), - PowerAssertComponentRegistrar(setOf(FqName("kotlin.test.assertFalse"))) + PowerAssertComponentRegistrar(setOf(FqName("kotlin.test.assertFalse"))), ) } @@ -112,7 +112,7 @@ class KotlinTestAssertTest { | true """.trimIndent(), - PowerAssertComponentRegistrar(setOf(FqName("kotlin.test.assertFalse"))) + PowerAssertComponentRegistrar(setOf(FqName("kotlin.test.assertFalse"))), ) } @@ -132,7 +132,7 @@ class KotlinTestAssertTest { | true """.trimIndent(), - PowerAssertComponentRegistrar(setOf(FqName("kotlin.test.assertFalse"))) + PowerAssertComponentRegistrar(setOf(FqName("kotlin.test.assertFalse"))), ) } @@ -153,7 +153,7 @@ class KotlinTestAssertTest { | World Hello ==> expected: but was: """.trimIndent(), - PowerAssertComponentRegistrar(setOf(FqName("kotlin.test.assertEquals"))) + PowerAssertComponentRegistrar(setOf(FqName("kotlin.test.assertEquals"))), ) } @@ -175,7 +175,7 @@ class KotlinTestAssertTest { | World Hello ==> expected: but was: """.trimIndent(), - PowerAssertComponentRegistrar(setOf(FqName("kotlin.test.assertEquals"))) + PowerAssertComponentRegistrar(setOf(FqName("kotlin.test.assertEquals"))), ) } @@ -198,7 +198,7 @@ class KotlinTestAssertTest { | World Hello ==> expected: but was: """.trimIndent(), - PowerAssertComponentRegistrar(setOf(FqName("kotlin.test.assertEquals"))) + PowerAssertComponentRegistrar(setOf(FqName("kotlin.test.assertEquals"))), ) } @@ -217,7 +217,7 @@ class KotlinTestAssertTest { | null ==> expected: not """.trimIndent(), - PowerAssertComponentRegistrar(setOf(FqName("kotlin.test.assertNotNull"))) + PowerAssertComponentRegistrar(setOf(FqName("kotlin.test.assertNotNull"))), ) } @@ -237,7 +237,7 @@ class KotlinTestAssertTest { | null ==> expected: not """.trimIndent(), - PowerAssertComponentRegistrar(setOf(FqName("kotlin.test.assertNotNull"))) + PowerAssertComponentRegistrar(setOf(FqName("kotlin.test.assertNotNull"))), ) } @@ -258,7 +258,7 @@ class KotlinTestAssertTest { | null ==> expected: not """.trimIndent(), - PowerAssertComponentRegistrar(setOf(FqName("kotlin.test.assertNotNull"))) + PowerAssertComponentRegistrar(setOf(FqName("kotlin.test.assertNotNull"))), ) } } diff --git a/kotlin-power-assert-plugin/src/test/kotlin/com/bnorm/power/LamdaTest.kt b/kotlin-power-assert-plugin/src/test/kotlin/com/bnorm/power/LamdaTest.kt index 763dc1f90ae..060da7a2940 100644 --- a/kotlin-power-assert-plugin/src/test/kotlin/com/bnorm/power/LamdaTest.kt +++ b/kotlin-power-assert-plugin/src/test/kotlin/com/bnorm/power/LamdaTest.kt @@ -35,7 +35,7 @@ class LamdaTest { | | false | [Doe, Jane, Doe, John] [Jane, John] - """.trimIndent() + """.trimIndent(), ) } @@ -65,7 +65,7 @@ class LamdaTest { false ) """.trimIndent(), - PowerAssertComponentRegistrar(setOf(FqName("kotlin.require"))) + PowerAssertComponentRegistrar(setOf(FqName("kotlin.require"))), ) } } 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 3900b7c0b28..e447920bf9c 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 @@ -29,7 +29,7 @@ class MultiParameterFunctionTest { """ val operation = "sum" dbg(operation, 1 + 2 + 3) - """.trimIndent() + """.trimIndent(), ) assertEquals( """ @@ -40,7 +40,7 @@ class MultiParameterFunctionTest { | 3 sum """.trimIndent(), - actual.trim() + actual.trim(), ) } @@ -54,7 +54,7 @@ class MultiParameterFunctionTest { key = greeting != null && greeting.length == 5, value = name == null || name.length == 5 ) - """.trimIndent() + """.trimIndent(), ) assertEquals( """ @@ -70,7 +70,7 @@ class MultiParameterFunctionTest { null ) """.trimIndent(), - actual.trim() + actual.trim(), ) } @@ -80,7 +80,7 @@ class MultiParameterFunctionTest { """ val operation = "sum" dbg(operation, 1 + 2 + 3, "Message:") - """.trimIndent() + """.trimIndent(), ) assertEquals( """ @@ -92,7 +92,7 @@ class MultiParameterFunctionTest { | 3 sum """.trimIndent(), - actual.trim() + actual.trim(), ) } @@ -107,7 +107,7 @@ class MultiParameterFunctionTest { value = name == null || name.length == 5, msg = "Message:" ) - """.trimIndent() + """.trimIndent(), ) assertEquals( """ @@ -125,7 +125,7 @@ class MultiParameterFunctionTest { msg = "Message:" ) """.trimIndent(), - actual.trim() + actual.trim(), ) } } @@ -145,7 +145,7 @@ fun main() { $mainBody } """, - trimIndent = false + trimIndent = false, ) val result = compile(listOf(file), PowerAssertComponentRegistrar(setOf(FqName("dbg")))) diff --git a/kotlin-power-assert-plugin/src/test/kotlin/com/bnorm/power/RegexMatchTest.kt b/kotlin-power-assert-plugin/src/test/kotlin/com/bnorm/power/RegexMatchTest.kt index ca23e36f646..fd806cfaf90 100644 --- a/kotlin-power-assert-plugin/src/test/kotlin/com/bnorm/power/RegexMatchTest.kt +++ b/kotlin-power-assert-plugin/src/test/kotlin/com/bnorm/power/RegexMatchTest.kt @@ -31,7 +31,7 @@ class RegexMatchTest { | [A-Za-z]+ false """.trimIndent(), - actual + actual, ) } @@ -46,7 +46,7 @@ class RegexMatchTest { | [A-Za-z]+ false """.trimIndent(), - actual + actual, ) } } diff --git a/kotlin-power-assert-plugin/src/test/kotlin/com/bnorm/power/compiler.kt b/kotlin-power-assert-plugin/src/test/kotlin/com/bnorm/power/compiler.kt index e2fa94c0f0c..5d0ddd7d962 100644 --- a/kotlin-power-assert-plugin/src/test/kotlin/com/bnorm/power/compiler.kt +++ b/kotlin-power-assert-plugin/src/test/kotlin/com/bnorm/power/compiler.kt @@ -27,12 +27,12 @@ import kotlin.test.assertEquals import kotlin.test.fail private val DEFAULT_COMPONENT_REGISTRARS = arrayOf( - PowerAssertComponentRegistrar(setOf(FqName("kotlin.assert"))) + PowerAssertComponentRegistrar(setOf(FqName("kotlin.assert"))), ) fun compile( list: List, - vararg plugins: ComponentRegistrar = DEFAULT_COMPONENT_REGISTRARS + vararg plugins: ComponentRegistrar = DEFAULT_COMPONENT_REGISTRARS, ): KotlinCompilation.Result { return KotlinCompilation().apply { sources = list @@ -53,7 +53,7 @@ fun compile( fun executeAssertion( @Language("kotlin") source: String, - vararg plugins: ComponentRegistrar = DEFAULT_COMPONENT_REGISTRARS + vararg plugins: ComponentRegistrar = DEFAULT_COMPONENT_REGISTRARS, ): String { val result = compile( listOf(SourceFile.kotlin("main.kt", source, trimIndent = false)), @@ -80,13 +80,13 @@ fun executeMainAssertion(mainBody: String) = executeAssertion( fun main() { $mainBody } -""" +""", ) fun assertMessage( @Language("kotlin") source: String, message: String, - vararg plugins: ComponentRegistrar = DEFAULT_COMPONENT_REGISTRARS + vararg plugins: ComponentRegistrar = DEFAULT_COMPONENT_REGISTRARS, ) { val actual = executeAssertion(source, *plugins) assertEquals(message, actual)