From: Bruno Haible Date: Sat, 26 Sep 2020 13:57:08 +0000 (+0200) Subject: regex-tests: Make test more robust. X-Git-Tag: v1.0~3601 X-Git-Url: https://gitweb.git.savannah.gnu.org/gitweb/?a=commitdiff_plain;h=b3865ddc7796109b265147ad1faff2ddba7dc861;p=gnulib.git regex-tests: Make test more robust. * tests/test-regex.c (main): Make sure to revert the locale to "C" after the test in "tr_TR.UTF-8" locale. Exit if we can't revert it. --- diff --git a/ChangeLog b/ChangeLog index 259f788f36..d5cabb4878 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2020-09-26 Bruno Haible + + regex-tests: Make test more robust. + * tests/test-regex.c (main): Make sure to revert the locale to "C" after + the test in "tr_TR.UTF-8" locale. Exit if we can't revert it. + 2020-09-25 Paul Eggert regex-tests: fix possible Turkish false-alarm diff --git a/tests/test-regex.c b/tests/test-regex.c index a54f643d83..3a3d8f1f1f 100644 --- a/tests/test-regex.c +++ b/tests/test-regex.c @@ -139,38 +139,46 @@ main (void) } if (! setlocale (LC_ALL, "C")) - return 1; + { + report_error ("setlocale \"C\" failed"); + return exit_status; + } } - if (setlocale (LC_ALL, "tr_TR.UTF-8") && really_utf8 () - && towupper (L'i') == 0x0130 /* U+0130; see below. */) + if (setlocale (LC_ALL, "tr_TR.UTF-8")) { - re_set_syntax (RE_SYNTAX_GREP | RE_ICASE); - memset (®ex, 0, sizeof regex); - static char const pat[] = "i"; - s = re_compile_pattern (pat, sizeof pat - 1, ®ex); - if (s) - report_error ("%s: %s", pat, s); - else + if (really_utf8 () && towupper (L'i') == 0x0130 /* U+0130; see below. */) { - /* UTF-8 encoding of U+0130 LATIN CAPITAL LETTER I WITH DOT ABOVE. - In Turkish, this is the upper-case equivalent of ASCII "i". - Older versions of Gnulib failed to match "i" to U+0130 when - ignoring case in Turkish . */ - static char const data[] = "\xc4\xb0"; + re_set_syntax (RE_SYNTAX_GREP | RE_ICASE); + memset (®ex, 0, sizeof regex); + static char const pat[] = "i"; + s = re_compile_pattern (pat, sizeof pat - 1, ®ex); + if (s) + report_error ("%s: %s", pat, s); + else + { + /* UTF-8 encoding of U+0130 LATIN CAPITAL LETTER I WITH DOT ABOVE. + In Turkish, this is the upper-case equivalent of ASCII "i". + Older versions of Gnulib failed to match "i" to U+0130 when + ignoring case in Turkish . */ + static char const data[] = "\xc4\xb0"; - memset (®s, 0, sizeof regs); - i = re_search (®ex, data, sizeof data - 1, 0, sizeof data - 1, - ®s); - if (i != 0) - report_error ("re_search '%s' on '%s' returned %d", - pat, data, i); - regfree (®ex); - free (regs.start); - free (regs.end); + memset (®s, 0, sizeof regs); + i = re_search (®ex, data, sizeof data - 1, 0, sizeof data - 1, + ®s); + if (i != 0) + report_error ("re_search '%s' on '%s' returned %d", + pat, data, i); + regfree (®ex); + free (regs.start); + free (regs.end); + } + } - if (! setlocale (LC_ALL, "C")) - report_error ("setlocale \"C\" failed"); + if (! setlocale (LC_ALL, "C")) + { + report_error ("setlocale \"C\" failed"); + return exit_status; } }