On Friday, 29 March 2024 at 07:21:43 UTC, Walter Bright wrote:
>You can add unit tests for C code already:
import myccode; // #define cmacro(a) 2
unittest
{
assert(cmacro(1) == 2);
}
The problem raised in that discussion has to do with things like
#define DOUBLE(x) (x) + (x)
DOUBLE(i++);
The output of DOUBLE isn't the problem, it's the part below it, which you referred to as metaprogramming. You can only test that by running the preprocessor on both lines. Currently, you'd have to create a new C file and add it to your project in order to put it in a unittest.
Now that some time has passed, where I've used this feature with at least 100,000 lines of C code, I'm not as concerned about it.