-
Notifications
You must be signed in to change notification settings - Fork 3
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
Adding support for Spies in Code Generation #128
Conversation
cc6c711
to
7f1987a
Compare
This patch allows the new ksp based code generator to generate Spies in addition to mocks
7f1987a
to
c4a0cbe
Compare
interface CodeBlockFactory { | ||
fun resolveSupertype(): String | ||
fun decorateConstructor(classToMock: KSType, classBuilder: TypeSpec.Builder) | ||
fun decorateFunctionBody(classToMock: KSClassDeclaration, function: KSFunctionDeclaration, isUnit: Boolean, functionBuilder: FunSpec.Builder) | ||
fun decoratePropertyGetter(classToMock: KSClassDeclaration, property: KSPropertyDeclaration, propertyBuilder: PropertySpec.Builder, typeResolver: Map<KSTypeParameter, KSTypeArgument>) | ||
fun decoratePropertySetter(classToMock: KSClassDeclaration, property: KSPropertyDeclaration, propertyBuilder: PropertySpec.Builder, typeResolver: Map<KSTypeParameter, KSTypeArgument>) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this si where codegen is different in Spies respect to mocks
import com.squareup.kotlinpoet.ksp.toKModifier | ||
import com.squareup.kotlinpoet.ksp.toTypeName | ||
|
||
abstract class Generator constructor( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just rename of MockGenerator, non common logic has been extracted to MockGenerator
and SpyGenerator
) | ||
} | ||
|
||
override fun decorateFunctionBody( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
function body is different between mocks and spies, this is the spy impl for the code gen of that block
// @Spy | ||
// lateinit var pippoMock: PippoSample | ||
// FIXME suspend function is not working |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this will be supported in future PRs
This patch allows the new ksp based code generator to generate Spies in addition to mocks
TODO: