summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorArthur Schreiber <arthurschreiber@github.com>2016-10-06 18:30:30 -0700
committerArthur Schreiber <arthurschreiber@github.com>2016-10-07 12:47:04 -0700
commit361179786d9c27381bac185337db9526593e2b47 (patch)
tree1ad580fdd93346a2510d4e1e402ed7782cf78b7e
parent45dc219f656ff05c06246eec2b36e6805cdf8012 (diff)
downloadlibgit2-361179786d9c27381bac185337db9526593e2b47.tar.gz
Fix the existence check for `regcomp_l`.
`xlocale.h` only defines `regcomp_l` if `regex.h` was included as well. Also change the test cases to actually test `p_regcomp` works with a multibyte locale.
-rw-r--r--CMakeLists.txt2
-rw-r--r--tests/core/posix.c36
2 files changed, 30 insertions, 8 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index ed106e405..f26f46879 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -508,7 +508,7 @@ ELSE ()
ENDIF ()
ENDIF()
-CHECK_SYMBOL_EXISTS(regcomp_l "xlocale.h" HAVE_REGCOMP_L)
+CHECK_SYMBOL_EXISTS(regcomp_l "regex.h;xlocale.h" HAVE_REGCOMP_L)
IF (HAVE_REGCOMP_L)
ADD_DEFINITIONS(-DHAVE_REGCOMP_L)
ENDIF ()
diff --git a/tests/core/posix.c b/tests/core/posix.c
index 4e177b1f9..26ae36049 100644
--- a/tests/core/posix.c
+++ b/tests/core/posix.c
@@ -9,6 +9,8 @@
# endif
#endif
+#include <locale.h>
+
#include "clar_libgit2.h"
#include "posix.h"
#include "userdiff.h"
@@ -148,26 +150,46 @@ void test_core_posix__utimes(void)
p_unlink("foo");
}
-void test_core_posix__p_regcomp_compile_single_byte_regexps(void)
+void test_core_posix__p_regcomp_ignores_global_locale_ctype(void)
{
regex_t preg;
+ int error = 0;
+
+ const char* oldlocale = setlocale(LC_CTYPE, NULL);
- cl_must_pass(p_regcomp(&preg, "[\xc0-\xff][\x80-\xbf]", REG_EXTENDED));
+ if (!setlocale(LC_CTYPE, "UTF-8") &&
+ !setlocale(LC_CTYPE, "c.utf8") &&
+ !setlocale(LC_CTYPE, "en_US.UTF-8"))
+ cl_skip();
+ if (MB_CUR_MAX == 1) {
+ setlocale(LC_CTYPE, oldlocale);
+ cl_fail("Expected locale to be switched to multibyte");
+ }
+
+ p_regcomp(&preg, "[\xc0-\xff][\x80-\xbf]", REG_EXTENDED);
regfree(&preg);
+
+ setlocale(LC_CTYPE, oldlocale);
+
+ cl_must_pass(error);
}
void test_core_posix__p_regcomp_compile_userdiff_regexps(void)
{
- regex_t preg;
size_t idx;
for (idx = 0; idx < ARRAY_SIZE(builtin_defs); ++idx) {
git_diff_driver_definition ddef = builtin_defs[idx];
+ int error = 0;
+ regex_t preg;
- cl_must_pass(p_regcomp(&preg, ddef.fns, REG_EXTENDED | ddef.flags));
- cl_must_pass(p_regcomp(&preg, ddef.words, REG_EXTENDED));
- }
+ error = p_regcomp(&preg, ddef.fns, REG_EXTENDED | ddef.flags);
+ regfree(&preg);
+ cl_must_pass(error);
- regfree(&preg);
+ error = p_regcomp(&preg, ddef.words, REG_EXTENDED);
+ regfree(&preg);
+ cl_must_pass(error);
+ }
}