diff --git a/utbot-framework-api/src/main/kotlin/org/utbot/framework/plugin/api/Api.kt b/utbot-framework-api/src/main/kotlin/org/utbot/framework/plugin/api/Api.kt index 3401ba0f0c..b7f39e6d54 100644 --- a/utbot-framework-api/src/main/kotlin/org/utbot/framework/plugin/api/Api.kt +++ b/utbot-framework-api/src/main/kotlin/org/utbot/framework/plugin/api/Api.kt @@ -575,6 +575,8 @@ class UtLambdaModel( .singleOrNull { it.name == lambdaName } ?.executableId // synthetic lambda methods should not have overloads, so we always expect there to be only one method with the given name ?: error("More than one method with name $lambdaName found in class: ${declaringClass.canonicalName}") + + override fun toString(): String = "Anonymous function $lambdaName implementing functional interface $declaringClass" } /** diff --git a/utbot-framework-test/src/test/kotlin/org/utbot/examples/lambda/SimpleLambdaExamplesTest.kt b/utbot-framework-test/src/test/kotlin/org/utbot/examples/lambda/SimpleLambdaExamplesTest.kt index 9723722c59..d3a04948b2 100644 --- a/utbot-framework-test/src/test/kotlin/org/utbot/examples/lambda/SimpleLambdaExamplesTest.kt +++ b/utbot-framework-test/src/test/kotlin/org/utbot/examples/lambda/SimpleLambdaExamplesTest.kt @@ -1,12 +1,21 @@ package org.utbot.examples.lambda -import org.junit.jupiter.api.Disabled import org.junit.jupiter.api.Test +import org.utbot.framework.plugin.api.CodegenLanguage +import org.utbot.testcheckers.eq +import org.utbot.tests.infrastructure.CodeGeneration +import org.utbot.tests.infrastructure.DoNotCalculate import org.utbot.tests.infrastructure.UtValueTestCaseChecker import org.utbot.tests.infrastructure.isException -import org.utbot.testcheckers.eq -class SimpleLambdaExamplesTest : UtValueTestCaseChecker(testClass = SimpleLambdaExamples::class) { +// TODO failed Kotlin compilation (generics) SAT-1332 +class SimpleLambdaExamplesTest : UtValueTestCaseChecker( + testClass = SimpleLambdaExamples::class, + languagePipelines = listOf( + CodeGenerationLanguageLastStage(CodegenLanguage.JAVA), + CodeGenerationLanguageLastStage(CodegenLanguage.KOTLIN, CodeGeneration), + ) +) { @Test fun testBiFunctionLambdaExample() { checkWithException( @@ -18,14 +27,13 @@ class SimpleLambdaExamplesTest : UtValueTestCaseChecker(testClass = SimpleLambda } @Test - @Disabled("TODO 0 executions https://github.com/UnitTestBot/UTBotJava/issues/192") fun testChoosePredicate() { check( SimpleLambdaExamples::choosePredicate, eq(2), { b, r -> b && !r!!.test(null) && r.test(0) }, { b, r -> !b && r!!.test(null) && !r.test(0) }, - // TODO coverage calculation fails https://github.com/UnitTestBot/UTBotJava/issues/192 + coverage = DoNotCalculate // coverage could not be calculated since method result is lambda ) } } diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/UtBotSymbolicEngine.kt b/utbot-framework/src/main/kotlin/org/utbot/engine/UtBotSymbolicEngine.kt index 0a154100f8..8641d5a9b4 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/engine/UtBotSymbolicEngine.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/engine/UtBotSymbolicEngine.kt @@ -101,6 +101,8 @@ import kotlinx.coroutines.flow.onStart import kotlinx.coroutines.isActive import kotlinx.coroutines.job import kotlinx.coroutines.yield +import org.utbot.framework.plugin.api.UtExecutionSuccess +import org.utbot.framework.plugin.api.UtLambdaModel val logger = KotlinLogging.logger {} val pathLogger = KotlinLogging.logger(logger.name + ".path") @@ -562,6 +564,17 @@ class UtBotSymbolicEngine( return } + // Check for lambda result as it cannot be emitted by concrete execution + (symbolicExecutionResult as? UtExecutionSuccess)?.takeIf { it.model is UtLambdaModel }?.run { + logger.debug { + "processResult<${methodUnderTest}>: impossible to create concrete value for lambda result ($model), " + + "emit purely symbolic result $symbolicUtExecution" + } + + emit(symbolicUtExecution) + return + } + //It's possible that symbolic and concrete stateAfter/results are diverged. //So we trust concrete results more. try {