After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 748610 - Some tests fail with non-English locales
Some tests fail with non-English locales
Status: RESOLVED FIXED
Product: glib
Classification: Platform
Component: general
unspecified
Other FreeBSD
: Normal normal
: ---
Assigned To: gtkdev
gtkdev
: 727920 (view as bug list)
Depends on:
Blocks:
 
 
Reported: 2015-04-29 06:51 UTC by Ting-Wei Lan
Modified: 2017-10-26 11:07 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
tests: Fix tests that fail with non-English locales (2.28 KB, patch)
2015-04-29 06:53 UTC, Ting-Wei Lan
none Details | Review
tests: Fix tests that fail with non-English locales - always use g_setenv in main (2.48 KB, patch)
2015-05-01 17:05 UTC, Ting-Wei Lan
committed Details | Review

Description Ting-Wei Lan 2015-04-29 06:51:12 UTC
There are 4 failing tests in glib/tests when using a non-English locales because they check whether the translated messages are expected.

I have a patch that adds g_setenv ("LC_ALL", "C", TRUE); to fix the problem.
Comment 1 Ting-Wei Lan 2015-04-29 06:53:56 UTC
Created attachment 302539 [details] [review]
tests: Fix tests that fail with non-English locales
Comment 2 Dan Winship 2015-05-01 13:53:10 UTC
Comment on attachment 302539 [details] [review]
tests: Fix tests that fail with non-English locales

>-  g_setenv ("LANG", "en_US.utf-8", TRUE);
>+  g_setenv ("LC_ALL", "en_US.utf-8", TRUE);

Why does LANG not work?

Note that option-context.c uses g_setenv("LANG"...) too

> test_format_size_for_display (void)
> {
>+  g_setenv ("LC_ALL", "C", TRUE);
> #ifdef G_OS_WIN32
>   SetThreadLocale (MAKELCID (MAKELANGID (LANG_ENGLISH, SUBLANG_ENGLISH_US), SORT_DEFAULT));
> #endif

It should do this from main(), like date.c does (because it's not safe to call g_setenv() if other threads are running, and it's difficult to know whether other threads are running or not once the program is doing anything).

>+++ b/glib/tests/option-context.c
>@@ -2487,6 +2487,7 @@ main (int   argc,
>   int i;
>   gchar *test_name;
> 
>+  g_setenv ("LC_ALL", "C", TRUE);

oh, so that answers part of my LANG-vs-LC_ALL question above. You should remove the existing g_setenv("LANG"...)
Comment 3 Ting-Wei Lan 2015-05-01 17:05:10 UTC
Created attachment 302728 [details] [review]
tests: Fix tests that fail with non-English locales - always use g_setenv in main

(In reply to Dan Winship from comment #2)
> Comment on attachment 302539 [details] [review] [review]
> tests: Fix tests that fail with non-English locales
> 
> >-  g_setenv ("LANG", "en_US.utf-8", TRUE);
> >+  g_setenv ("LC_ALL", "en_US.utf-8", TRUE);
> 
> Why does LANG not work?

If LC_ALL is already set in the environment, setlocale will use LC_ALL instead of LANG.

> 
> Note that option-context.c uses g_setenv("LANG"...) too
> 
> > test_format_size_for_display (void)
> > {
> >+  g_setenv ("LC_ALL", "C", TRUE);
> > #ifdef G_OS_WIN32
> >   SetThreadLocale (MAKELCID (MAKELANGID (LANG_ENGLISH, SUBLANG_ENGLISH_US), SORT_DEFAULT));
> > #endif
> 
> It should do this from main(), like date.c does (because it's not safe to
> call g_setenv() if other threads are running, and it's difficult to know
> whether other threads are running or not once the program is doing anything).

Fixed in the new patch.

> 
> >+++ b/glib/tests/option-context.c
> >@@ -2487,6 +2487,7 @@ main (int   argc,
> >   int i;
> >   gchar *test_name;
> > 
> >+  g_setenv ("LC_ALL", "C", TRUE);
> 
> oh, so that answers part of my LANG-vs-LC_ALL question above. You should
> remove the existing g_setenv("LANG"...)
Comment 4 Dan Winship 2015-06-29 14:42:06 UTC
Comment on attachment 302728 [details] [review]
tests: Fix tests that fail with non-English locales - always use g_setenv in main

looks good
Comment 5 Ting-Wei Lan 2015-06-29 14:52:14 UTC
Attachment 302728 [details] pushed as 5574315 - tests: Fix tests that fail with non-English locales
Comment 6 Philip Withnall 2017-10-26 11:07:50 UTC
*** Bug 727920 has been marked as a duplicate of this bug. ***