Commit 0d3ce2ac3f21f7b1af02c64a6c2ba0e9e59eea29

Edward Thomson 2020-06-02T10:23:41

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 `$`.

diff --git a/tests/clar.c b/tests/clar.c
index ead13f4..69283b8 100644
--- a/tests/clar.c
+++ b/tests/clar.c
@@ -293,6 +293,7 @@ clar_run_suite(const struct clar_suite *suite, const char *filter)
 	const struct clar_func *test = suite->tests;
 	size_t i, matchlen;
 	struct clar_report *report;
+	int exact = 0;
 
 	if (!suite->enabled)
 		return;
@@ -317,6 +318,11 @@ clar_run_suite(const struct clar_suite *suite, const char *filter)
 			while (*filter == ':')
 				++filter;
 			matchlen = strlen(filter);
+
+			if (matchlen && filter[matchlen - 1] == '$') {
+				exact = 1;
+				matchlen--;
+			}
 		}
 	}
 
@@ -324,6 +330,9 @@ clar_run_suite(const struct clar_suite *suite, const char *filter)
 		if (filter && strncmp(test[i].name, filter, matchlen))
 			continue;
 
+		if (exact && strlen(test[i].name) != matchlen)
+			continue;
+
 		_clar.active_test = test[i].name;
 
 		report = calloc(1, sizeof(struct clar_report));