Mocking overloaded function

2024-01-08 Thread Strinnityk
Thank you for all your responses, they were quite insightful! So, I've tried running all your proposals and I always arrive at `Error: 'add' cannot be passed to a procvar`. Which, I understand, means I can't mock them because they're built-in, as @jyapayne mentioned. Out of curiosity, I take t

Mocking overloaded function

2024-01-05 Thread ElegantBeef
To start an arms race of "the best way to get a proc symbol" I enter my improved `extractProc` :P import std/[macros, genasts] macro extractProcImpl(call: typed): untyped = call[0] macro extractProc(prc: typed, params: varargs[typed]): untyped = result =

Mocking overloaded function

2024-01-05 Thread jyapayne
You can also disambiguate the function call you need with a macro like so: import macros proc dummy() = echo "normal dummy" proc dummy(s: string) = echo "string dummy " & s macro getProc(sym: typed, types: varargs[typedesc]): untyped =

Mocking overloaded function

2024-01-05 Thread ElegantBeef
Personally I find a macro like the following to work the best for grabbing overloaded symbols import std/macros macro extractProc(t: typed): untyped = if t.kind != nnkCall: error("Expected a call", t) t[0] var myAdd = static: var i: seq[int

Mocking overloaded function

2024-01-05 Thread Isofruit
What you're trying to do is something I attempted (and failed at with mockingbird) and has been solved by ElegantBeef: Enabling replacing any proc as long as it is assigned a specific pragma. I do not claim to understand it

Mocking overloaded function

2024-01-05 Thread Strinnityk
Hey there! I’ve been trying to mock a specific overload of the `system.add` function call using [this](https://forum.nim-lang.org/t/9255#60617) `mock` template. I’ve had luck with mocking non-overloaded functions but not this one. The main issue I’m facing (for now) is I’m not able to retrieve