Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Disabled concrete execution for symbolic execution with UtLambdaModel…
… as method result
  • Loading branch information
Damtev committed Sep 22, 2022
commit 9580b14a498eca0f7a9942837202ee3659c6bb03
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -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(
Expand All @@ -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
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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 {
Expand Down