8000 Verify inline functions with reified and crossinline params · Issue #27 · mockk/mockk · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Verify inline functions with reified and crossinline params #27

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

Closed
kristiyanP opened this issue Feb 15, 2018 · 3 comments
Closed

Verify inline functions with reified and crossinline params #27

kristiyanP opened this issue Feb 15, 2018 · 3 comments

Comments

@kristiyanP
Copy link

Is it possible to verify a function like this?

inline fun <reified T> Socket.emitTyped(event: String,
                                        objectToEmit: Any?,
                                        crossinline success: (response: T) -> Unit,
                                        crossinline error: (reason: String) -> Unit) 
@oleksiyp
Copy link
Collaborator

@kristiyanP, unfortunately, it is not possible as no method with bytecode is produced. I heard this question already few times. It would require a totally different approach to solve. For example writing an annotation processor. I am thinking about it, as this can probably make it possible to run on Android devices.

@sriharshachilakapati
Copy link

Why not wrap it in a regular function and test that instead? Wouldn't that work?

inline fun <reified T> Socket.emitTyped(event: String,
                                        objectToEmit: Any?,
                                        crossinline success: (response: T) -> Unit,
                                        crossinline error: (reason: String) -> Unit) {
    // Some code which gets inlined
}

fun <T> emitTypedWrapper(event: String,
                                        objectToEmit: Any?,
                                        success: (response: T) -> Unit,
                                        error: (reason: String) -> Unit) {
    // This will be replaced with code inside the inline function by compiler
    Socket.emitTyped(event, objectToEmit, success, error)
}

Now write your tests with the wrapper function.

@paypulse
Copy link
paypulse commented Apr 10, 2025

Hi , this is my first comment
But, kotlin has a reified restrict . so, you can't use function

Why don't you use like this.
inline fun testEmitTyped(...) {
socket.emitTyped(...)
}
so, you can call emitTyped() ...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants
0