[gjs: 6/10] build: Look for suitable locale to run tests in



commit 132e55c924e1fdb8ef598b31fa806e40c865690f
Author: Philip Chimento <philip endlessm com>
Date:   Thu Jan 10 16:22:10 2019 -0800

    build: Look for suitable locale to run tests in
    
    Apparently only newer libcs define a C.UTF-8 locale (see
    https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=636086). Notably, in
    the Freedesktop SDK there is no C.UTF-8 locale.
    
    This tests using "locale -a" if the C.UTF-8 locale is available, before
    selecting it. If it is not available, we try to find a reasonable
    fallback, preferring English locales in order to make it easier to share
    debug output in bug reports.

 Makefile-test.am |  2 +-
 configure.ac     | 26 ++++++++++++++++++++++++++
 2 files changed, 27 insertions(+), 1 deletion(-)
---
diff --git a/Makefile-test.am b/Makefile-test.am
index c251f1cc..c74f080b 100644
--- a/Makefile-test.am
+++ b/Makefile-test.am
@@ -286,7 +286,7 @@ AM_TESTS_ENVIRONMENT =                                      \
        export G_FILENAME_ENCODING=latin1;              \
        export LSAN_OPTIONS="suppressions=$(abs_top_srcdir)/installed-tests/extra/lsan.supp"; \
        export NO_AT_BRIDGE=1;                          \
-       export LC_ALL=C.UTF-8;                          \
+       export LC_ALL=$(TESTS_LOCALE);                  \
        $(COVERAGE_TESTS_ENVIRONMENT)                   \
        $(GTK_TESTS_ENVIRONMENT)                        \
        $(XVFB_START)                                   \
diff --git a/configure.ac b/configure.ac
index 3d7b2d18..f1d348b2 100644
--- a/configure.ac
+++ b/configure.ac
@@ -337,6 +337,26 @@ AS_IF([test "x$with_dbus_tests" != "xno"], [
 ])
 AM_CONDITIONAL([DBUS_TESTS], [test "x$with_dbus_tests" != "xno"])
 
+AC_MSG_CHECKING([for a suitable UTF-8 locale to run the tests in])
+LOCALES=$(locale -a)
+AS_CASE([$LOCALES],
+  dnl Prefer C.UTF-8 although it is only available with newer libc
+  [*C.UTF-8*], [TESTS_LOCALE=C.UTF-8],
+
+  dnl Most systems will probably have this
+  [*en_US.UTF-8*], [TESTS_LOCALE=en_US.UTF-8],
+  [*en_US.utf8*], [TESTS_LOCALE=en_US.utf8],
+
+  dnl If not, fall back to any English UTF-8 locale or any UTF-8 locale at all
+  [*en_*.UTF-8*], [TESTS_LOCALE=$(echo $LOCALES | grep -m1 en_.\*\\.UTF-8)],
+  [*en_*.utf8*], [TESTS_LOCALE=$(echo $LOCALES | grep -m1 en_.\*\\.utf8)],
+  [*.UTF-8*], [TESTS_LOCALE=$(echo $LOCALES | grep -m1 \\.UTF-8)],
+  [*.utf8*], [TESTS_LOCALE=$(echo $LOCALES | grep -m1 \\.utf8)],
+
+  [TESTS_LOCALE=C])
+AC_MSG_RESULT([$TESTS_LOCALE])
+AC_SUBST([TESTS_LOCALE])
+
 AC_SUBST([gjsjsdir], [\${datadir}/gjs-1.0])
 
 dnl automake 1.11/1.12 defines this but does not substitute it
@@ -362,6 +382,12 @@ PKG_CHECK_EXISTS([gobject-introspection-1.0 >= 1.57.2], [], [
 gobject-introspection to run the tests. You can still build GJS, but some
 tests will fail.])])
 
+AS_IF([test "$TESTS_LOCALE" = "C"], [
+  AC_MSG_WARN([Your libc does not have the C.UTF-8 locale and no other
+suitable UTF-8 fallback locale could be found. You can still build GJS, but
+some tests will fail.])
+])
+
 TEST_MSG=
 AM_COND_IF([XVFB_TESTS], [TEST_MSG="xvfb "])
 AM_COND_IF([DBUS_TESTS], [TEST_MSG="${TEST_MSG}dbus"])


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]