From 732035c57ff83f17f6bf66d79fcfa9b127878a16 Mon Sep 17 00:00:00 2001 From: Lucas Bajolet Date: Thu, 29 Mar 2018 15:53:46 -0400 Subject: [PATCH] tests: fix locale issue on non-Debian linux The C.UTF-8 locale is Debian-specific and causes issues on other platforms. To avoid setlocale error messages, the LC_ALL export will default on C.UTF-8, the system utf-8 locale if unavailable, and on C if no better choice is available. Signed-off-by: Lucas Bajolet --- tests/tests.sh | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/tests/tests.sh b/tests/tests.sh index 46cb74f..9eda24c 100755 --- a/tests/tests.sh +++ b/tests/tests.sh @@ -19,7 +19,24 @@ # Set lang do default to avoid failed tests because of locale export LANG=C.UTF-8 -export LC_ALL=C.UTF-8 + +# Explore candidates for LC_ALL +# +# If C.UTF-8, the most agnostic UTF-8 locale is supported, we +# use it, otherwise we default to the UTF-8 system locale, and +# if unavailable, we default on C. +# +# Note that C however is not guaranteed to be UTF-8, and +# some tests may fail when relying on Unicode semantics. +locale_candidate=C.UTF-8 +if ! locale -a 2>/dev/null | grep -q C.UTF-8; then + locale_candidate="$(locale -a | grep -i utf8 | head -n1)" + if [ -z "$locale_candidate" ]; then + locale_candidate=C + fi +fi +export LC_ALL="$locale_candidate" + if uname | grep Darwin 1>/dev/null 2>&1; then export LANG=en_US.UTF-8 export LC_ALL=en_US.UTF-8 -- 1.7.9.5