Skip to content

Commit 43e3d77

Browse files
committed
regex: report error failures in return code
1 parent bd135fb commit 43e3d77

1 file changed

Lines changed: 12 additions & 9 deletions

File tree

regex_src/regexMain.c

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ struct test_case {
105105
const regex_char_t *string; /* NULL : end of tests. */
106106
};
107107

108-
static void run_tests(struct test_case* test, int verbose, int silent)
108+
static int run_tests(struct test_case* test, int verbose, int silent)
109109
{
110110
int error;
111111
const regex_char_t *ptr;
@@ -123,12 +123,12 @@ static void run_tests(struct test_case* test, int verbose, int silent)
123123
/* sljit_get_platform_namei() is meant to return a string literal so this should never happen, but... */
124124
if (platform_name == NULL) {
125125
printf("ABORT: sljit_get_platform_name() broken\n");
126-
return;
126+
return 1;
127127
}
128128

129129
if (strlen(platform_name) >= PLATFORM_NAME_BUFFERSIZE_LIMIT) {
130130
printf("ABORT: Platform name '%s' exceeds %d bytes limit\n", platform_name, PLATFORM_NAME_BUFFERSIZE_LIMIT);
131-
return;
131+
return 1;
132132
}
133133

134134
for ( ; test->string ; test++) {
@@ -150,20 +150,20 @@ static void run_tests(struct test_case* test, int verbose, int silent)
150150
if (!verbose)
151151
printf("test: '%s' '%s': ", test->pattern ? test->pattern : "[[REUSE]]", test->string);
152152
printf("ABORT: Error %d\n", error);
153-
return;
153+
return 1;
154154
}
155155
if (!machine) {
156156
if (!verbose)
157157
printf("test: '%s' '%s': ", test->pattern ? test->pattern : "[[REUSE]]", test->string);
158158
printf("ABORT: machine must be exists. Report this bug, please\n");
159-
return;
159+
return 1;
160160
}
161161
}
162162
else if (test->flags != 0) {
163163
if (!verbose)
164164
printf("test: '%s' '%s': ", test->pattern ? test->pattern : "[[REUSE]]", test->string);
165165
printf("ABORT: flag must be 0 if no pattern\n");
166-
return;
166+
return 1;
167167
}
168168

169169
ptr = test->string;
@@ -177,7 +177,7 @@ static void run_tests(struct test_case* test, int verbose, int silent)
177177
printf("test: '%s' '%s': ", test->pattern ? test->pattern : "[[REUSE]]", test->string);
178178
printf("ABORT: Not enough memory for matching\n");
179179
regex_free_machine(machine);
180-
return;
180+
return 1;
181181
}
182182
regex_continue_match_debug(match, test->string, (int)(ptr - test->string));
183183
begin = regex_get_result(match, &end, &id);
@@ -230,6 +230,8 @@ static void run_tests(struct test_case* test, int verbose, int silent)
230230
else
231231
printf(COLOR_RED "%d" COLOR_DEFAULT " (" COLOR_RED "%d%%" COLOR_DEFAULT ") tests failed ", fail, fail * 100 / (success + fail));
232232
printf("on " COLOR_ARCH "%s" COLOR_DEFAULT "\n", platform_name);
233+
234+
return !!fail;
233235
}
234236

235237
/* Testing. */
@@ -331,6 +333,7 @@ static struct test_case tests[] = {
331333

332334
int main(int argc, char* argv[])
333335
{
336+
int ret;
334337
int has_arg = (argc >= 2 && argv[1][0] == '-' && argv[1][2] == '\0');
335338

336339
/* verbose_test("a((b)((c|d))|)c|"); */
@@ -340,11 +343,11 @@ int main(int argc, char* argv[])
340343
/* verbose_test("^a({2!})*b+(a|{1!}b)+d$"); */
341344
/* verbose_test("((a|b|c)*(xy)+)+", "asbcxyxy"); */
342345

343-
run_tests(tests, has_arg && argv[1][1] == 'v', has_arg && argv[1][1] == 's');
346+
ret = run_tests(tests, has_arg && argv[1][1] == 'v', has_arg && argv[1][1] == 's');
344347

345348
#if !(defined SLJIT_CONFIG_UNSUPPORTED && SLJIT_CONFIG_UNSUPPORTED)
346349
sljit_free_unused_memory_exec();
347350
#endif /* !SLJIT_CONFIG_UNSUPPORTED */
348351

349-
return 0;
352+
return ret;
350353
}

0 commit comments

Comments
 (0)