Skip to content

Change private expectedResult type to Object in generated parametrized tests #528 #529

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
Jul 15, 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 @@ -231,8 +231,10 @@ internal class CgMethodConstructor(val context: CgContext) : CgContextOwner by c
val fieldAccessible = field.isAccessibleFrom(testClassPackageName)

// prevValue is nullable if not accessible because of getStaticFieldValue(..) : Any?
val prevValue = newVar(CgClassId(field.type, isNullable = !fieldAccessible),
"prev${field.name.capitalize()}") {
val prevValue = newVar(
CgClassId(field.type, isNullable = !fieldAccessible),
"prev${field.name.capitalize()}"
) {
if (fieldAccessible) {
declaringClass[field]
} else {
Expand Down Expand Up @@ -1198,7 +1200,8 @@ internal class CgMethodConstructor(val context: CgContext) : CgContextOwner by c
it.variableName,
// guard initializer to reuse typecast creation logic
initializer = guardExpression(varType, nullLiteral()).expression,
isMutable = true)
isMutable = true,
)
}
+tryWithMocksFinallyClosing
}
Expand Down Expand Up @@ -1253,10 +1256,13 @@ internal class CgMethodConstructor(val context: CgContext) : CgContextOwner by c
}
val method = currentExecutable as MethodId
val containsFailureExecution = containsFailureExecution(testSet)
if (method.returnType != voidClassId) {

val expectedResultClassId = wrapTypeIfRequired(method.returnType)

if (expectedResultClassId != voidClassId) {
testArguments += CgParameterDeclaration(
expectedResultVarName, resultClassId(method.returnType),
isReferenceType = containsFailureExecution || !method.returnType.isPrimitive
expectedResultVarName, resultClassId(expectedResultClassId),
isReferenceType = containsFailureExecution || !expectedResultClassId.isPrimitive
)
}
if (containsFailureExecution) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,8 @@ interface CgStatementConstructor {
fun declareVariable(type: ClassId, name: String): CgVariable

fun guardExpression(baseType: ClassId, expression: CgExpression): ExpressionWithType

fun wrapTypeIfRequired(baseType: ClassId): ClassId
}

internal class CgStatementConstructorImpl(context: CgContext) :
Expand Down Expand Up @@ -385,6 +387,9 @@ internal class CgStatementConstructorImpl(context: CgContext) :
updateVariableScope(it)
}

override fun wrapTypeIfRequired(baseType: ClassId): ClassId =
if (baseType.isAccessibleFrom(testClassPackageName)) baseType else objectClassId

// utils

private fun classRefOrNull(type: ClassId, expr: CgExpression): ClassId? {
Expand Down Expand Up @@ -444,11 +449,8 @@ internal class CgStatementConstructorImpl(context: CgContext) :
if (call.executableId != mockMethodId) return guardExpression(baseType, call)

// call represents a call to mock() method
return if (baseType.isAccessibleFrom(testClassPackageName)) {
ExpressionWithType(baseType, call)
} else {
ExpressionWithType(objectClassId, call)
}
val wrappedType = wrapTypeIfRequired(baseType)
return ExpressionWithType(wrappedType, call)
}

override fun guardExpression(baseType: ClassId, expression: CgExpression): ExpressionWithType {
Expand Down