Use regular expressions when matching expected and actual text.
This commit is contained in:
@@ -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(®ex, expected, REG_NOSUB)) != 0) { \
|
||||
char errbuf[1024]; \
|
||||
regerror(result, ®ex, errbuf, sizeof(errbuf)); \
|
||||
fprintf(stderr, "regcomp failed at %s:%d: %s\npattern: %s\n", \
|
||||
__FILE__, __LINE__, errbuf, expected); \
|
||||
} else { \
|
||||
result = regexec(®ex, actual_str, 0, NULL, 0); \
|
||||
regfree(®ex); \
|
||||
} \
|
||||
} \
|
||||
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) \
|
||||
|
Reference in New Issue
Block a user