Skip to content

Commit 599e010

Browse files
authored
Disabled concrete execution for lambda results (#989)
1 parent 6dc08be commit 599e010

File tree

3 files changed

+28
-5
lines changed

3 files changed

+28
-5
lines changed

utbot-framework-api/src/main/kotlin/org/utbot/framework/plugin/api/Api.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -575,6 +575,8 @@ class UtLambdaModel(
575575
.singleOrNull { it.name == lambdaName }
576576
?.executableId // synthetic lambda methods should not have overloads, so we always expect there to be only one method with the given name
577577
?: error("More than one method with name $lambdaName found in class: ${declaringClass.canonicalName}")
578+
579+
override fun toString(): String = "Anonymous function $lambdaName implementing functional interface $declaringClass"
578580
}
579581

580582
/**
Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,21 @@
11
package org.utbot.examples.lambda
22

3-
import org.junit.jupiter.api.Disabled
43
import org.junit.jupiter.api.Test
4+
import org.utbot.framework.plugin.api.CodegenLanguage
5+
import org.utbot.testcheckers.eq
6+
import org.utbot.tests.infrastructure.CodeGeneration
7+
import org.utbot.tests.infrastructure.DoNotCalculate
58
import org.utbot.tests.infrastructure.UtValueTestCaseChecker
69
import org.utbot.tests.infrastructure.isException
7-
import org.utbot.testcheckers.eq
810

9-
class SimpleLambdaExamplesTest : UtValueTestCaseChecker(testClass = SimpleLambdaExamples::class) {
11+
// TODO failed Kotlin compilation (generics) SAT-1332
12+
class SimpleLambdaExamplesTest : UtValueTestCaseChecker(
13+
testClass = SimpleLambdaExamples::class,
14+
languagePipelines = listOf(
15+
CodeGenerationLanguageLastStage(CodegenLanguage.JAVA),
16+
CodeGenerationLanguageLastStage(CodegenLanguage.KOTLIN, CodeGeneration),
17+
)
18+
) {
1019
@Test
1120
fun testBiFunctionLambdaExample() {
1221
checkWithException(
@@ -18,14 +27,13 @@ class SimpleLambdaExamplesTest : UtValueTestCaseChecker(testClass = SimpleLambda
1827
}
1928

2029
@Test
21-
@Disabled("TODO 0 executions https://github.com/UnitTestBot/UTBotJava/issues/192")
2230
fun testChoosePredicate() {
2331
check(
2432
SimpleLambdaExamples::choosePredicate,
2533
eq(2),
2634
{ b, r -> b && !r!!.test(null) && r.test(0) },
2735
{ b, r -> !b && r!!.test(null) && !r.test(0) },
28-
// TODO coverage calculation fails https://github.com/UnitTestBot/UTBotJava/issues/192
36+
coverage = DoNotCalculate // coverage could not be calculated since method result is lambda
2937
)
3038
}
3139
}

utbot-framework/src/main/kotlin/org/utbot/engine/UtBotSymbolicEngine.kt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,8 @@ import kotlinx.coroutines.flow.onStart
101101
import kotlinx.coroutines.isActive
102102
import kotlinx.coroutines.job
103103
import kotlinx.coroutines.yield
104+
import org.utbot.framework.plugin.api.UtExecutionSuccess
105+
import org.utbot.framework.plugin.api.UtLambdaModel
104106

105107
val logger = KotlinLogging.logger {}
106108
val pathLogger = KotlinLogging.logger(logger.name + ".path")
@@ -562,6 +564,17 @@ class UtBotSymbolicEngine(
562564
return
563565
}
564566

567+
// Check for lambda result as it cannot be emitted by concrete execution
568+
(symbolicExecutionResult as? UtExecutionSuccess)?.takeIf { it.model is UtLambdaModel }?.run {
569+
logger.debug {
570+
"processResult<${methodUnderTest}>: impossible to create concrete value for lambda result ($model), " +
571+
"emit purely symbolic result $symbolicUtExecution"
572+
}
573+
574+
emit(symbolicUtExecution)
575+
return
576+
}
577+
565578
//It's possible that symbolic and concrete stateAfter/results are diverged.
566579
//So we trust concrete results more.
567580
try {

0 commit comments

Comments
 (0)