Skip to content

Commit 09aebe1

Browse files
Use assertSame instead of deepEquals if actual a mock (#2641)
* Use assertSame instead of deepEquals if actual is a mock * Use assertSame instead of deepEquals if expected is a mock * assertSame is used on each depth of deepEquals
1 parent b42b698 commit 09aebe1

File tree

5 files changed

+27
-1
lines changed

5 files changed

+27
-1
lines changed

utbot-framework/src/main/kotlin/org/utbot/framework/codegen/domain/Domain.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,8 @@ abstract class TestFramework(
190190

191191
open val testSuperClass: ClassId? = null
192192

193+
open val assertSame by lazy { assertionId("assertSame", objectClassId, objectClassId) }
194+
193195
open val assertEquals by lazy { assertionId("assertEquals", objectClassId, objectClassId) }
194196

195197
val assertFloatEquals by lazy { assertionId("assertEquals", floatClassId, floatClassId, floatClassId) }

utbot-framework/src/main/kotlin/org/utbot/framework/codegen/services/framework/TestFrameworkManager.kt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ abstract class TestFrameworkManager(val context: CgContext)
4444

4545
val assertions = context.testFramework.assertionsClass
4646

47+
val assertSame = context.testFramework.assertSame
48+
4749
val assertEquals = context.testFramework.assertEquals
4850
val assertFloatEquals = context.testFramework.assertFloatEquals
4951
val assertDoubleEquals = context.testFramework.assertDoubleEquals
@@ -86,6 +88,10 @@ abstract class TestFrameworkManager(val context: CgContext)
8688
+assertions[assertEquals](expected, actual)
8789
}
8890

91+
open fun assertSame(expected: CgValue, actual: CgValue) {
92+
+assertions[assertSame](expected, actual)
93+
}
94+
8995
open fun assertFloatEquals(expected: CgExpression, actual: CgExpression, delta: Any) {
9096
+assertions[assertFloatEquals](expected, actual, delta)
9197
}

utbot-framework/src/main/kotlin/org/utbot/framework/codegen/tree/CgMethodConstructor.kt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ import org.utbot.framework.plugin.api.UtSymbolicExecution
115115
import org.utbot.framework.plugin.api.UtTaintAnalysisFailure
116116
import org.utbot.framework.plugin.api.UtTimeoutException
117117
import org.utbot.framework.plugin.api.UtVoidModel
118+
import org.utbot.framework.plugin.api.isMockModel
118119
import org.utbot.framework.plugin.api.isNotNull
119120
import org.utbot.framework.plugin.api.isNull
120121
import org.utbot.framework.plugin.api.onFailure
@@ -618,6 +619,11 @@ open class CgMethodConstructor(val context: CgContext) : CgContextOwner by conte
618619
visitedModels += modelWithField
619620

620621
with(testFrameworkManager) {
622+
if (expectedModel.isMockModel()) {
623+
currentBlock += assertions[assertSame](expected, actual).toStatement()
624+
return
625+
}
626+
621627
if (depth >= DEEP_EQUALS_MAX_DEPTH) {
622628
currentBlock += CgSingleLineComment("Current deep equals depth exceeds max depth $DEEP_EQUALS_MAX_DEPTH")
623629
currentBlock += getDeepEqualsAssertion(expected, actual).toStatement()

utbot-js/src/main/kotlin/framework/codegen/model/constructor/tree/JsTestFrameworkManager.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,10 @@ class MochaManager(context: CgContext) : TestFrameworkManager(context) {
5151
+assertions[jsAssertEquals](expected, actual)
5252
}
5353

54+
override fun assertSame(expected: CgValue, actual: CgValue) {
55+
error("assertSame does not exist in Mocha")
56+
}
57+
5458
override fun disableTestMethod(reason: String) {
5559

5660
}

utbot-python/src/main/kotlin/org/utbot/python/framework/codegen/model/constructor/tree/PythonTestFrameworkManager.kt

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,10 @@ internal class PytestManager(context: CgContext) : TestFrameworkManager(context)
8181
)
8282
}
8383

84+
override fun assertSame(expected: CgValue, actual: CgValue) {
85+
error("assertSame does not exist in PyTest")
86+
}
87+
8488
fun assertIsinstance(types: List<PythonClassId>, actual: CgVariable) {
8589
+CgPythonAssertEquals(
8690
CgPythonFunctionCall(
@@ -102,12 +106,16 @@ internal class UnittestManager(context: CgContext) : TestFrameworkManager(contex
102106
override val isExpectedExceptionExecutionBreaking: Boolean = true
103107

104108
override val dataProviderMethodsHolder: TestClassContext
105-
get() = error("Parametrized tests are not supported for JavaScript")
109+
get() = error("Parametrized tests are not supported in Unittest")
106110

107111
override fun addAnnotationForNestedClasses() {
108112
error("Nested classes annotation does not exist in Unittest")
109113
}
110114

115+
override fun assertSame(expected: CgValue, actual: CgValue) {
116+
error("assertSame does not exist in Unittest")
117+
}
118+
111119
override fun expectException(exception: ClassId, block: () -> Unit) {
112120
require(testFramework is Unittest) { "According to settings, Unittest was expected, but got: $testFramework" }
113121
require(exception is PythonClassId) { "Exceptions must be PythonClassId" }

0 commit comments

Comments
 (0)