Hacker News new | ask | show | jobs
by Robadob 2235 days ago
We've come across this problem. The major testing frameworks seem to rely heavily on macros for tests. In particular, we were struggling to handle tests of thrown exceptions, as we couldn't trivially capture the result in a variable and place that inside the macro instead. The most versatile solution we found was to use a function pointer, so that the templating wasn't required when the function was called.
1 comments

If you want the name of a variable in eg. an assert you need the # operator unless you require the programmer to manually write the name as a string.
You could also

1) parse the source file

2) find the debug info and read it

3) hack the compiler to do this for you