From 9838c1df309ee17eb13fd536b538f46df77be193 Mon Sep 17 00:00:00 2001 From: Kamenev Yury Date: Fri, 9 Sep 2022 12:37:37 +0300 Subject: [PATCH 1/6] Used real variable type after field access with reflection if possible --- ...ithPrivateMutableFieldOfPrivateTypeTest.kt | 33 +++++++++++++++++++ .../constructor/tree/CgFieldStateManager.kt | 6 ++-- .../infrastructure/UtValueTestCaseChecker.kt | 20 +++++------ ...sWithPrivateMutableFieldOfPrivateType.java | 16 +++++++++ 4 files changed, 63 insertions(+), 12 deletions(-) create mode 100644 utbot-framework-test/src/test/kotlin/org/utbot/examples/codegen/modifiers/ClassWithPrivateMutableFieldOfPrivateTypeTest.kt create mode 100644 utbot-sample/src/main/java/org/utbot/examples/codegen/modifiers/ClassWithPrivateMutableFieldOfPrivateType.java diff --git a/utbot-framework-test/src/test/kotlin/org/utbot/examples/codegen/modifiers/ClassWithPrivateMutableFieldOfPrivateTypeTest.kt b/utbot-framework-test/src/test/kotlin/org/utbot/examples/codegen/modifiers/ClassWithPrivateMutableFieldOfPrivateTypeTest.kt new file mode 100644 index 0000000000..ab1f4107bb --- /dev/null +++ b/utbot-framework-test/src/test/kotlin/org/utbot/examples/codegen/modifiers/ClassWithPrivateMutableFieldOfPrivateTypeTest.kt @@ -0,0 +1,33 @@ +package org.utbot.examples.codegen.modifiers + +import org.junit.jupiter.api.Test +import org.utbot.common.withAccessibility +import org.utbot.framework.plugin.api.FieldId +import org.utbot.framework.plugin.api.util.id +import org.utbot.framework.plugin.api.util.jField +import org.utbot.testcheckers.eq +import org.utbot.tests.infrastructure.UtValueTestCaseChecker + +class ClassWithPrivateMutableFieldOfPrivateTypeTest : UtValueTestCaseChecker( + testClass = ClassWithPrivateMutableFieldOfPrivateType::class +) { + @Test + fun testChangePrivateMutableFieldWithPrivateType() { + checkAllMutationsWithThis( + ClassWithPrivateMutableFieldOfPrivateType::changePrivateMutableFieldWithPrivateType, + eq(1), + { thisBefore, _, thisAfter, _, r -> + val privateMutableField = FieldId( + ClassWithPrivateMutableFieldOfPrivateType::class.id, + "privateMutableField" + ).jField + + val (privateFieldBeforeValue, privateFieldAfterValue) = privateMutableField.withAccessibility { + privateMutableField.get(thisBefore) to privateMutableField.get(thisAfter) + } + + privateFieldBeforeValue == null && privateFieldAfterValue != null && r == 0 + } + ) + } +} diff --git a/utbot-framework/src/main/kotlin/org/utbot/framework/codegen/model/constructor/tree/CgFieldStateManager.kt b/utbot-framework/src/main/kotlin/org/utbot/framework/codegen/model/constructor/tree/CgFieldStateManager.kt index 2bb300557b..29923ffbb9 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/framework/codegen/model/constructor/tree/CgFieldStateManager.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/framework/codegen/model/constructor/tree/CgFieldStateManager.kt @@ -229,7 +229,9 @@ internal class CgFieldStateManagerImpl(val context: CgContext) if (index > path.lastIndex) return@generateSequence null val passedPath = FieldPath(path.subList(0, index + 1)) val name = if (index == path.lastIndex) customName else getFieldVariableName(prev, passedPath) - val expression = when (val newElement = path[index++]) { + + val newElement = path[index++] + val expression = when (newElement) { is FieldAccess -> { val fieldId = newElement.field utilsClassId[getFieldValue](prev, fieldId.declaringClass.name, fieldId.name) @@ -238,7 +240,7 @@ internal class CgFieldStateManagerImpl(val context: CgContext) Array::class.id[getArrayElement](prev, newElement.index) } } - newVar(objectClassId, name) { expression } + newVar(newElement.type, name) { expression } }.last() } diff --git a/utbot-framework/src/main/kotlin/org/utbot/tests/infrastructure/UtValueTestCaseChecker.kt b/utbot-framework/src/main/kotlin/org/utbot/tests/infrastructure/UtValueTestCaseChecker.kt index 6e321c4cf2..22c57a4ab3 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/tests/infrastructure/UtValueTestCaseChecker.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/tests/infrastructure/UtValueTestCaseChecker.kt @@ -2151,10 +2151,10 @@ abstract class UtValueTestCaseChecker( ) // checks mutations in this, parameters and statics - protected inline fun checkAllMutationsWithThis( - method: KFunction1, + protected inline fun checkAllMutationsWithThis( + method: KFunction1, branches: ExecutionsNumberMatcher, - vararg matchers: (T, StaticsType, T, StaticsType) -> Boolean, + vararg matchers: (T, StaticsType, T, StaticsType, R) -> Boolean, coverage: CoverageMatcher = Full, mockStrategy: MockStrategyApi = NO_MOCKS, additionalDependencies: Array> = emptyArray(), @@ -2170,10 +2170,10 @@ abstract class UtValueTestCaseChecker( summaryDisplayNameChecks = summaryDisplayNameChecks ) - protected inline fun checkAllMutationsWithThis( + protected inline fun checkAllMutationsWithThis( method: KFunction2, branches: ExecutionsNumberMatcher, - vararg matchers: (T, T1, StaticsType, T, T1, StaticsType) -> Boolean, + vararg matchers: (T, T1, StaticsType, T, T1, StaticsType, R) -> Boolean, coverage: CoverageMatcher = Full, mockStrategy: MockStrategyApi = NO_MOCKS, additionalDependencies: Array> = emptyArray(), @@ -2189,10 +2189,10 @@ abstract class UtValueTestCaseChecker( summaryDisplayNameChecks = summaryDisplayNameChecks ) - protected inline fun checkAllMutationsWithThis( + protected inline fun checkAllMutationsWithThis( method: KFunction3, branches: ExecutionsNumberMatcher, - vararg matchers: (T, T1, T2, StaticsType, T, T1, T2, StaticsType) -> Boolean, + vararg matchers: (T, T1, T2, StaticsType, T, T1, T2, StaticsType, R) -> Boolean, coverage: CoverageMatcher = Full, mockStrategy: MockStrategyApi = NO_MOCKS, additionalDependencies: Array> = emptyArray(), @@ -2208,7 +2208,7 @@ abstract class UtValueTestCaseChecker( summaryDisplayNameChecks = summaryDisplayNameChecks ) - protected inline fun checkAllMutationsWithThis( + protected inline fun checkAllMutationsWithThis( method: KFunction4, branches: ExecutionsNumberMatcher, vararg matchers: (T, T1, T2, T3, StaticsType, T, T1, T2, T3, StaticsType) -> Boolean, @@ -2227,7 +2227,7 @@ abstract class UtValueTestCaseChecker( summaryDisplayNameChecks = summaryDisplayNameChecks ) - protected inline fun checkAllMutationsWithThis( + protected inline fun checkAllMutationsWithThis( method: KFunction5, branches: ExecutionsNumberMatcher, vararg matchers: (T, T1, T2, T3, T4, StaticsType, T, T1, T2, T3, T4, StaticsType) -> Boolean, @@ -2798,7 +2798,7 @@ fun withMutationsAndThis(ex: UtValueExecution<*>) = addAll(ex.paramsAfter) add(ex.staticsAfter) - add(ex.returnValue) + add(ex.evaluatedResult) } private val UtValueExecution<*>.callerBefore get() = stateBefore.caller!!.value diff --git a/utbot-sample/src/main/java/org/utbot/examples/codegen/modifiers/ClassWithPrivateMutableFieldOfPrivateType.java b/utbot-sample/src/main/java/org/utbot/examples/codegen/modifiers/ClassWithPrivateMutableFieldOfPrivateType.java new file mode 100644 index 0000000000..938f6f863d --- /dev/null +++ b/utbot-sample/src/main/java/org/utbot/examples/codegen/modifiers/ClassWithPrivateMutableFieldOfPrivateType.java @@ -0,0 +1,16 @@ +package org.utbot.examples.codegen.modifiers; + +public class ClassWithPrivateMutableFieldOfPrivateType { + @SuppressWarnings({"FieldCanBeLocal", "unused"}) + private PrivateClass privateMutableField = null; + + public int changePrivateMutableFieldWithPrivateType() { + privateMutableField = new PrivateClass(); + + return privateMutableField.x; + } + + private static class PrivateClass { + int x = 0; + } +} From 7802a251584d1d5c4119be3e9572a8127d9807d8 Mon Sep 17 00:00:00 2001 From: Kamenev Yury Date: Mon, 12 Sep 2022 12:53:32 +0300 Subject: [PATCH 2/6] Added missing line separator after single-line block comment --- .../utbot/framework/codegen/model/visitor/CgAbstractRenderer.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/utbot-framework/src/main/kotlin/org/utbot/framework/codegen/model/visitor/CgAbstractRenderer.kt b/utbot-framework/src/main/kotlin/org/utbot/framework/codegen/model/visitor/CgAbstractRenderer.kt index f97dbc5c1a..b4d7a3c8d2 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/framework/codegen/model/visitor/CgAbstractRenderer.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/framework/codegen/model/visitor/CgAbstractRenderer.kt @@ -326,7 +326,7 @@ internal abstract class CgAbstractRenderer( if (lines.isEmpty()) return if (lines.size == 1) { - print("/* ${lines.first()} */") + println("/* ${lines.first()} */") return } From 3794310574765954b8aae2e022a1676627fbc91a Mon Sep 17 00:00:00 2001 From: Kamenev Yury Date: Mon, 12 Sep 2022 14:56:32 +0300 Subject: [PATCH 3/6] Added missed initial field states for arrays --- .../codegen/model/constructor/tree/CgFieldStateManager.kt | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/utbot-framework/src/main/kotlin/org/utbot/framework/codegen/model/constructor/tree/CgFieldStateManager.kt b/utbot-framework/src/main/kotlin/org/utbot/framework/codegen/model/constructor/tree/CgFieldStateManager.kt index 29923ffbb9..1f0f70ff40 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/framework/codegen/model/constructor/tree/CgFieldStateManager.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/framework/codegen/model/constructor/tree/CgFieldStateManager.kt @@ -28,11 +28,7 @@ import org.utbot.framework.fields.ModifiedFields import org.utbot.framework.fields.StateModificationInfo import org.utbot.framework.plugin.api.ClassId import org.utbot.framework.plugin.api.UtSymbolicExecution -import org.utbot.framework.plugin.api.util.hasField -import org.utbot.framework.plugin.api.util.id -import org.utbot.framework.plugin.api.util.isArray -import org.utbot.framework.plugin.api.util.isRefType -import org.utbot.framework.plugin.api.util.objectClassId +import org.utbot.framework.plugin.api.util.* import org.utbot.framework.util.hasThisInstance import org.utbot.fuzzer.UtFuzzedExecution import java.lang.reflect.Array @@ -141,7 +137,7 @@ internal class CgFieldStateManagerImpl(val context: CgContext) emptyLineIfNeeded() val fields = when (state) { FieldState.INITIAL -> modifiedFields - .filter { it.path.elements.isNotEmpty() && it.path.fieldType.isRefType } + .filter { it.path.elements.isNotEmpty() && !it.path.fieldType.isPrimitive } .filter { needExpectedDeclaration(it.after) } FieldState.FINAL -> modifiedFields } From 84eb506bfde20a4fc3b0c8739d99d39b36fb0238 Mon Sep 17 00:00:00 2001 From: Kamenev Yury Date: Mon, 12 Sep 2022 15:51:56 +0300 Subject: [PATCH 4/6] Removed field state assertions for failing tests --- .../constructor/tree/CgMethodConstructor.kt | 122 +++++++++++------- .../constructor/tree/TestFrameworkManager.kt | 11 ++ .../framework/codegen/model/tree/CgElement.kt | 13 +- 3 files changed, 94 insertions(+), 52 deletions(-) diff --git a/utbot-framework/src/main/kotlin/org/utbot/framework/codegen/model/constructor/tree/CgMethodConstructor.kt b/utbot-framework/src/main/kotlin/org/utbot/framework/codegen/model/constructor/tree/CgMethodConstructor.kt index 8bd36ad50f..01eba4300c 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/framework/codegen/model/constructor/tree/CgMethodConstructor.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/framework/codegen/model/constructor/tree/CgMethodConstructor.kt @@ -58,11 +58,7 @@ import org.utbot.framework.codegen.model.tree.CgStatement import org.utbot.framework.codegen.model.tree.CgStaticFieldAccess import org.utbot.framework.codegen.model.tree.CgTestMethod import org.utbot.framework.codegen.model.tree.CgTestMethodType -import org.utbot.framework.codegen.model.tree.CgTestMethodType.CRASH -import org.utbot.framework.codegen.model.tree.CgTestMethodType.FAILING -import org.utbot.framework.codegen.model.tree.CgTestMethodType.PARAMETRIZED -import org.utbot.framework.codegen.model.tree.CgTestMethodType.SUCCESSFUL -import org.utbot.framework.codegen.model.tree.CgTestMethodType.TIMEOUT +import org.utbot.framework.codegen.model.tree.CgTestMethodType.* import org.utbot.framework.codegen.model.tree.CgTryCatch import org.utbot.framework.codegen.model.tree.CgTypeCast import org.utbot.framework.codegen.model.tree.CgValue @@ -305,15 +301,13 @@ internal class CgMethodConstructor(val context: CgContext) : CgContextOwner by c assertEquality(expected, actual) } } - .onFailure { exception -> - processExecutionFailure(currentExecution, exception) - } + .onFailure { exception -> processExecutionFailure(exception) } } else -> {} // TODO: check this specific case } } - private fun processExecutionFailure(execution: UtExecution, exception: Throwable) { + private fun processExecutionFailure(exception: Throwable) { val methodInvocationBlock = { with(currentExecutable) { when (this) { @@ -324,42 +318,36 @@ internal class CgMethodConstructor(val context: CgContext) : CgContextOwner by c } } - if (shouldTestPassWithException(execution, exception)) { - testFrameworkManager.expectException(exception::class.id) { - methodInvocationBlock() - } - methodType = SUCCESSFUL - - return - } - - if (shouldTestPassWithTimeoutException(execution, exception)) { - writeWarningAboutTimeoutExceeding() - testFrameworkManager.expectTimeout(hangingTestsTimeout.timeoutMs) { - methodInvocationBlock() + when (methodType) { + SUCCESSFUL -> error("Unexpected successful without exception method type for execution with exception $exception") + PASSED_EXCEPTION -> { + testFrameworkManager.expectException(exception::class.id) { + methodInvocationBlock() + } } - methodType = TIMEOUT - - return - } - - when (exception) { - is ConcreteExecutionFailureException -> { - methodType = CRASH - writeWarningAboutCrash() + TIMEOUT -> { + writeWarningAboutTimeoutExceeding() + testFrameworkManager.expectTimeout(hangingTestsTimeout.timeoutMs) { + methodInvocationBlock() + } } - is AccessControlException -> { - methodType = CRASH - writeWarningAboutFailureTest(exception) - return + CRASH -> when (exception) { + is ConcreteExecutionFailureException -> { + writeWarningAboutCrash() + methodInvocationBlock() + } + is AccessControlException -> { + // exception from sandbox + writeWarningAboutFailureTest(exception) + } + else -> error("Unexpected crash suite for failing execution with $exception exception") } - else -> { - methodType = FAILING + FAILING -> { writeWarningAboutFailureTest(exception) + methodInvocationBlock() } + PARAMETRIZED -> error("Unexpected $PARAMETRIZED method type for failing execution with $exception exception") } - - methodInvocationBlock() } private fun shouldTestPassWithException(execution: UtExecution, exception: Throwable): Boolean { @@ -1187,9 +1175,7 @@ internal class CgMethodConstructor(val context: CgContext) : CgContextOwner by c constructorCall(*methodArguments.toTypedArray()) } } - .onFailure { exception -> - processExecutionFailure(currentExecution, exception) - } + .onFailure { exception -> processExecutionFailure(exception) } } /** @@ -1258,6 +1244,12 @@ internal class CgMethodConstructor(val context: CgContext) : CgContextOwner by c ) { thisInstance[executable](*methodArguments.toTypedArray()) } + + // We need to clear scope of created variables + // because after invocation of MUT some expressions could be changed. + // For example, fields of object that were null could be assigned to some new objects + // and previously created variables do not reflect these changes. + createdFromExpressionVariables.clear() } else -> {} // TODO: check this specific case } @@ -1288,11 +1280,22 @@ internal class CgMethodConstructor(val context: CgContext) : CgContextOwner by c val name = paramNames[executableId]?.get(index) methodArguments += variableConstructor.getOrCreateVariable(param, name) } - fieldStateManager.rememberInitialEnvironmentState(modificationInfo) + + if (requiresFieldStateAssertions()) { + // we should generate field assertions only for successful tests + // that does not break the current test execution after invocation of method under test + fieldStateManager.rememberInitialEnvironmentState(modificationInfo) + } + recordActualResult() generateResultAssertions() - fieldStateManager.rememberFinalEnvironmentState(modificationInfo) - generateFieldStateAssertions() + + if (requiresFieldStateAssertions()) { + // we should generate field assertions only for successful tests + // that does not break the current test execution after invocation of method under test + fieldStateManager.rememberFinalEnvironmentState(modificationInfo) + generateFieldStateAssertions() + } } if (statics.isNotEmpty()) { @@ -1340,6 +1343,10 @@ internal class CgMethodConstructor(val context: CgContext) : CgContextOwner by c } } + private fun requiresFieldStateAssertions(): Boolean = + !methodType.isThrowing || + (methodType == PASSED_EXCEPTION && !testFrameworkManager.isExpectedExceptionExecutionBreaking) + private val expectedResultVarName = "expectedResult" private val expectedErrorVarName = "expectedError" @@ -1367,7 +1374,8 @@ internal class CgMethodConstructor(val context: CgContext) : CgContextOwner by c substituteStaticFields(statics, isParametrized = true) // build this instance - thisInstance = genericExecution.stateBefore.thisInstance?.let { + thisInstance = + genericExecution.stateBefore.thisInstance?.let { variableConstructor.getOrCreateVariable(it) } @@ -1583,6 +1591,7 @@ internal class CgMethodConstructor(val context: CgContext) : CgContextOwner by c private fun withTestMethodScope(execution: UtExecution, block: () -> R): R { clearTestMethodScope() currentExecution = execution + determineExecutionType() statesCache = EnvironmentFieldStateCache.emptyCacheFor(execution) return try { block() @@ -1649,6 +1658,27 @@ internal class CgMethodConstructor(val context: CgContext) : CgContextOwner by c testSet.executions.any { it.result is UtExecutionFailure } + /** + * Determines [CgTestMethodType] for current execution according to its success or failure. + */ + private fun determineExecutionType() { + val currentExecution = currentExecution!! + + currentExecution.result + .onSuccess { methodType = SUCCESSFUL } + .onFailure { exception -> + methodType = when { + shouldTestPassWithException(currentExecution, exception) -> PASSED_EXCEPTION + shouldTestPassWithTimeoutException(currentExecution, exception) -> TIMEOUT + else -> when (exception) { + is ConcreteExecutionFailureException -> CRASH + is AccessControlException -> CRASH // exception from sandbox + else -> FAILING + } + } + } + } + private fun testMethod( methodName: String, displayName: String?, diff --git a/utbot-framework/src/main/kotlin/org/utbot/framework/codegen/model/constructor/tree/TestFrameworkManager.kt b/utbot-framework/src/main/kotlin/org/utbot/framework/codegen/model/constructor/tree/TestFrameworkManager.kt index fcc8ee0200..fec6458c1a 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/framework/codegen/model/constructor/tree/TestFrameworkManager.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/framework/codegen/model/constructor/tree/TestFrameworkManager.kt @@ -86,6 +86,11 @@ internal abstract class TestFrameworkManager(val context: CgContext) abstract val annotationForOuterClasses: CgAnnotation? + /** + * Determines whether appearance of expected exception in test method breaks current test execution or not. + */ + abstract val isExpectedExceptionExecutionBreaking: Boolean + protected open val timeoutArgumentName: String = "timeout" open fun assertEquals(expected: CgValue, actual: CgValue) { @@ -246,6 +251,8 @@ internal class TestNgManager(context: CgContext) : TestFrameworkManager(context) override val annotationForOuterClasses: CgAnnotation? get() = null + override val isExpectedExceptionExecutionBreaking: Boolean = false + override val timeoutArgumentName: String = "timeOut" private val assertThrows: BuiltinMethodId @@ -403,6 +410,8 @@ internal class Junit4Manager(context: CgContext) : TestFrameworkManager(context) ) } + override val isExpectedExceptionExecutionBreaking: Boolean = true + override fun expectException(exception: ClassId, block: () -> Unit) { require(testFramework is Junit4) { "According to settings, JUnit4 was expected, but got: $testFramework" } @@ -466,6 +475,8 @@ internal class Junit5Manager(context: CgContext) : TestFrameworkManager(context) override val annotationForOuterClasses: CgAnnotation? get() = null + override val isExpectedExceptionExecutionBreaking: Boolean = false + private val assertThrows: BuiltinMethodId get() { require(testFramework is Junit5) { "According to settings, JUnit5 was expected, but got: $testFramework" } diff --git a/utbot-framework/src/main/kotlin/org/utbot/framework/codegen/model/tree/CgElement.kt b/utbot-framework/src/main/kotlin/org/utbot/framework/codegen/model/tree/CgElement.kt index 05952f59f9..ce2de69bcb 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/framework/codegen/model/tree/CgElement.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/framework/codegen/model/tree/CgElement.kt @@ -335,12 +335,13 @@ class CgParameterizedTestDataProviderMethod( override val requiredFields: List = emptyList() } -enum class CgTestMethodType(val displayName: String) { - SUCCESSFUL("Successful tests"), - FAILING("Failing tests (with exceptions)"), - TIMEOUT("Failing tests (with timeout)"), - CRASH("Possibly crashing tests"), - PARAMETRIZED("Parametrized tests"); +enum class CgTestMethodType(val displayName: String, val isThrowing: Boolean) { + SUCCESSFUL(displayName = "Successful tests without exceptions", isThrowing = false), + PASSED_EXCEPTION(displayName = "Thrown exceptions marked as passed", isThrowing = true), + FAILING(displayName = "Failing tests (with exceptions)", isThrowing = true), + TIMEOUT(displayName = "Failing tests (with timeout)", isThrowing = true), + CRASH(displayName = "Possibly crashing tests", isThrowing = true), + PARAMETRIZED(displayName = "Parametrized tests", isThrowing = false); override fun toString(): String = displayName } From f5d558a57a9457765ba6e9572126bde9ac07aaca Mon Sep 17 00:00:00 2001 From: Kamenev Yury Date: Fri, 7 Oct 2022 16:57:37 +0800 Subject: [PATCH 5/6] Fixed rebase errors --- .../model/constructor/tree/CgMethodConstructor.kt | 6 ------ .../model/constructor/tree/TestsGenerationReport.kt | 11 ++++++----- 2 files changed, 6 insertions(+), 11 deletions(-) diff --git a/utbot-framework/src/main/kotlin/org/utbot/framework/codegen/model/constructor/tree/CgMethodConstructor.kt b/utbot-framework/src/main/kotlin/org/utbot/framework/codegen/model/constructor/tree/CgMethodConstructor.kt index 01eba4300c..f6bdc6a901 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/framework/codegen/model/constructor/tree/CgMethodConstructor.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/framework/codegen/model/constructor/tree/CgMethodConstructor.kt @@ -1244,12 +1244,6 @@ internal class CgMethodConstructor(val context: CgContext) : CgContextOwner by c ) { thisInstance[executable](*methodArguments.toTypedArray()) } - - // We need to clear scope of created variables - // because after invocation of MUT some expressions could be changed. - // For example, fields of object that were null could be assigned to some new objects - // and previously created variables do not reflect these changes. - createdFromExpressionVariables.clear() } else -> {} // TODO: check this specific case } diff --git a/utbot-framework/src/main/kotlin/org/utbot/framework/codegen/model/constructor/tree/TestsGenerationReport.kt b/utbot-framework/src/main/kotlin/org/utbot/framework/codegen/model/constructor/tree/TestsGenerationReport.kt index 606ef293af..deaaf72551 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/framework/codegen/model/constructor/tree/TestsGenerationReport.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/framework/codegen/model/constructor/tree/TestsGenerationReport.kt @@ -4,6 +4,7 @@ import org.utbot.common.appendHtmlLine import org.utbot.framework.codegen.model.constructor.CgMethodTestSet import org.utbot.framework.codegen.model.tree.CgTestMethod import org.utbot.framework.codegen.model.tree.CgTestMethodType +import org.utbot.framework.codegen.model.tree.CgTestMethodType.* import org.utbot.framework.plugin.api.ExecutableId import org.utbot.framework.plugin.api.util.kClass import kotlin.reflect.KClass @@ -57,11 +58,11 @@ data class TestsGenerationReport( testMethods.forEach { when (it.type) { - CgTestMethodType.SUCCESSFUL -> updateExecutions(it, successfulExecutions) - CgTestMethodType.FAILING -> updateExecutions(it, failedExecutions) - CgTestMethodType.TIMEOUT -> updateExecutions(it, timeoutExecutions) - CgTestMethodType.CRASH -> updateExecutions(it, crashExecutions) - CgTestMethodType.PARAMETRIZED -> { + SUCCESSFUL, PASSED_EXCEPTION -> updateExecutions(it, successfulExecutions) + FAILING -> updateExecutions(it, failedExecutions) + TIMEOUT -> updateExecutions(it, timeoutExecutions) + CRASH -> updateExecutions(it, crashExecutions) + PARAMETRIZED -> { // Parametrized tests are not supported in the tests report yet // TODO JIRA:1507 } From 130f598872ced00010ac76744a63e3b4aaf285c0 Mon Sep 17 00:00:00 2001 From: Kamenev Yury Date: Fri, 7 Oct 2022 21:20:40 +0800 Subject: [PATCH 6/6] Disabled Kotlin execution for the new test --- .../ClassWithPrivateMutableFieldOfPrivateTypeTest.kt | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/utbot-framework-test/src/test/kotlin/org/utbot/examples/codegen/modifiers/ClassWithPrivateMutableFieldOfPrivateTypeTest.kt b/utbot-framework-test/src/test/kotlin/org/utbot/examples/codegen/modifiers/ClassWithPrivateMutableFieldOfPrivateTypeTest.kt index ab1f4107bb..40e9d4be16 100644 --- a/utbot-framework-test/src/test/kotlin/org/utbot/examples/codegen/modifiers/ClassWithPrivateMutableFieldOfPrivateTypeTest.kt +++ b/utbot-framework-test/src/test/kotlin/org/utbot/examples/codegen/modifiers/ClassWithPrivateMutableFieldOfPrivateTypeTest.kt @@ -2,14 +2,22 @@ package org.utbot.examples.codegen.modifiers import org.junit.jupiter.api.Test import org.utbot.common.withAccessibility +import org.utbot.framework.plugin.api.CodegenLanguage import org.utbot.framework.plugin.api.FieldId import org.utbot.framework.plugin.api.util.id import org.utbot.framework.plugin.api.util.jField import org.utbot.testcheckers.eq +import org.utbot.tests.infrastructure.Compilation import org.utbot.tests.infrastructure.UtValueTestCaseChecker +// TODO failed Kotlin tests execution with non-nullable expected field class ClassWithPrivateMutableFieldOfPrivateTypeTest : UtValueTestCaseChecker( - testClass = ClassWithPrivateMutableFieldOfPrivateType::class + testClass = ClassWithPrivateMutableFieldOfPrivateType::class, + testCodeGeneration = true, + languagePipelines = listOf( + CodeGenerationLanguageLastStage(CodegenLanguage.JAVA), + CodeGenerationLanguageLastStage(CodegenLanguage.KOTLIN, Compilation) + ) ) { @Test fun testChangePrivateMutableFieldWithPrivateType() {