I'm writing unit tests for some function macros, which are just wrappers around some function calls, with a little housekeeping thrown in.
I've been writing tests all morning and I'm starting to get tedium of the brainpan, so this might just be a case of tunnel vision, but:
Is there a valid case to be made for unit testing for macro expansion? By that I mean checking that the correct function behavior is produced for the various source code forms of the function macro's arguments. For example, function arguments can take the form, in source code of a:
- literal
- variable
- operator expression
- struct member access
- pointer-to-struct member access
- pointer dereference
- array index
- function call
- macro expansion
- (feel free to point out any that I've missed)
If the macro doesn't expand properly, then the code usually won't even compile. So then, is there even any sensible point in a different unit test if the argument was a float literal or a float variable, or the result of a function call?
Should the expansion be part of the unit test?
value & 1could reveal that the macros are careless, but code inspections can do that too. I think going through the full panoply of tests is overkill; the tedium is giving you a relevant warning. - Jonathan Leffler