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
This commit is contained in:
Christoph Sturm
2023-04-07 14:42:43 +02:00
committed by GitHub
parent 36fe1734bd
commit 87b209ab91
31 changed files with 284 additions and 269 deletions
+2
View File
@@ -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 = 2147483647
ij_kotlin_name_count_to_use_star_import_for_members = 2147483647 ij_kotlin_name_count_to_use_star_import_for_members = 2147483647
ij_kotlin_packages_to_use_import_on_demand = unset ij_kotlin_packages_to_use_import_on_demand = unset
ij_kotlin_allow_trailing_comma_on_call_site = true
ij_kotlin_allow_trailing_comma = true
+1 -1
View File
@@ -47,7 +47,7 @@ jobs:
steps: steps:
- uses: actions/checkout@v3 - uses: actions/checkout@v3
- name: Run ktlint - name: Run ktlint
uses: ScaCap/action-ktlint@1.4 uses: ScaCap/action-ktlint@1.5.1
with: with:
github_token: ${{ secrets.GITHUB_TOKEN }} github_token: ${{ secrets.GITHUB_TOKEN }}
reporter: github-pr-check reporter: github-pr-check
+1
View File
@@ -3,6 +3,7 @@ plugins {
id("org.jetbrains.dokka") version "1.7.0" apply false id("org.jetbrains.dokka") version "1.7.0" apply false
id("com.gradle.plugin-publish") version "1.1.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("com.github.gmazzo.buildconfig") version "3.1.0" apply false
// id("org.jmailen.kotlinter") version "3.14.0" apply false
} }
allprojects { allprojects {
@@ -5,6 +5,7 @@ plugins {
kotlin("jvm") kotlin("jvm")
id("com.gradle.plugin-publish") id("com.gradle.plugin-publish")
id("com.github.gmazzo.buildconfig") id("com.github.gmazzo.buildconfig")
// id("org.jmailen.kotlinter")
} }
dependencies { dependencies {
@@ -39,11 +39,11 @@ class PowerAssertGradlePlugin : KotlinCompilerPluginSupportPlugin {
override fun getPluginArtifact(): SubpluginArtifact = SubpluginArtifact( override fun getPluginArtifact(): SubpluginArtifact = SubpluginArtifact(
groupId = BuildConfig.PLUGIN_GROUP_ID, groupId = BuildConfig.PLUGIN_GROUP_ID,
artifactId = BuildConfig.PLUGIN_ARTIFACT_ID, artifactId = BuildConfig.PLUGIN_ARTIFACT_ID,
version = BuildConfig.PLUGIN_VERSION version = BuildConfig.PLUGIN_VERSION,
) )
override fun applyToCompilation( override fun applyToCompilation(
kotlinCompilation: KotlinCompilation<*> kotlinCompilation: KotlinCompilation<*>,
): Provider<List<SubpluginOption>> { ): Provider<List<SubpluginOption>> {
val project = kotlinCompilation.target.project val project = kotlinCompilation.target.project
val extension = project.extensions.getByType(PowerAssertGradleExtension::class.java) val extension = project.extensions.getByType(PowerAssertGradleExtension::class.java)
@@ -7,6 +7,7 @@ plugins {
signing signing
`maven-publish` `maven-publish`
// id("org.jmailen.kotlinter")
} }
dependencies { dependencies {
@@ -68,7 +68,7 @@ class PowerAssertCallTransformer(
private val sourceFile: SourceFile, private val sourceFile: SourceFile,
private val context: IrPluginContext, private val context: IrPluginContext,
private val messageCollector: MessageCollector, private val messageCollector: MessageCollector,
private val functions: Set<FqName> private val functions: Set<FqName>,
) : IrElementTransformerVoidWithContext() { ) : IrElementTransformerVoidWithContext() {
private val irTypeSystemContext = IrTypeSystemContextImpl(context.irBuiltIns) private val irTypeSystemContext = IrTypeSystemContextImpl(context.irBuiltIns)
@@ -95,7 +95,7 @@ class PowerAssertCallTransformer(
| - $fqName($valueTypesTruncated() -> String) | - $fqName($valueTypesTruncated() -> String)
| - $fqName(${valueTypesAll}String) | - $fqName(${valueTypesAll}String)
| - $fqName($valueTypesAll() -> String) | - $fqName($valueTypesAll() -> String)
""".trimMargin() """.trimMargin(),
) )
return super.visitCall(expression) return super.visitCall(expression)
} }
@@ -132,7 +132,7 @@ class PowerAssertCallTransformer(
messageArgument = messageArgument, messageArgument = messageArgument,
roots = roots, roots = roots,
dispatchRoot = dispatchRoot, dispatchRoot = dispatchRoot,
extensionRoot = extensionRoot extensionRoot = extensionRoot,
) )
} }
@@ -142,14 +142,14 @@ class PowerAssertCallTransformer(
messageArgument: IrExpression?, messageArgument: IrExpression?,
roots: List<Node?>, roots: List<Node?>,
dispatchRoot: Node? = null, dispatchRoot: Node? = null,
extensionRoot: Node? = null extensionRoot: Node? = null,
): IrExpression { ): IrExpression {
fun recursive( fun recursive(
index: Int, index: Int,
dispatch: IrExpression?, dispatch: IrExpression?,
extension: IrExpression?, extension: IrExpression?,
arguments: List<IrExpression?>, arguments: List<IrExpression?>,
variables: List<IrTemporaryVariable> variables: List<IrTemporaryVariable>,
): IrExpression { ): IrExpression {
if (index >= roots.size) { if (index >= roots.size) {
val prefix = buildMessagePrefix(messageArgument, delegate.messageParameter, roots, call) val prefix = buildMessagePrefix(messageArgument, delegate.messageParameter, roots, call)
@@ -181,7 +181,7 @@ class PowerAssertCallTransformer(
messageArgument: IrExpression?, messageArgument: IrExpression?,
messageParameter: IrValueParameter, messageParameter: IrValueParameter,
roots: List<Node?>, roots: List<Node?>,
original: IrCall original: IrCall,
): IrExpression? { ): IrExpression? {
return when { return when {
messageArgument is IrConst<*> -> messageArgument messageArgument is IrConst<*> -> messageArgument
@@ -32,14 +32,14 @@ class PowerAssertCommandLineProcessor : CommandLineProcessor {
valueDescription = "function full-qualified name", valueDescription = "function full-qualified name",
description = "fully qualified path of function to intercept", description = "fully qualified path of function to intercept",
required = false, // TODO required for Kotlin/JS required = false, // TODO required for Kotlin/JS
allowMultipleOccurrences = true allowMultipleOccurrences = true,
) ),
) )
override fun processOption( override fun processOption(
option: AbstractCliOption, option: AbstractCliOption,
value: String, value: String,
configuration: CompilerConfiguration configuration: CompilerConfiguration,
) { ) {
return when (option.optionName) { return when (option.optionName) {
"function" -> configuration.add(KEY_FUNCTIONS, value) "function" -> configuration.add(KEY_FUNCTIONS, value)
@@ -30,13 +30,14 @@ val KEY_FUNCTIONS = CompilerConfigurationKey<List<String>>("fully-qualified func
@AutoService(ComponentRegistrar::class) @AutoService(ComponentRegistrar::class)
class PowerAssertComponentRegistrar( class PowerAssertComponentRegistrar(
private val functions: Set<FqName> private val functions: Set<FqName>,
) : ComponentRegistrar { ) : ComponentRegistrar {
@Suppress("unused") constructor() : this(emptySet()) // Used by service loader @Suppress("unused")
constructor() : this(emptySet()) // Used by service loader
override fun registerProjectComponents( override fun registerProjectComponents(
project: MockProject, project: MockProject,
configuration: CompilerConfiguration 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
@@ -45,5 +46,3 @@ class PowerAssertComponentRegistrar(
IrGenerationExtension.registerExtension(project, PowerAssertIrGenerationExtension(messageCollector, functions.toSet())) IrGenerationExtension.registerExtension(project, PowerAssertIrGenerationExtension(messageCollector, functions.toSet()))
} }
} }
@@ -25,7 +25,7 @@ import org.jetbrains.kotlin.name.FqName
class PowerAssertIrGenerationExtension( class PowerAssertIrGenerationExtension(
private val messageCollector: MessageCollector, private val messageCollector: MessageCollector,
private val functions: Set<FqName> private val functions: Set<FqName>,
) : IrGenerationExtension { ) : IrGenerationExtension {
override fun generate(moduleFragment: IrModuleFragment, pluginContext: IrPluginContext) { override fun generate(moduleFragment: IrModuleFragment, pluginContext: IrPluginContext) {
for (file in moduleFragment.files) { for (file in moduleFragment.files) {
@@ -36,7 +36,7 @@ interface FunctionDelegate {
dispatchReceiver: IrExpression?, dispatchReceiver: IrExpression?,
extensionReceiver: IrExpression?, extensionReceiver: IrExpression?,
valueArguments: List<IrExpression?>, valueArguments: List<IrExpression?>,
messageArgument: IrExpression messageArgument: IrExpression,
): IrExpression ): IrExpression
fun IrBuilderWithScope.irCallCopy( fun IrBuilderWithScope.irCallCopy(
@@ -45,7 +45,7 @@ interface FunctionDelegate {
dispatchReceiver: IrExpression?, dispatchReceiver: IrExpression?,
extensionReceiver: IrExpression?, extensionReceiver: IrExpression?,
valueArguments: List<IrExpression?>, valueArguments: List<IrExpression?>,
messageArgument: IrExpression messageArgument: IrExpression,
): IrExpression { ): IrExpression {
return irCall(overload, type = original.type).apply { return irCall(overload, type = original.type).apply {
this.dispatchReceiver = original.dispatchReceiver?.deepCopyWithSymbols(parent) this.dispatchReceiver = original.dispatchReceiver?.deepCopyWithSymbols(parent)
@@ -36,7 +36,7 @@ class LambdaFunctionDelegate(
dispatchReceiver: IrExpression?, dispatchReceiver: IrExpression?,
extensionReceiver: IrExpression?, extensionReceiver: IrExpression?,
valueArguments: List<IrExpression?>, valueArguments: List<IrExpression?>,
messageArgument: IrExpression messageArgument: IrExpression,
): IrExpression = with(builder) { ): IrExpression = with(builder) {
val expression = irLambda(context.irBuiltIns.stringType, messageParameter.type) { val expression = irLambda(context.irBuiltIns.stringType, messageParameter.type) {
+irReturn(messageArgument) +irReturn(messageArgument)
@@ -47,7 +47,7 @@ class LambdaFunctionDelegate(
dispatchReceiver = dispatchReceiver, dispatchReceiver = dispatchReceiver,
extensionReceiver = extensionReceiver, extensionReceiver = extensionReceiver,
valueArguments = valueArguments, valueArguments = valueArguments,
messageArgument = expression messageArgument = expression,
) )
} }
} }
@@ -37,7 +37,7 @@ class SamConversionLambdaFunctionDelegate(
dispatchReceiver: IrExpression?, dispatchReceiver: IrExpression?,
extensionReceiver: IrExpression?, extensionReceiver: IrExpression?,
valueArguments: List<IrExpression?>, valueArguments: List<IrExpression?>,
messageArgument: IrExpression messageArgument: IrExpression,
): IrExpression = with(builder) { ): IrExpression = with(builder) {
val lambda = irLambda(context.irBuiltIns.stringType, messageParameter.type) { val lambda = irLambda(context.irBuiltIns.stringType, messageParameter.type) {
+irReturn(messageArgument) +irReturn(messageArgument)
@@ -49,7 +49,7 @@ class SamConversionLambdaFunctionDelegate(
dispatchReceiver = dispatchReceiver, dispatchReceiver = dispatchReceiver,
extensionReceiver = extensionReceiver, extensionReceiver = extensionReceiver,
valueArguments = valueArguments, valueArguments = valueArguments,
messageArgument = expression messageArgument = expression,
) )
} }
} }
@@ -34,13 +34,13 @@ class SimpleFunctionDelegate(
dispatchReceiver: IrExpression?, dispatchReceiver: IrExpression?,
extensionReceiver: IrExpression?, extensionReceiver: IrExpression?,
valueArguments: List<IrExpression?>, valueArguments: List<IrExpression?>,
messageArgument: IrExpression messageArgument: IrExpression,
): IrExpression = builder.irCallCopy( ): IrExpression = builder.irCallCopy(
overload = overload, overload = overload,
original = original, original = original,
dispatchReceiver = dispatchReceiver, dispatchReceiver = dispatchReceiver,
extensionReceiver = extensionReceiver, extensionReceiver = extensionReceiver,
valueArguments = valueArguments, valueArguments = valueArguments,
messageArgument = messageArgument messageArgument = messageArgument,
) )
} }
@@ -27,7 +27,7 @@ import org.jetbrains.kotlin.ir.util.deepCopyWithSymbols
fun IrBuilderWithScope.buildDiagramNesting( fun IrBuilderWithScope.buildDiagramNesting(
root: Node, root: Node,
variables: List<IrTemporaryVariable> = emptyList(), variables: List<IrTemporaryVariable> = emptyList(),
call: IrBuilderWithScope.(IrExpression, List<IrTemporaryVariable>) -> IrExpression call: IrBuilderWithScope.(IrExpression, List<IrTemporaryVariable>) -> IrExpression,
): IrExpression { ): IrExpression {
return buildExpression(root, variables) { argument, subStack -> return buildExpression(root, variables) { argument, subStack ->
call(argument, subStack) call(argument, subStack)
@@ -37,7 +37,7 @@ fun IrBuilderWithScope.buildDiagramNesting(
fun IrBuilderWithScope.buildDiagramNestingNullable( fun IrBuilderWithScope.buildDiagramNestingNullable(
root: Node?, root: Node?,
variables: List<IrTemporaryVariable> = emptyList(), variables: List<IrTemporaryVariable> = emptyList(),
call: IrBuilderWithScope.(IrExpression?, List<IrTemporaryVariable>) -> IrExpression call: IrBuilderWithScope.(IrExpression?, List<IrTemporaryVariable>) -> IrExpression,
): IrExpression { ): IrExpression {
return if (root != null) buildDiagramNesting(root, variables, call) else call(null, variables) return if (root != null) buildDiagramNesting(root, variables, call) else call(null, variables)
} }
@@ -45,7 +45,7 @@ fun IrBuilderWithScope.buildDiagramNestingNullable(
private fun IrBuilderWithScope.buildExpression( private fun IrBuilderWithScope.buildExpression(
node: Node, node: Node,
variables: List<IrTemporaryVariable>, variables: List<IrTemporaryVariable>,
call: IrBuilderWithScope.(IrExpression, List<IrTemporaryVariable>) -> IrExpression call: IrBuilderWithScope.(IrExpression, List<IrTemporaryVariable>) -> IrExpression,
): IrExpression = when (node) { ): IrExpression = when (node) {
is ExpressionNode -> add(node, variables, call) is ExpressionNode -> add(node, variables, call)
is AndNode -> nest(node, 0, variables, call) is AndNode -> nest(node, 0, variables, call)
@@ -69,7 +69,7 @@ private fun IrBuilderWithScope.buildExpression(
private fun IrBuilderWithScope.add( private fun IrBuilderWithScope.add(
node: ExpressionNode, node: ExpressionNode,
variables: List<IrTemporaryVariable>, variables: List<IrTemporaryVariable>,
call: IrBuilderWithScope.(IrExpression, List<IrTemporaryVariable>) -> IrExpression call: IrBuilderWithScope.(IrExpression, List<IrTemporaryVariable>) -> IrExpression,
): IrExpression { ): IrExpression {
return irBlock { return irBlock {
val head = node.expressions.first().deepCopyWithSymbols(scope.getLocalDeclarationParent()) val head = node.expressions.first().deepCopyWithSymbols(scope.getLocalDeclarationParent())
@@ -100,18 +100,21 @@ private fun IrBuilderWithScope.nest(
node: AndNode, node: AndNode,
index: Int, index: Int,
variables: List<IrTemporaryVariable>, variables: List<IrTemporaryVariable>,
call: IrBuilderWithScope.(IrExpression, List<IrTemporaryVariable>) -> IrExpression call: IrBuilderWithScope.(IrExpression, List<IrTemporaryVariable>) -> IrExpression,
): IrExpression { ): IrExpression {
val children = node.children val children = node.children
val child = children[index] val child = children[index]
return buildExpression(child, variables) { argument, newVariables -> return buildExpression(child, variables) { argument, newVariables ->
if (index + 1 == children.size) call(argument, newVariables) // last expression, result is false if (index + 1 == children.size) {
else irIfThenElse( call(argument, newVariables) // last expression, result is false
context.irBuiltIns.anyType, } else {
argument, irIfThenElse(
nest(node, index + 1, newVariables, call), // more expressions, continue nesting context.irBuiltIns.anyType,
call(irFalse(), newVariables), // short-circuit result to false 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, node: OrNode,
index: Int, index: Int,
variables: List<IrTemporaryVariable>, variables: List<IrTemporaryVariable>,
call: IrBuilderWithScope.(IrExpression, List<IrTemporaryVariable>) -> IrExpression call: IrBuilderWithScope.(IrExpression, List<IrTemporaryVariable>) -> IrExpression,
): IrExpression { ): IrExpression {
val children = node.children val children = node.children
val child = children[index] val child = children[index]
return buildExpression(child, variables) { argument, newVariables -> return buildExpression(child, variables) { argument, newVariables ->
if (index + 1 == children.size) call(argument, newVariables) // last expression, result is false if (index + 1 == children.size) {
else irIfThenElse( call(argument, newVariables) // last expression, result is false
context.irBuiltIns.anyType, } else {
argument, irIfThenElse(
call(irTrue(), newVariables), // short-circuit result to true context.irBuiltIns.anyType,
nest(node, index + 1, newVariables, call), // more expressions, continue nesting argument,
) call(irTrue(), newVariables), // short-circuit result to true
nest(node, index + 1, newVariables, call), // more expressions, continue nesting
)
}
} }
} }
@@ -75,113 +75,116 @@ fun buildTree(expression: IrExpression): Node? {
} }
val tree = RootNode() val tree = RootNode()
expression.accept(object : IrElementVisitor<Unit, Node> { expression.accept(
override fun visitElement(element: IrElement, data: Node) { object : IrElementVisitor<Unit, Node> {
element.acceptChildren(this, data) override fun visitElement(element: IrElement, data: Node) {
} element.acceptChildren(this, data)
}
override fun visitExpression(expression: IrExpression, data: Node) { override fun visitExpression(expression: IrExpression, data: Node) {
if (expression is IrFunctionExpression) return // Do not transform lambda expressions, especially their body 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) } val node = data as? ExpressionNode ?: ExpressionNode().also { data.addChild(it) }
node.add(expression) node.add(expression)
} expression.acceptChildren(this, node)
}
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 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) { override fun visitTypeOperator(expression: IrTypeOperatorCall, data: Node) {
if (expression.symbol.owner.name.asString() == "EQEQ" && expression.origin == IrStatementOrigin.EXCLEQ) { val node = data as? ExpressionNode ?: ExpressionNode().also { data.addChild(it) }
// Skip the EQEQ part of a EXCLEQ call 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) expression.acceptChildren(this, data)
} else {
super.visitCall(expression, data)
} }
}
override fun visitVararg(expression: IrVararg, data: Node) { override fun visitConst(expression: IrConst<*>, data: Node) {
// Skip processing of vararg array // Do not include constants
expression.acceptChildren(this, data) }
}
override fun visitConst(expression: IrConst<*>, data: Node) { override fun visitWhen(expression: IrWhen, data: Node) {
// Do not include constants 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) { require(expression.branches.size == 2)
when (expression.origin) { val thenBranch = expression.branches[0]
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) thenBranch.condition.accept(this, node)
val thenBranch = expression.branches[0] thenBranch.result.accept(this, node)
thenBranch.condition.accept(this, node) val elseBranchCondition = expression.branches[1].condition
thenBranch.result.accept(this, node) val elseBranchResult = expression.branches[1].result
val elseBranchCondition = expression.branches[1].condition if (elseBranchCondition !is IrConst<*> || elseBranchCondition.value != true) {
val elseBranchResult = expression.branches[1].result elseBranchCondition.accept(this, node)
}
if (elseBranchCondition !is IrConst<*> || elseBranchCondition.value != true) { if (elseBranchResult !is IrConst<*> || elseBranchResult.value != false) {
elseBranchCondition.accept(this, node) 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) { require(expression.branches.size == 2)
elseBranchResult.accept(this, node) 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)
}
} }
} else -> {
IrStatementOrigin.OROR -> { // Add as basic expression and terminate
// flatten `||` expressions to be at the same level // TODO this has to be broken and not work in all cases...
val node = data as? OrNode ?: OrNode().also { data.addChild(it) } ExpressionNode().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)
} }
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() return tree.children.singleOrNull()
} }
@@ -38,7 +38,7 @@ fun IrBuilderWithScope.irDiagramString(
sourceFile: SourceFile, sourceFile: SourceFile,
prefix: IrExpression? = null, prefix: IrExpression? = null,
call: IrCall, call: IrCall,
variables: List<IrTemporaryVariable> variables: List<IrTemporaryVariable>,
): IrExpression { ): IrExpression {
val callInfo = sourceFile.getSourceRangeInfo(call) val callInfo = sourceFile.getSourceRangeInfo(call)
val callIndent = callInfo.startColumnNumber val callIndent = callInfo.startColumnNumber
@@ -69,7 +69,7 @@ fun IrBuilderWithScope.irDiagramString(
last = i last = i
} }
} }
} },
) )
for (tmp in rowValues.asReversed()) { for (tmp in rowValues.asReversed()) {
@@ -83,7 +83,7 @@ fun IrBuilderWithScope.irDiagramString(
last = i last = i
} }
indent(tmp.indent - last - 1) indent(tmp.indent - last - 1)
} },
) )
addArgument(irGet(tmp.value)) addArgument(irGet(tmp.value))
} }
@@ -95,13 +95,13 @@ private data class ValueDisplay(
val value: IrVariable, val value: IrVariable,
val indent: Int, val indent: Int,
val row: Int, val row: Int,
val source: String val source: String,
) )
private fun IrTemporaryVariable.toValueDisplay( private fun IrTemporaryVariable.toValueDisplay(
fileSource: SourceFile, fileSource: SourceFile,
callIndent: Int, callIndent: Int,
originalInfo: SourceRangeInfo originalInfo: SourceRangeInfo,
): ValueDisplay { ): ValueDisplay {
val info = fileSource.getSourceRangeInfo(original) val info = fileSource.getSourceRangeInfo(original)
var indent = info.startColumnNumber - callIndent var indent = info.startColumnNumber - callIndent
@@ -158,7 +158,7 @@ private fun IrTemporaryVariable.toValueDisplay(
private fun findDisplayOffset( private fun findDisplayOffset(
sourceFile: SourceFile, sourceFile: SourceFile,
expression: IrExpression, expression: IrExpression,
source: String source: String,
): Int { ): Int {
return when (expression) { return when (expression) {
is IrMemberAccessExpression<*> -> memberAccessOffset(sourceFile, expression, source) is IrMemberAccessExpression<*> -> memberAccessOffset(sourceFile, expression, source)
@@ -170,7 +170,7 @@ private fun findDisplayOffset(
private fun memberAccessOffset( private fun memberAccessOffset(
sourceFile: SourceFile, sourceFile: SourceFile,
expression: IrMemberAccessExpression<*>, expression: IrMemberAccessExpression<*>,
source: String source: String,
): Int { ): Int {
if (expression.origin == IrStatementOrigin.EXCLEQ || expression.origin == IrStatementOrigin.EXCLEQEQ) { if (expression.origin == IrStatementOrigin.EXCLEQ || expression.origin == IrStatementOrigin.EXCLEQEQ) {
// special case to handle `value != null` // special case to handle `value != null`
@@ -207,7 +207,7 @@ private fun memberAccessOffset(
private fun typeOperatorOffset( private fun typeOperatorOffset(
expression: IrTypeOperatorCall, expression: IrTypeOperatorCall,
source: String source: String,
): Int { ): Int {
return when (expression.operator) { return when (expression.operator) {
IrTypeOperator.INSTANCEOF -> source.indexOf(" is ") + 1 IrTypeOperator.INSTANCEOF -> source.indexOf(" is ") + 1
@@ -26,12 +26,12 @@ import org.jetbrains.kotlin.ir.visitors.IrElementTransformerVoid
data class IrTemporaryVariable( data class IrTemporaryVariable(
val temporary: IrVariable, val temporary: IrVariable,
val original: IrExpression val original: IrExpression,
) )
class IrTemporaryExtractionTransformer( class IrTemporaryExtractionTransformer(
private val builder: IrStatementsBuilder<*>, private val builder: IrStatementsBuilder<*>,
private val transform: Set<IrExpression> private val transform: Set<IrExpression>,
) : IrElementTransformerVoid() { ) : IrElementTransformerVoid() {
private val _variables = mutableListOf<IrTemporaryVariable>() private val _variables = mutableListOf<IrTemporaryVariable>()
val variables: List<IrTemporaryVariable> = _variables val variables: List<IrTemporaryVariable> = _variables
@@ -9,7 +9,7 @@ import org.jetbrains.kotlin.ir.expressions.IrCall
import java.io.File import java.io.File
data class SourceFile( data class SourceFile(
private val irFile: IrFile private val irFile: IrFile,
) { ) {
private val source: String = File(irFile.path).readText() private val source: String = File(irFile.path).readText()
.replace("\r\n", "\n") // https://youtrack.jetbrains.com/issue/KT-41888 .replace("\r\n", "\n") // https://youtrack.jetbrains.com/issue/KT-41888
@@ -39,7 +39,7 @@ fun IrBuilderWithScope.irLambda(
lambdaType: IrType, lambdaType: IrType,
startOffset: Int = this.startOffset, startOffset: Int = this.startOffset,
endOffset: Int = this.endOffset, endOffset: Int = this.endOffset,
block: IrBlockBodyBuilder.() -> Unit block: IrBlockBodyBuilder.() -> Unit,
): IrFunctionExpression { ): IrFunctionExpression {
val scope = this val scope = this
val lambda = context.irFactory.buildFun { val lambda = context.irFactory.buildFun {
@@ -31,7 +31,7 @@ class ArithmeticExpressionTest {
| false | false
2 2
""".trimIndent(), """.trimIndent(),
actual actual,
) )
} }
@@ -46,7 +46,7 @@ class ArithmeticExpressionTest {
| false | false
2 2
""".trimIndent(), """.trimIndent(),
actual actual,
) )
} }
@@ -61,7 +61,7 @@ class ArithmeticExpressionTest {
| false | false
2 2
""".trimIndent(), """.trimIndent(),
actual actual,
) )
} }
@@ -76,7 +76,7 @@ class ArithmeticExpressionTest {
| false | false
2 2
""".trimIndent(), """.trimIndent(),
actual actual,
) )
} }
@@ -86,7 +86,7 @@ class ArithmeticExpressionTest {
""" """
var i = 1 var i = 1
assert(++i == 4) assert(++i == 4)
""".trimIndent() """.trimIndent(),
) )
assertEquals( assertEquals(
""" """
@@ -96,7 +96,7 @@ class ArithmeticExpressionTest {
| false | false
2 2
""".trimIndent(), """.trimIndent(),
actual actual,
) )
} }
@@ -106,7 +106,7 @@ class ArithmeticExpressionTest {
""" """
var i = 1 var i = 1
assert(i++ == 4) assert(i++ == 4)
""".trimIndent() """.trimIndent(),
) )
assertEquals( assertEquals(
""" """
@@ -116,7 +116,7 @@ class ArithmeticExpressionTest {
| false | false
1 1
""".trimIndent(), """.trimIndent(),
actual actual,
) )
} }
@@ -126,7 +126,7 @@ class ArithmeticExpressionTest {
""" """
var i = 3 var i = 3
assert(--i == 4) assert(--i == 4)
""".trimIndent() """.trimIndent(),
) )
assertEquals( assertEquals(
""" """
@@ -136,7 +136,7 @@ class ArithmeticExpressionTest {
| false | false
2 2
""".trimIndent(), """.trimIndent(),
actual actual,
) )
} }
@@ -146,7 +146,7 @@ class ArithmeticExpressionTest {
""" """
var i = 3 var i = 3
assert(i-- == 4) assert(i-- == 4)
""".trimIndent() """.trimIndent(),
) )
assertEquals( assertEquals(
""" """
@@ -156,7 +156,7 @@ class ArithmeticExpressionTest {
| false | false
3 3
""".trimIndent(), """.trimIndent(),
actual actual,
) )
} }
} }
@@ -37,7 +37,7 @@ assert(hello.length == "World".substring(1, 4).length)
| | false | | false
| 5 | 5
Hello Hello
""".trimIndent() """.trimIndent(),
) )
} }
@@ -57,7 +57,7 @@ assert(hello.reversed() == emptyList<String>())
| | false | | false
| [World, Hello] | [World, Hello]
[Hello, World] [Hello, World]
""".trimIndent() """.trimIndent(),
) )
} }
@@ -73,7 +73,7 @@ Not equal
assert(1 == 2) { "Not equal" } assert(1 == 2) { "Not equal" }
| |
false false
""".trimIndent() """.trimIndent(),
) )
} }
@@ -90,7 +90,7 @@ fun main() {
assert(1 == 2, lambda) assert(1 == 2, lambda)
| |
false false
""".trimIndent() """.trimIndent(),
) )
} }
@@ -108,7 +108,7 @@ assert(text != null && text.length == 1)
| | | |
| false | false
null null
""".trimIndent() """.trimIndent(),
) )
} }
@@ -133,7 +133,7 @@ assert(text != null && text.length == 5 && text.toLowerCase() == text)
| | Hello | | Hello
| true | true
Hello Hello
""".trimIndent() """.trimIndent(),
) )
} }
@@ -158,7 +158,7 @@ assert(text == null || text.length == 1 || text.toLowerCase() == text)
| | Hello | | Hello
| false | false
Hello Hello
""".trimIndent() """.trimIndent(),
) )
} }
@@ -183,7 +183,7 @@ assert(text != null && (text.length == 1 || text.toLowerCase() == text))
| | Hello | | Hello
| true | true
Hello Hello
""".trimIndent() """.trimIndent(),
) )
} }
@@ -206,7 +206,7 @@ assert((text.length == 1 || text.toLowerCase() == text) && text.length == 1)
| | false | | false
| 5 | 5
Hello Hello
""".trimIndent() """.trimIndent(),
) )
} }
@@ -231,7 +231,7 @@ assert(text == null || (text.length == 5 && text.toLowerCase() == text))
| | Hello | | Hello
| false | false
Hello Hello
""".trimIndent() """.trimIndent(),
) )
} }
@@ -257,7 +257,7 @@ assert((text.length == 5 && text.toLowerCase() == text) || text.length == 1)
| | true | | true
| 5 | 5
Hello Hello
""".trimIndent() """.trimIndent(),
) )
} }
@@ -277,7 +277,7 @@ assert(text?.length?.minus(2) == 1)
| | 3 | | 3
| 5 | 5
Hello Hello
""".trimIndent() """.trimIndent(),
) )
} }
@@ -294,7 +294,7 @@ fun main() {
| | | |
| false | false
2 2
""".trimIndent() """.trimIndent(),
) )
assertMessage( assertMessage(
@@ -308,7 +308,7 @@ assert(1 shl 1 == 4)
| | | |
| false | false
2 2
""".trimIndent() """.trimIndent(),
) )
} }
@@ -349,7 +349,7 @@ assert(
Hello Hello
) )
) )
""".trimIndent() """.trimIndent(),
) )
} }
@@ -368,8 +368,8 @@ Hello, the world is broken
assertTrue(1 == 2, message = "${"$"}text, the world is broken") assertTrue(1 == 2, message = "${"$"}text, the world is broken")
| |
false false
""".trimIndent(), """.trimIndent(),
PowerAssertComponentRegistrar(setOf(FqName("kotlin.test.assertTrue"))) PowerAssertComponentRegistrar(setOf(FqName("kotlin.test.assertTrue"))),
) )
} }
@@ -385,8 +385,8 @@ the world is broken
require(1 == 2) { "the world is broken" } require(1 == 2) { "the world is broken" }
| |
false false
""".trimIndent(), """.trimIndent(),
PowerAssertComponentRegistrar(setOf(FqName("kotlin.require"))) PowerAssertComponentRegistrar(setOf(FqName("kotlin.require"))),
) )
} }
@@ -402,8 +402,8 @@ the world is broken
check(1 == 2) { "the world is broken" } check(1 == 2) { "the world is broken" }
| |
false false
""".trimIndent(), """.trimIndent(),
PowerAssertComponentRegistrar(setOf(FqName("kotlin.check"))) PowerAssertComponentRegistrar(setOf(FqName("kotlin.check"))),
) )
} }
@@ -421,7 +421,8 @@ assert(a == 42)
| | | |
| false | false
0 0
""".trimIndent()) """.trimIndent(),
)
} }
@Test @Test
@@ -434,7 +435,7 @@ fun main() {
}""", }""",
""" """
Assertion failed Assertion failed
""".trimIndent() """.trimIndent(),
) )
} }
} }
@@ -30,7 +30,7 @@ class CastExpressionTest {
| |
false false
""".trimIndent(), """.trimIndent(),
actual actual,
) )
} }
@@ -44,7 +44,7 @@ class CastExpressionTest {
| |
false false
""".trimIndent(), """.trimIndent(),
actual actual,
) )
} }
@@ -54,7 +54,7 @@ class CastExpressionTest {
""" """
val greeting: Any = "hello" val greeting: Any = "hello"
assert(greeting is String && greeting.length == 2) assert(greeting is String && greeting.length == 2)
""".trimIndent() """.trimIndent(),
) )
assertEquals( assertEquals(
""" """
@@ -67,7 +67,7 @@ class CastExpressionTest {
| true | true
hello hello
""".trimIndent(), """.trimIndent(),
actual actual,
) )
} }
} }
@@ -31,7 +31,7 @@ class DebugFunctionTest {
val actual = executeMainDebug( val actual = executeMainDebug(
""" """
dbg(1 + 2 + 3) dbg(1 + 2 + 3)
""".trimIndent() """.trimIndent(),
) )
assertEquals( assertEquals(
""" """
@@ -40,7 +40,7 @@ class DebugFunctionTest {
| 6 | 6
3 3
""".trimIndent(), """.trimIndent(),
actual.trim() actual.trim(),
) )
} }
@@ -49,7 +49,7 @@ class DebugFunctionTest {
val actual = executeMainDebug( val actual = executeMainDebug(
""" """
dbg(1 + 2 + 3, "Message:") dbg(1 + 2 + 3, "Message:")
""".trimIndent() """.trimIndent(),
) )
assertEquals( assertEquals(
""" """
@@ -59,7 +59,7 @@ class DebugFunctionTest {
| 6 | 6
3 3
""".trimIndent(), """.trimIndent(),
actual.trim() actual.trim(),
) )
} }
} }
@@ -79,7 +79,7 @@ fun main() {
$mainBody $mainBody
} }
""", """,
trimIndent = false trimIndent = false,
) )
val result = compile(listOf(file), PowerAssertComponentRegistrar(setOf(FqName("dbg")))) 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") fail("main did not throw expected exception")
} catch (t: InvocationTargetException) { } catch (t: InvocationTargetException) {
with(t.cause) { 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:") return message!!.substringAfter("result:")
}
} }
throw t.cause!! throw t.cause!!
} }
@@ -30,7 +30,7 @@ class InfixFunctionTest {
val actual = runExtensionInfix( val actual = runExtensionInfix(
""" """
(1 + 1) mustEqual (2 + 4) (1 + 1) mustEqual (2 + 4)
""".trimIndent() """.trimIndent(),
) )
assertEquals( assertEquals(
""" """
@@ -39,7 +39,7 @@ class InfixFunctionTest {
| 6 | 6
2 2
""".trimIndent(), """.trimIndent(),
actual.trim() actual.trim(),
) )
} }
@@ -48,7 +48,7 @@ class InfixFunctionTest {
val actual = runExtensionInfix( val actual = runExtensionInfix(
""" """
1 mustEqual (2 + 4) 1 mustEqual (2 + 4)
""".trimIndent() """.trimIndent(),
) )
assertEquals( assertEquals(
""" """
@@ -56,7 +56,7 @@ class InfixFunctionTest {
| |
6 6
""".trimIndent(), """.trimIndent(),
actual.trim() actual.trim(),
) )
} }
@@ -65,7 +65,7 @@ class InfixFunctionTest {
val actual = runExtensionInfix( val actual = runExtensionInfix(
""" """
(1 + 1) mustEqual 6 (1 + 1) mustEqual 6
""".trimIndent() """.trimIndent(),
) )
assertEquals( assertEquals(
""" """
@@ -73,7 +73,7 @@ class InfixFunctionTest {
| |
2 2
""".trimIndent(), """.trimIndent(),
actual.trim() actual.trim(),
) )
} }
@@ -82,13 +82,13 @@ class InfixFunctionTest {
val actual = runExtensionInfix( val actual = runExtensionInfix(
""" """
2 mustEqual 6 2 mustEqual 6
""".trimIndent() """.trimIndent(),
) )
assertEquals( assertEquals(
""" """
Assertion failed Assertion failed
""".trimIndent(), """.trimIndent(),
actual.trim() actual.trim(),
) )
} }
@@ -97,7 +97,7 @@ class InfixFunctionTest {
val actual = runExtensionInfix( val actual = runExtensionInfix(
""" """
(1 + 1).mustEqual(2 + 4) (1 + 1).mustEqual(2 + 4)
""".trimIndent() """.trimIndent(),
) )
assertEquals( assertEquals(
""" """
@@ -106,7 +106,7 @@ class InfixFunctionTest {
| 6 | 6
2 2
""".trimIndent(), """.trimIndent(),
actual.trim() actual.trim(),
) )
} }
@@ -115,7 +115,7 @@ class InfixFunctionTest {
val actual = runExtensionInfix( val actual = runExtensionInfix(
""" """
1.mustEqual(2 + 4) 1.mustEqual(2 + 4)
""".trimIndent() """.trimIndent(),
) )
assertEquals( assertEquals(
""" """
@@ -123,7 +123,7 @@ class InfixFunctionTest {
| |
6 6
""".trimIndent(), """.trimIndent(),
actual.trim() actual.trim(),
) )
} }
@@ -132,7 +132,7 @@ class InfixFunctionTest {
val actual = runExtensionInfix( val actual = runExtensionInfix(
""" """
(1 + 1).mustEqual(6) (1 + 1).mustEqual(6)
""".trimIndent() """.trimIndent(),
) )
assertEquals( assertEquals(
""" """
@@ -140,7 +140,7 @@ class InfixFunctionTest {
| |
2 2
""".trimIndent(), """.trimIndent(),
actual.trim() actual.trim(),
) )
} }
@@ -149,13 +149,13 @@ class InfixFunctionTest {
val actual = runExtensionInfix( val actual = runExtensionInfix(
""" """
2.mustEqual(6) 2.mustEqual(6)
""".trimIndent() """.trimIndent(),
) )
assertEquals( assertEquals(
""" """
Assertion failed Assertion failed
""".trimIndent(), """.trimIndent(),
actual.trim() actual.trim(),
) )
} }
@@ -164,7 +164,7 @@ class InfixFunctionTest {
val actual = runDispatchInfix( val actual = runDispatchInfix(
""" """
Wrapper(1 + 1) mustEqual (2 + 4) Wrapper(1 + 1) mustEqual (2 + 4)
""".trimIndent() """.trimIndent(),
) )
assertEquals( assertEquals(
""" """
@@ -174,7 +174,7 @@ class InfixFunctionTest {
| 2 | 2
Wrapper Wrapper
""".trimIndent(), """.trimIndent(),
actual.trim() actual.trim(),
) )
} }
@@ -183,7 +183,7 @@ class InfixFunctionTest {
val actual = runDispatchInfix( val actual = runDispatchInfix(
""" """
Wrapper(1) mustEqual (2 + 4) Wrapper(1) mustEqual (2 + 4)
""".trimIndent() """.trimIndent(),
) )
assertEquals( assertEquals(
""" """
@@ -192,7 +192,7 @@ class InfixFunctionTest {
| 6 | 6
Wrapper Wrapper
""".trimIndent(), """.trimIndent(),
actual.trim() actual.trim(),
) )
} }
@@ -201,7 +201,7 @@ class InfixFunctionTest {
val actual = runDispatchInfix( val actual = runDispatchInfix(
""" """
Wrapper(1 + 1) mustEqual 6 Wrapper(1 + 1) mustEqual 6
""".trimIndent() """.trimIndent(),
) )
assertEquals( assertEquals(
""" """
@@ -210,7 +210,7 @@ class InfixFunctionTest {
| 2 | 2
Wrapper Wrapper
""".trimIndent(), """.trimIndent(),
actual.trim() actual.trim(),
) )
} }
@@ -219,7 +219,7 @@ class InfixFunctionTest {
val actual = runDispatchInfix( val actual = runDispatchInfix(
""" """
Wrapper(2) mustEqual 6 Wrapper(2) mustEqual 6
""".trimIndent() """.trimIndent(),
) )
assertEquals( assertEquals(
""" """
@@ -227,7 +227,7 @@ class InfixFunctionTest {
| |
Wrapper Wrapper
""".trimIndent(), """.trimIndent(),
actual.trim() actual.trim(),
) )
} }
@@ -236,7 +236,7 @@ class InfixFunctionTest {
val actual = runDispatchInfix( val actual = runDispatchInfix(
""" """
Wrapper(1 + 1).mustEqual(2 + 4) Wrapper(1 + 1).mustEqual(2 + 4)
""".trimIndent() """.trimIndent(),
) )
assertEquals( assertEquals(
""" """
@@ -246,7 +246,7 @@ class InfixFunctionTest {
| 2 | 2
Wrapper Wrapper
""".trimIndent(), """.trimIndent(),
actual.trim() actual.trim(),
) )
} }
@@ -255,7 +255,7 @@ class InfixFunctionTest {
val actual = runDispatchInfix( val actual = runDispatchInfix(
""" """
Wrapper(1).mustEqual(2 + 4) Wrapper(1).mustEqual(2 + 4)
""".trimIndent() """.trimIndent(),
) )
assertEquals( assertEquals(
""" """
@@ -264,7 +264,7 @@ class InfixFunctionTest {
| 6 | 6
Wrapper Wrapper
""".trimIndent(), """.trimIndent(),
actual.trim() actual.trim(),
) )
} }
@@ -273,7 +273,7 @@ class InfixFunctionTest {
val actual = runDispatchInfix( val actual = runDispatchInfix(
""" """
Wrapper(1 + 1).mustEqual(6) Wrapper(1 + 1).mustEqual(6)
""".trimIndent() """.trimIndent(),
) )
assertEquals( assertEquals(
""" """
@@ -282,7 +282,7 @@ class InfixFunctionTest {
| 2 | 2
Wrapper Wrapper
""".trimIndent(), """.trimIndent(),
actual.trim() actual.trim(),
) )
} }
@@ -291,7 +291,7 @@ class InfixFunctionTest {
val actual = runDispatchInfix( val actual = runDispatchInfix(
""" """
Wrapper(2).mustEqual(6) Wrapper(2).mustEqual(6)
""".trimIndent() """.trimIndent(),
) )
assertEquals( assertEquals(
""" """
@@ -299,7 +299,7 @@ class InfixFunctionTest {
| |
Wrapper Wrapper
""".trimIndent(), """.trimIndent(),
actual.trim() actual.trim(),
) )
} }
@@ -317,9 +317,9 @@ class InfixFunctionTest {
$mainBody $mainBody
} }
""".trimIndent(), """.trimIndent(),
trimIndent = false trimIndent = false,
), ),
setOf(FqName("mustEqual")) setOf(FqName("mustEqual")),
) )
} }
@@ -343,9 +343,9 @@ class InfixFunctionTest {
$mainBody $mainBody
} }
""".trimIndent(), """.trimIndent(),
trimIndent = false trimIndent = false,
), ),
setOf(FqName("Wrapper.mustEqual")) setOf(FqName("Wrapper.mustEqual")),
) )
} }
@@ -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"))) PowerAssertComponentRegistrar(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"))) PowerAssertComponentRegistrar(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"))) PowerAssertComponentRegistrar(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"))) PowerAssertComponentRegistrar(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"))) PowerAssertComponentRegistrar(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"))) PowerAssertComponentRegistrar(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"))) PowerAssertComponentRegistrar(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"))) PowerAssertComponentRegistrar(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"))) PowerAssertComponentRegistrar(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"))) PowerAssertComponentRegistrar(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"))) PowerAssertComponentRegistrar(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"))) PowerAssertComponentRegistrar(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"))) PowerAssertComponentRegistrar(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"))) PowerAssertComponentRegistrar(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"))) PowerAssertComponentRegistrar(setOf(FqName("org.junit.jupiter.api.Assertions.assertEquals"))),
) )
} }
} }
@@ -35,7 +35,7 @@ class KotlinTestAssertTest {
| |
false false
""".trimIndent(), """.trimIndent(),
PowerAssertComponentRegistrar(setOf(FqName("kotlin.test.assertTrue"))) PowerAssertComponentRegistrar(setOf(FqName("kotlin.test.assertTrue"))),
) )
} }
@@ -54,7 +54,7 @@ class KotlinTestAssertTest {
| |
false false
""".trimIndent(), """.trimIndent(),
PowerAssertComponentRegistrar(setOf(FqName("kotlin.test.assertTrue"))) PowerAssertComponentRegistrar(setOf(FqName("kotlin.test.assertTrue"))),
) )
} }
@@ -74,7 +74,7 @@ class KotlinTestAssertTest {
| |
false false
""".trimIndent(), """.trimIndent(),
PowerAssertComponentRegistrar(setOf(FqName("kotlin.test.assertTrue"))) PowerAssertComponentRegistrar(setOf(FqName("kotlin.test.assertTrue"))),
) )
} }
@@ -93,7 +93,7 @@ class KotlinTestAssertTest {
| |
true true
""".trimIndent(), """.trimIndent(),
PowerAssertComponentRegistrar(setOf(FqName("kotlin.test.assertFalse"))) PowerAssertComponentRegistrar(setOf(FqName("kotlin.test.assertFalse"))),
) )
} }
@@ -112,7 +112,7 @@ class KotlinTestAssertTest {
| |
true true
""".trimIndent(), """.trimIndent(),
PowerAssertComponentRegistrar(setOf(FqName("kotlin.test.assertFalse"))) PowerAssertComponentRegistrar(setOf(FqName("kotlin.test.assertFalse"))),
) )
} }
@@ -132,7 +132,7 @@ class KotlinTestAssertTest {
| |
true true
""".trimIndent(), """.trimIndent(),
PowerAssertComponentRegistrar(setOf(FqName("kotlin.test.assertFalse"))) PowerAssertComponentRegistrar(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"))) PowerAssertComponentRegistrar(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"))) PowerAssertComponentRegistrar(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"))) PowerAssertComponentRegistrar(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"))) PowerAssertComponentRegistrar(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"))) PowerAssertComponentRegistrar(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"))) PowerAssertComponentRegistrar(setOf(FqName("kotlin.test.assertNotNull"))),
) )
} }
} }
@@ -35,7 +35,7 @@ class LamdaTest {
| | false | | false
| [Doe, Jane, Doe, John] | [Doe, Jane, Doe, John]
[Jane, John] [Jane, John]
""".trimIndent() """.trimIndent(),
) )
} }
@@ -65,7 +65,7 @@ class LamdaTest {
false false
) )
""".trimIndent(), """.trimIndent(),
PowerAssertComponentRegistrar(setOf(FqName("kotlin.require"))) PowerAssertComponentRegistrar(setOf(FqName("kotlin.require"))),
) )
} }
} }
@@ -29,7 +29,7 @@ class MultiParameterFunctionTest {
""" """
val operation = "sum" val operation = "sum"
dbg(operation, 1 + 2 + 3) dbg(operation, 1 + 2 + 3)
""".trimIndent() """.trimIndent(),
) )
assertEquals( assertEquals(
""" """
@@ -40,7 +40,7 @@ class MultiParameterFunctionTest {
| 3 | 3
sum sum
""".trimIndent(), """.trimIndent(),
actual.trim() actual.trim(),
) )
} }
@@ -54,7 +54,7 @@ class MultiParameterFunctionTest {
key = greeting != null && greeting.length == 5, key = greeting != null && greeting.length == 5,
value = name == null || name.length == 5 value = name == null || name.length == 5
) )
""".trimIndent() """.trimIndent(),
) )
assertEquals( assertEquals(
""" """
@@ -70,7 +70,7 @@ class MultiParameterFunctionTest {
null null
) )
""".trimIndent(), """.trimIndent(),
actual.trim() actual.trim(),
) )
} }
@@ -80,7 +80,7 @@ class MultiParameterFunctionTest {
""" """
val operation = "sum" val operation = "sum"
dbg(operation, 1 + 2 + 3, "Message:") dbg(operation, 1 + 2 + 3, "Message:")
""".trimIndent() """.trimIndent(),
) )
assertEquals( assertEquals(
""" """
@@ -92,7 +92,7 @@ class MultiParameterFunctionTest {
| 3 | 3
sum sum
""".trimIndent(), """.trimIndent(),
actual.trim() actual.trim(),
) )
} }
@@ -107,7 +107,7 @@ class MultiParameterFunctionTest {
value = name == null || name.length == 5, value = name == null || name.length == 5,
msg = "Message:" msg = "Message:"
) )
""".trimIndent() """.trimIndent(),
) )
assertEquals( assertEquals(
""" """
@@ -125,7 +125,7 @@ class MultiParameterFunctionTest {
msg = "Message:" msg = "Message:"
) )
""".trimIndent(), """.trimIndent(),
actual.trim() actual.trim(),
) )
} }
} }
@@ -145,7 +145,7 @@ fun main() {
$mainBody $mainBody
} }
""", """,
trimIndent = false trimIndent = false,
) )
val result = compile(listOf(file), PowerAssertComponentRegistrar(setOf(FqName("dbg")))) val result = compile(listOf(file), PowerAssertComponentRegistrar(setOf(FqName("dbg"))))
@@ -31,7 +31,7 @@ class RegexMatchTest {
| [A-Za-z]+ | [A-Za-z]+
false false
""".trimIndent(), """.trimIndent(),
actual actual,
) )
} }
@@ -46,7 +46,7 @@ class RegexMatchTest {
| [A-Za-z]+ | [A-Za-z]+
false false
""".trimIndent(), """.trimIndent(),
actual actual,
) )
} }
} }
@@ -27,12 +27,12 @@ import kotlin.test.assertEquals
import kotlin.test.fail import kotlin.test.fail
private val DEFAULT_COMPONENT_REGISTRARS = arrayOf( private val DEFAULT_COMPONENT_REGISTRARS = arrayOf(
PowerAssertComponentRegistrar(setOf(FqName("kotlin.assert"))) PowerAssertComponentRegistrar(setOf(FqName("kotlin.assert"))),
) )
fun compile( fun compile(
list: List<SourceFile>, list: List<SourceFile>,
vararg plugins: ComponentRegistrar = DEFAULT_COMPONENT_REGISTRARS vararg plugins: ComponentRegistrar = DEFAULT_COMPONENT_REGISTRARS,
): KotlinCompilation.Result { ): KotlinCompilation.Result {
return KotlinCompilation().apply { return KotlinCompilation().apply {
sources = list sources = list
@@ -53,7 +53,7 @@ fun compile(
fun executeAssertion( fun executeAssertion(
@Language("kotlin") source: String, @Language("kotlin") source: String,
vararg plugins: ComponentRegistrar = DEFAULT_COMPONENT_REGISTRARS vararg plugins: ComponentRegistrar = DEFAULT_COMPONENT_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)),
@@ -80,13 +80,13 @@ fun executeMainAssertion(mainBody: String) = executeAssertion(
fun main() { fun main() {
$mainBody $mainBody
} }
""" """,
) )
fun assertMessage( fun assertMessage(
@Language("kotlin") source: String, @Language("kotlin") source: String,
message: String, message: String,
vararg plugins: ComponentRegistrar = DEFAULT_COMPONENT_REGISTRARS vararg plugins: ComponentRegistrar = DEFAULT_COMPONENT_REGISTRARS,
) { ) {
val actual = executeAssertion(source, *plugins) val actual = executeAssertion(source, *plugins)
assertEquals(message, actual) assertEquals(message, actual)