-
-
Notifications
You must be signed in to change notification settings - Fork 0
Assert
This is the main Assertions macro.
It is a drop-in replacement for the C provided assert
.
The definition of the macro is variadic, but it actually requires at least one argument, being the condition.
When the condition is zero or false, a message will be printed and the program will be aborted, but if the condition is non-zero or true, the process will continue.
The condition of this macro doesn't actually need to use the utility macros provided.
It is pretty much just passed into an if
statement and used like that, so any condition could be used.
This macro also can take a format message.
This refers to all arguments after the first one.
The format message and arguments use the printf
format, as they are passed directly to it.
The order goes condition, message, format arguments.
Both the message and format arguments are optional and not required.
If no format message is specified, a default one will be used instead. This will include a message stating that an assertion failed as well as the condition that failed.
All error messages will include the file and line that the assertion was on.
Arguments:
-
Condition
: The condition to test. If false, abort. - [Optional]
Message
: An optional format message, passed toprintf
on failure. - [Optional]
Arguments
: Optional format arguments, passed withMessage
toprintf
on failure.
Example:
Assert(1); // Passes
Assert(1, "Expected success"); // Passes
Assert(1, "Expected success with %d", 1); // Passes
Assert(0); // Fails
Assert(0, "Expected failure"); // Fails
Assert(0, "Expected failure with %d", 0); // Fails