Skip to content

Commit

Permalink
Use assertSame instead of deepEquals if actual a mock (#2641)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
EgorkaKulikov authored Oct 4, 2023
1 parent b42b698 commit 09aebe1
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,8 @@ abstract class TestFramework(

open val testSuperClass: ClassId? = null

open val assertSame by lazy { assertionId("assertSame", objectClassId, objectClassId) }

open val assertEquals by lazy { assertionId("assertEquals", objectClassId, objectClassId) }

val assertFloatEquals by lazy { assertionId("assertEquals", floatClassId, floatClassId, floatClassId) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ abstract class TestFrameworkManager(val context: CgContext)

val assertions = context.testFramework.assertionsClass

val assertSame = context.testFramework.assertSame

val assertEquals = context.testFramework.assertEquals
val assertFloatEquals = context.testFramework.assertFloatEquals
val assertDoubleEquals = context.testFramework.assertDoubleEquals
Expand Down Expand Up @@ -86,6 +88,10 @@ abstract class TestFrameworkManager(val context: CgContext)
+assertions[assertEquals](expected, actual)
}

open fun assertSame(expected: CgValue, actual: CgValue) {
+assertions[assertSame](expected, actual)
}

open fun assertFloatEquals(expected: CgExpression, actual: CgExpression, delta: Any) {
+assertions[assertFloatEquals](expected, actual, delta)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ import org.utbot.framework.plugin.api.UtSymbolicExecution
import org.utbot.framework.plugin.api.UtTaintAnalysisFailure
import org.utbot.framework.plugin.api.UtTimeoutException
import org.utbot.framework.plugin.api.UtVoidModel
import org.utbot.framework.plugin.api.isMockModel
import org.utbot.framework.plugin.api.isNotNull
import org.utbot.framework.plugin.api.isNull
import org.utbot.framework.plugin.api.onFailure
Expand Down Expand Up @@ -618,6 +619,11 @@ open class CgMethodConstructor(val context: CgContext) : CgContextOwner by conte
visitedModels += modelWithField

with(testFrameworkManager) {
if (expectedModel.isMockModel()) {
currentBlock += assertions[assertSame](expected, actual).toStatement()
return
}

if (depth >= DEEP_EQUALS_MAX_DEPTH) {
currentBlock += CgSingleLineComment("Current deep equals depth exceeds max depth $DEEP_EQUALS_MAX_DEPTH")
currentBlock += getDeepEqualsAssertion(expected, actual).toStatement()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ class MochaManager(context: CgContext) : TestFrameworkManager(context) {
+assertions[jsAssertEquals](expected, actual)
}

override fun assertSame(expected: CgValue, actual: CgValue) {
error("assertSame does not exist in Mocha")
}

override fun disableTestMethod(reason: String) {

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,10 @@ internal class PytestManager(context: CgContext) : TestFrameworkManager(context)
)
}

override fun assertSame(expected: CgValue, actual: CgValue) {
error("assertSame does not exist in PyTest")
}

fun assertIsinstance(types: List<PythonClassId>, actual: CgVariable) {
+CgPythonAssertEquals(
CgPythonFunctionCall(
Expand All @@ -102,12 +106,16 @@ internal class UnittestManager(context: CgContext) : TestFrameworkManager(contex
override val isExpectedExceptionExecutionBreaking: Boolean = true

override val dataProviderMethodsHolder: TestClassContext
get() = error("Parametrized tests are not supported for JavaScript")
get() = error("Parametrized tests are not supported in Unittest")

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

override fun assertSame(expected: CgValue, actual: CgValue) {
error("assertSame does not exist in Unittest")
}

override fun expectException(exception: ClassId, block: () -> Unit) {
require(testFramework is Unittest) { "According to settings, Unittest was expected, but got: $testFramework" }
require(exception is PythonClassId) { "Exceptions must be PythonClassId" }
Expand Down

0 comments on commit 09aebe1

Please sign in to comment.