X-Git-Url: http://git.annexia.org/?a=blobdiff_plain;f=tests.h;h=dc6abe87b418b59e106fa701e136f27958636f39;hb=fcf73607913050d246dbcc4f39e7717d0960763f;hp=e258782f14788e76c6f236be907b24eae621a3ac;hpb=5cac23de1963880d8fb3aed4be47ec2894cf520c;p=miniexpect.git diff --git a/tests.h b/tests.h index e258782..dc6abe8 100644 --- a/tests.h +++ b/tests.h @@ -1,5 +1,5 @@ /* miniexpect test suite - * Copyright (C) 2014 Red Hat Inc. + * Copyright (C) 2014-2022 Red Hat Inc. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -39,4 +39,27 @@ test_diagnose (int status) fprintf (stderr, "stopped by signal %d", WSTOPSIG (status)); } +__attribute__((__unused__)) +static pcre2_code * +test_compile_re (const char *rex) +{ + int errorcode; + PCRE2_SIZE erroroffset; + char errormsg[256]; + pcre2_code *ret; + + ret = pcre2_compile ((PCRE2_SPTR) rex, PCRE2_ZERO_TERMINATED, + 0, &errorcode, &erroroffset, NULL); + if (ret == NULL) { + pcre2_get_error_message (errorcode, + (PCRE2_UCHAR *) errormsg, sizeof errormsg); + fprintf (stderr, "error: " + "failed to compile regular expression '%s': " + "%s at offset %zu\n", + rex, errormsg, erroroffset); + exit (EXIT_FAILURE); + } + return ret; +} + #endif /* TESTS_H_ */