Skip to content

Commit 0d3ce2a

Browse files
committed
offer exact name matching with a $ suffix
When using `-s` to specify a particular test, it will do a prefix match. Thus, `-sapply::both::rename_a_to_b_to_c` will match both a test named `test_apply_both__rename_a_to_b_to_c` and a test that begins with that name, like `test_apply_both__rename_a_to_b_to_c_exact`. Permit a trailing `$` to `-s` syntax. This allows a user to specify `-sapply::both::rename_a_to_b_to_c$` to match _only_ the `test_apply_both__rename_a_to_b_to_c` function. We already filter to ensure that the given prefix matches the current test name. Also ensure that the length of the test name matches the length of the filter, sans trailing `$`.
1 parent d4b953f commit 0d3ce2a

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

tests/clar.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,7 @@ clar_run_suite(const struct clar_suite *suite, const char *filter)
293293
const struct clar_func *test = suite->tests;
294294
size_t i, matchlen;
295295
struct clar_report *report;
296+
int exact = 0;
296297

297298
if (!suite->enabled)
298299
return;
@@ -317,13 +318,21 @@ clar_run_suite(const struct clar_suite *suite, const char *filter)
317318
while (*filter == ':')
318319
++filter;
319320
matchlen = strlen(filter);
321+
322+
if (matchlen && filter[matchlen - 1] == '$') {
323+
exact = 1;
324+
matchlen--;
325+
}
320326
}
321327
}
322328

323329
for (i = 0; i < suite->test_count; ++i) {
324330
if (filter && strncmp(test[i].name, filter, matchlen))
325331
continue;
326332

333+
if (exact && strlen(test[i].name) != matchlen)
334+
continue;
335+
327336
_clar.active_test = test[i].name;
328337

329338
report = calloc(1, sizeof(struct clar_report));

0 commit comments

Comments
 (0)