|
9 | 9 | # endif |
10 | 10 | #endif |
11 | 11 |
|
| 12 | +#include <locale.h> |
| 13 | + |
12 | 14 | #include "clar_libgit2.h" |
13 | 15 | #include "posix.h" |
14 | 16 | #include "userdiff.h" |
@@ -148,26 +150,46 @@ void test_core_posix__utimes(void) |
148 | 150 | p_unlink("foo"); |
149 | 151 | } |
150 | 152 |
|
151 | | -void test_core_posix__p_regcomp_compile_single_byte_regexps(void) |
| 153 | +void test_core_posix__p_regcomp_ignores_global_locale_ctype(void) |
152 | 154 | { |
153 | 155 | regex_t preg; |
| 156 | + int error = 0; |
| 157 | + |
| 158 | + const char* oldlocale = setlocale(LC_CTYPE, NULL); |
154 | 159 |
|
155 | | - cl_must_pass(p_regcomp(&preg, "[\xc0-\xff][\x80-\xbf]", REG_EXTENDED)); |
| 160 | + if (!setlocale(LC_CTYPE, "UTF-8") && |
| 161 | + !setlocale(LC_CTYPE, "c.utf8") && |
| 162 | + !setlocale(LC_CTYPE, "en_US.UTF-8")) |
| 163 | + cl_skip(); |
156 | 164 |
|
| 165 | + if (MB_CUR_MAX == 1) { |
| 166 | + setlocale(LC_CTYPE, oldlocale); |
| 167 | + cl_fail("Expected locale to be switched to multibyte"); |
| 168 | + } |
| 169 | + |
| 170 | + p_regcomp(&preg, "[\xc0-\xff][\x80-\xbf]", REG_EXTENDED); |
157 | 171 | regfree(&preg); |
| 172 | + |
| 173 | + setlocale(LC_CTYPE, oldlocale); |
| 174 | + |
| 175 | + cl_must_pass(error); |
158 | 176 | } |
159 | 177 |
|
160 | 178 | void test_core_posix__p_regcomp_compile_userdiff_regexps(void) |
161 | 179 | { |
162 | | - regex_t preg; |
163 | 180 | size_t idx; |
164 | 181 |
|
165 | 182 | for (idx = 0; idx < ARRAY_SIZE(builtin_defs); ++idx) { |
166 | 183 | git_diff_driver_definition ddef = builtin_defs[idx]; |
| 184 | + int error = 0; |
| 185 | + regex_t preg; |
167 | 186 |
|
168 | | - cl_must_pass(p_regcomp(&preg, ddef.fns, REG_EXTENDED | ddef.flags)); |
169 | | - cl_must_pass(p_regcomp(&preg, ddef.words, REG_EXTENDED)); |
170 | | - } |
| 187 | + error = p_regcomp(&preg, ddef.fns, REG_EXTENDED | ddef.flags); |
| 188 | + regfree(&preg); |
| 189 | + cl_must_pass(error); |
171 | 190 |
|
172 | | - regfree(&preg); |
| 191 | + error = p_regcomp(&preg, ddef.words, REG_EXTENDED); |
| 192 | + regfree(&preg); |
| 193 | + cl_must_pass(error); |
| 194 | + } |
173 | 195 | } |
0 commit comments