I use the unit test structure, which relies on the REQUIRE
macro to execute statements.
Simplified, the macro works as follows:
#define REQUIRE( expr ) INTERNAL_REQUIRE( expr, "REQUIRE" )
Which is defined similarly to this:
#define INTERNAL_REQUIRE( expr, macroName ) \ PerformAssertion( macroName, #expr, expr );
PerformAssertion
first two parameters are of type: const char*
. The reason for the second parameter ( #expr
) is that the exact expression that was declared can be registered. This is the problem. The preprocessor extends the expression before it is passed as const char *
, so it is not the same expression that was originally approved.
For instance:
REQUIRE( foo != NULL );
The result of this call:
PerformAssertion( "REQUIRE", "foo != 0", foo != 0 );
As you can see, the expression is partially extended, for example. the expression foo != NULL
appears in the log as foo != 0
. NULL
(which is a macro defined as 0
) was extended by the C preprocessor before creating the message body with the statements. Is there a way to ignore or bypass the extension for message text?
EDIT: here's a solution for anyone curious:
#define REQUIRE( expr ) INTERNAL_REQUIRE( expr, #expr, "REQUIRE" ) #define INTERNAL_REQUIRE( expr, exprString, macroName ) \ PerformAssertion( macroName, exprString, expr );