changeset 40040:9050cdbaac75

localename: Avoid test failure on some glibc systems. * tests/test-localename.c (test_locale_name, test_locale_name_posix): Unset environment variables that might disturb the first setlocale call, and verify that this setlocale call succeeds.
author Bruno Haible <bruno@clisp.org>
date Sun, 16 Dec 2018 21:31:15 +0100
parents 929010f01e22
children 4584f15ba9c0
files ChangeLog tests/test-localename.c
diffstat 2 files changed, 39 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog	Sun Dec 16 07:33:54 2018 -0800
+++ b/ChangeLog	Sun Dec 16 21:31:15 2018 +0100
@@ -1,3 +1,10 @@
+2018-12-16  Bruno Haible  <bruno@clisp.org>
+
+	localename: Avoid test failure on some glibc systems.
+	* tests/test-localename.c (test_locale_name, test_locale_name_posix):
+	Unset environment variables that might disturb the first setlocale call,
+	and verify that this setlocale call succeeds.
+
 2018-12-16  Assaf Gordon  <assafgordon@gmail.com>
 
 	random: Fix build error on native Windows (regression from 2018-06-21).
--- a/tests/test-localename.c	Sun Dec 16 07:33:54 2018 -0800
+++ b/tests/test-localename.c	Sun Dec 16 21:31:15 2018 +0100
@@ -67,6 +67,7 @@
 static void
 test_locale_name (void)
 {
+  const char *ret;
   const char *name;
 
   /* Check that gl_locale_name returns non-NULL.  */
@@ -85,7 +86,21 @@
   unsetenv ("LC_MESSAGES");
   unsetenv ("LC_NUMERIC");
   unsetenv ("LANG");
-  setlocale (LC_ALL, "");
+  /* Need also to unset all environment variables that specify standard or
+     non-standard locale categories.  Otherwise, on glibc systems, when some
+     of these variables are set and reference a nonexistent locale, the
+     setlocale (LC_ALL, "") call below would fail.  */
+  unsetenv ("LC_COLLATE");
+  unsetenv ("LC_MONETARY");
+  unsetenv ("LC_TIME");
+  unsetenv ("LC_ADDRESS");
+  unsetenv ("LC_IDENTIFICATION");
+  unsetenv ("LC_MEASUREMENT");
+  unsetenv ("LC_NAME");
+  unsetenv ("LC_PAPER");
+  unsetenv ("LC_TELEPHONE");
+  ret = setlocale (LC_ALL, "");
+  ASSERT (ret != NULL);
   ASSERT (strcmp (gl_locale_name (LC_MESSAGES, "LC_MESSAGES"),
                   gl_locale_name_default ()) == 0);
   ASSERT (strcmp (gl_locale_name (LC_NUMERIC, "LC_NUMERIC"),
@@ -496,6 +511,7 @@
 static void
 test_locale_name_posix (void)
 {
+  const char *ret;
   const char *name;
 
   /* Get into a defined state,  */
@@ -511,7 +527,21 @@
   unsetenv ("LC_MESSAGES");
   unsetenv ("LC_NUMERIC");
   unsetenv ("LANG");
-  setlocale (LC_ALL, "");
+  /* Need also to unset all environment variables that specify standard or
+     non-standard locale categories.  Otherwise, on glibc systems, when some
+     of these variables are set and reference a nonexistent locale, the
+     setlocale (LC_ALL, "") call below would fail.  */
+  unsetenv ("LC_COLLATE");
+  unsetenv ("LC_MONETARY");
+  unsetenv ("LC_TIME");
+  unsetenv ("LC_ADDRESS");
+  unsetenv ("LC_IDENTIFICATION");
+  unsetenv ("LC_MEASUREMENT");
+  unsetenv ("LC_NAME");
+  unsetenv ("LC_PAPER");
+  unsetenv ("LC_TELEPHONE");
+  ret = setlocale (LC_ALL, "");
+  ASSERT (ret != NULL);
   name = gl_locale_name_posix (LC_MESSAGES, "LC_MESSAGES");
   ASSERT (name == NULL || strcmp (name, gl_locale_name_default ()) == 0);
   name = gl_locale_name_posix (LC_NUMERIC, "LC_NUMERIC");