-
Notifications
You must be signed in to change notification settings - Fork 108
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add _FMT for every assertions? #114
Comments
You're right, it is convenient, but I've generally favored keeping it smaller (there's a self-imposed 1000 LOC limit guiding the design) and avoiding any non-portable constructs because I want it to be usable in any context C could be -- it's been used to drive testing of OS kernels, OS-less code running on embedded systems, etc. |
I understand your point. It's just that each time I get the "x < y" message I have either to start a debugger, print the variable before the assertion (thus editing the code, which isn't handy). Maybe changing the default formatting to print those values would be a reasonable suggestion? |
I would be happy to, but haven't yet figured out a way to do so portably, and without evaluating the arguments multiple times like I'm definitely not opposed, though! If there's a way to do it portably, I would add the format string as an argument (like |
Hi,
For the moment, ASSERT_GTE does only print that the assertion fails with the given argument without expansion so in a debugging purpose it's not convenient as you always have to finally add some printf's or to start debugging:
On the other hand
ASSERT_EQ_FMT
has the opportunity to print the different by expanding their values. Shouldn't we add _FMT for every assertion macros?I think that may clutter the number of macros but unfortunately in C we don't have a good template mechanism to print values without specifying the format string (we could use
_Generic
but that's limited and requires C11).We could also use some kind of literals macros:
ASSERT_INT_EQ|NE|LT|GT
and so on, then printf could simply use%ju
and force a cast(intmax_t)
on the user values.ASSERT_DOUBLE_...
and so on, ...The text was updated successfully, but these errors were encountered: