Skip to content

Fix empty else-branch in parameterized test generation #908

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

Merged
merged 1 commit into from
Sep 21, 2022
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
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,8 @@ sealed class TestFramework(

val assertNull by lazy { assertionId("assertNull", objectClassId) }

val assertNotNull by lazy { assertionId("assertNotNull", objectClassId) }

val assertFalse by lazy { assertionId("assertFalse", booleanClassId) }

val assertTrue by lazy { assertionId("assertTrue", booleanClassId) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1212,7 +1212,10 @@ internal class CgMethodConstructor(val context: CgContext) : CgContextOwner by c
else -> ifStatement(
CgEqualTo(expected, nullLiteral()),
trueBranch = { +testFrameworkManager.assertions[testFramework.assertNull](actual).toStatement() },
falseBranch = { generateDeepEqualsAssertion(expected, actual) }
falseBranch = {
+testFrameworkManager.assertions[testFrameworkManager.assertNotNull](actual).toStatement()
generateDeepEqualsAssertion(expected, actual)
}
)
}
}
Expand Down Expand Up @@ -1344,10 +1347,7 @@ internal class CgMethodConstructor(val context: CgContext) : CgContextOwner by c
fun createParameterizedTestMethod(testSet: CgMethodTestSet, dataProviderMethodName: String): CgTestMethod {
//TODO: orientation on generic execution may be misleading, but what is the alternative?
//may be a heuristic to select a model with minimal number of internal nulls should be used
val genericExecution = testSet.executions
.firstOrNull { it.result is UtExecutionSuccess && (it.result as UtExecutionSuccess).model !is UtNullModel }
?: testSet.executions
.firstOrNull { it.result is UtExecutionSuccess } ?: testSet.executions.first()
val genericExecution = chooseGenericExecution(testSet.executions)

val statics = genericExecution.stateBefore.statics

Expand Down Expand Up @@ -1415,6 +1415,13 @@ internal class CgMethodConstructor(val context: CgContext) : CgContextOwner by c
}
}

private fun chooseGenericExecution(executions: List<UtExecution>): UtExecution {
return executions
.firstOrNull { it.result is UtExecutionSuccess && (it.result as UtExecutionSuccess).model !is UtNullModel }
?: executions
.firstOrNull { it.result is UtExecutionSuccess } ?: executions.first()
}

private fun createParameterDeclarations(
testSet: CgMethodTestSet,
genericExecution: UtExecution,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ internal abstract class TestFrameworkManager(val context: CgContext)
val assertDoubleEquals = context.testFramework.assertDoubleEquals

val assertNull = context.testFramework.assertNull
val assertNotNull = context.testFramework.assertNotNull
val assertTrue = context.testFramework.assertTrue
val assertFalse = context.testFramework.assertFalse

Expand Down