Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use assertSame instead of deepEquals if actual is a mock #2641

Merged
merged 3 commits into from
Oct 4, 2023
Merged
Show file tree
Hide file tree
Changes from 2 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
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) {
EgorkaKulikov marked this conversation as resolved.
Show resolved Hide resolved
+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 @@ -1225,7 +1226,12 @@ open class CgMethodConstructor(val context: CgContext) : CgContextOwner by conte
if (!successfullyConstructedCustomAssert) {
val expectedVariable = variableConstructor.getOrCreateVariable(expected, expectedVariableName)
if (emptyLineIfNeeded) emptyLineIfNeeded()
assertEquality(expectedVariable, actual)

if (expected.isMockModel()) {
EgorkaKulikov marked this conversation as resolved.
Show resolved Hide resolved
testFrameworkManager.assertSame(expectedVariable, actual)
} else {
assertEquality(expectedVariable, actual)
}
}
}

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")
EgorkaKulikov marked this conversation as resolved.
Show resolved Hide resolved
}

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