Use regular expressions when matching expected and actual text.

This commit is contained in:
Todd C. Miller
2020-04-07 14:03:58 -06:00
parent 8a2c0d784f
commit a77ef93f8a
11 changed files with 57 additions and 39 deletions

View File

@@ -111,10 +111,27 @@ char ** create_str_array(size_t count, ...);
#define VERIFY_STR(actual, expected) \
do { \
const char *actual_str = actual; \
if (!actual_str || strcmp(actual_str, expected) != 0) { \
VERIFY_PRINT_MSG("%s", #actual, actual_str ? actual_str : "(null)", #expected, expected, "expected to be"); \
return false; \
} \
regex_t regex; \
int result = 0; \
if (!actual_str) { \
result = -1; \
} else if (*expected == '\0') { \
result = strcmp(actual_str, expected); \
} else { \
if ((result = regcomp(&regex, expected, REG_NOSUB)) != 0) { \
char errbuf[1024]; \
regerror(result, &regex, errbuf, sizeof(errbuf)); \
fprintf(stderr, "regcomp failed at %s:%d: %s\npattern: %s\n", \
__FILE__, __LINE__, errbuf, expected); \
} else { \
result = regexec(&regex, actual_str, 0, NULL, 0); \
regfree(&regex); \
} \
} \
if (result != 0) { \
VERIFY_PRINT_MSG("%s", #actual, actual_str ? actual_str : "(null)", #expected, expected, "expected to be"); \
return false; \
} \
} while(false)
#define VERIFY_STR_CONTAINS(actual, expected) \