summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorBruno Haible <bruno@clisp.org>2018-12-16 21:31:15 +0100
committerBruno Haible <bruno@clisp.org>2018-12-16 21:31:15 +0100
commit61fbeacfc33f05999dd44586e8a4960ca1aceb00 (patch)
tree69867a88969d7c4bee3bc6d4d5aabc8e198e1b23 /tests
parenta00bedccf07e5c7e51a518a4eb97f0a4c6c65fd5 (diff)
downloadgnulib-61fbeacfc33f05999dd44586e8a4960ca1aceb00.tar.gz
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.
Diffstat (limited to 'tests')
-rw-r--r--tests/test-localename.c34
1 files changed, 32 insertions, 2 deletions
diff --git a/tests/test-localename.c b/tests/test-localename.c
index 8c3c4254b0..2b91782f71 100644
--- a/tests/test-localename.c
+++ b/tests/test-localename.c
@@ -67,6 +67,7 @@ static struct { int cat; int mask; const char *string; } const categories[] =
static void
test_locale_name (void)
{
+ const char *ret;
const char *name;
/* Check that gl_locale_name returns non-NULL. */
@@ -85,7 +86,21 @@ test_locale_name (void)
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 @@ test_locale_name_thread (void)
static void
test_locale_name_posix (void)
{
+ const char *ret;
const char *name;
/* Get into a defined state, */
@@ -511,7 +527,21 @@ test_locale_name_posix (void)
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");