Skip to content

Commit

Permalink
show calling function on unit test failure
Browse files Browse the repository at this point in the history
We compile using C17, so we can use `__func__` which has been
introduced with C99.
  • Loading branch information
mmitch committed Feb 22, 2025
1 parent 2a15563 commit dc48d48
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions test.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

#define ASSERT_EQUAL(fmt, a, b) do { \
if ((a) != (b)) { \
fprintf(stderr, "FAIL\nTest failed: "fmt"!="fmt" at %s:%d\n", (a), (b), __FILE__, __LINE__); \
fprintf(stderr, "FAIL\nTest failed: "fmt"!="fmt" at %s:%d in %s()\n", (a), (b), __FILE__, __LINE__, __func__); \
exit(1); \
} \
} while(0)
Expand All @@ -31,7 +31,7 @@
} \
if (pass) \
return; \
fprintf(stderr, "FAIL\nTest failed at %s:%d\n", __FILE__, __LINE__); \
fprintf(stderr, "FAIL\nTest failed at %s:%d in %s()\n", __FILE__, __LINE__, __func__); \
for (i=0; i<sizeof(a)/sizeof(*(a)); i++) { \
if ((a)[i] == (b)[i]) \
cmp = "=="; \
Expand Down

0 comments on commit dc48d48

Please # to comment.