Skip to content

Commit

Permalink
fix macros not handling args with commas and a small buffer (#3)
Browse files Browse the repository at this point in the history
  • Loading branch information
probablyanewt authored Sep 30, 2024
1 parent 61e24e6 commit 9729ceb
Showing 1 changed file with 13 additions and 13 deletions.
26 changes: 13 additions & 13 deletions pactf.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

// Constants
#define PACTF_STR_BUF_LEN 50
#define PACTF_PREFIX_BUF_LEN 4
#define PACTF_PREFIX_BUF_LEN 10
#define P_STRINGIFY(x) #x

// Loggers
Expand Down Expand Up @@ -35,40 +35,40 @@
}

// Helpers
#define P_FUNCTION(name, fn_body) \
#define P_FUNCTION(name, __VA_ARGS__) \
{ \
char pactf_test_prefix[PACTF_PREFIX_BUF_LEN] = "- "; \
(void)pactf_test_prefix; \
char pactf_assert_prefix[PACTF_PREFIX_BUF_LEN] = " "; \
(void)pactf_assert_prefix; \
\
P_LOG("\n%s\n", name); \
{ fn_body } \
{ __VA_ARGS__ } \
}

#define P_TEST(name, test_body) \
#define P_TEST(name, ...) \
P_LOG("%s%s\n", pactf_test_prefix, name); \
if (pactf_before_each) { \
pactf_before_each(); \
} \
{ test_body } \
{ __VA_ARGS__ } \
if (pactf_after_each) { \
pactf_after_each(); \
}

#define P_BEFORE_EACH(before_each_body) \
void pactf_before_each() { before_each_body }
#define P_BEFORE_EACH(...) \
void pactf_before_each() { __VA_ARGS__ }

#define P_AFTER_EACH(after_each_body) \
void pactf_after_each() { after_each_body }
#define P_AFTER_EACH(...) \
void pactf_after_each() { __VA_ARGS__ }

// Core
#define PACTF_SETUP(setup_body) \
#define PACTF_SETUP(...) \
void pactf_before_each() __attribute__((weak)); \
void pactf_after_each() __attribute__((weak)); \
setup_body
__VA_ARGS__

#define PACTF_SUITE(tests_body) \
#define PACTF_SUITE(...) \
void pactf_before_each() __attribute__((weak)); \
void pactf_after_each() __attribute__((weak)); \
\
Expand All @@ -81,7 +81,7 @@
(void)pactf_assert_prefix; \
int pactf_errors = 0; \
\
{ tests_body } \
{ __VA_ARGS__ } \
\
if (pactf_errors > 0) { \
return 1; \
Expand Down

0 comments on commit 9729ceb

Please sign in to comment.