Skip to content

Commit

Permalink
test-str-source: Return nonzero status if a test case fails.
Browse files Browse the repository at this point in the history
  • Loading branch information
dag-erling committed Sep 9, 2024
1 parent 1d5f478 commit 70c538c
Showing 1 changed file with 21 additions and 9 deletions.
30 changes: 21 additions & 9 deletions tests/test-str-source.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
}

0 comments on commit 70c538c

Please sign in to comment.