From 70c538cbfffd10895a4fa5a7965cad5e45497c6e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dag-Erling=20Sm=C3=B8rgrav?= Date: Mon, 9 Sep 2024 11:39:01 +0200 Subject: [PATCH] test-str-source: Return nonzero status if a test case fails. --- tests/test-str-source.c | 30 +++++++++++++++++++++--------- 1 file changed, 21 insertions(+), 9 deletions(-) diff --git a/tests/test-str-source.c b/tests/test-str-source.c index 1bd36c2..a899a70 100644 --- a/tests/test-str-source.c +++ b/tests/test-str-source.c @@ -116,28 +116,40 @@ free_str_source(tre_str_source *s) } /* Run one test with tre_reguexec */ -static void +static int test_reguexec(const char *str, const char *regex) { regex_t preg; tre_str_source *source; regmatch_t pmatch[5]; + int ret = 0; source = make_str_source(str); if (!source) - return; + return 1; tre_regcomp(&preg, regex, REG_EXTENDED); if (tre_reguexec(&preg, source, elementsof(pmatch), pmatch, 0) == 0) - fprintf(outf, "Match: %d - %d\n", (int)pmatch[0].rm_so, (int)pmatch[0].rm_eo); + { + fprintf(outf, "Match: /%s/ matches \"%.*s\" in \"%s\"\n", regex, + (int)(pmatch[0].rm_eo - pmatch[0].rm_so), str + pmatch[0].rm_so, + str); + } + else + { + fprintf(outf, "No match: /%s/ in \"%s\"\n", regex, str); + ret = 1; + } free_str_source(source); tre_regfree(&preg); + return ret; } int main(int argc, char **argv) { + int ret = 0; outf = stdout; #if defined(HAVE_UNISTD_H) || defined(HAVE_GETOPT_H) int opt; @@ -158,11 +170,11 @@ main(int argc, char **argv) } } #endif - test_reguexec("xfoofofoofoo","(foo)\\1"); - test_reguexec("catcat","(cat|dog)\\1"); - test_reguexec("catdog","(cat|dog)\\1"); - test_reguexec("dogdog","(cat|dog)\\1"); - test_reguexec("dogcat","(cat|dog)\\1"); + ret += test_reguexec("xfoofofoofoo", "(foo)\\1"); + ret += test_reguexec("catcat", "(cat|dog)\\1"); + ret += !test_reguexec("catdog", "(cat|dog)\\1"); + ret += test_reguexec("dogdog", "(cat|dog)\\1"); + ret += !test_reguexec("dogcat", "(cat|dog)\\1"); - return 0; + return ret; }