summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorvlefevre <vlefevre@280ebfd0-de03-0410-8827-d642c229c3f4>2018-07-04 12:04:26 +0000
committervlefevre <vlefevre@280ebfd0-de03-0410-8827-d642c229c3f4>2018-07-04 12:04:26 +0000
commit6c966fc018f06dce6291768f6cf507d1241db665 (patch)
tree9aa1b3978cb4b6f36a32b40ad43d18159b242ac7
parentea41605991674a6117daf362c6ab521c9aadf2c9 (diff)
downloadmpfr-6c966fc018f06dce6291768f6cf507d1241db665.tar.gz
Added MPFR_CHECK_LOCALES environment variable for the tests (to be
used by developers): when set, terminate with an error if locales cannot be tested. (merged changeset r12870 from the trunk; merging tests/tprintf.c r12861 was needed first) git-svn-id: svn://scm.gforge.inria.fr/svn/mpfr/branches/4.0@12872 280ebfd0-de03-0410-8827-d642c229c3f4
-rw-r--r--doc/README.dev7
-rw-r--r--tests/tprintf.c26
-rw-r--r--tests/tsprintf.c22
3 files changed, 44 insertions, 11 deletions
diff --git a/doc/README.dev b/doc/README.dev
index ae91449ec..d820a2dbd 100644
--- a/doc/README.dev
+++ b/doc/README.dev
@@ -329,7 +329,7 @@ To make a release (for the MPFR team):
Also test with different environment variables set
(GMP_CHECK_RANDOMIZE, MPFR_CHECK_LIBC_PRINTF, MPFR_CHECK_LARGEMEM,
- MPFR_SUSPICIOUS_OVERFLOW).
+ MPFR_SUSPICIOUS_OVERFLOW, MPFR_CHECK_LOCALES).
Check there is no branch misprediction due to wrong MPFR_LIKELY or
MPFR_UNLIKELY statements. For that test, configure with
@@ -540,6 +540,11 @@ Environment variables that affect the tests:
the C library itself on some machines, and they
do not affect MPFR.
++ MPFR_CHECK_LOCALES: Fail in case a locale cannot be set. Developers
+ can set this variable on their machines to make
+ sure that needed locales are properly installed
+ and tested.
+
+ MPFR_DEBUG_BADCASES: For debugging (see tests.c, function bad_cases).
+ MPFR_SUSPICIOUS_OVERFLOW:
diff --git a/tests/tprintf.c b/tests/tprintf.c
index bb7fe90d6..dad57501a 100644
--- a/tests/tprintf.c
+++ b/tests/tprintf.c
@@ -493,11 +493,23 @@ test_locale (void)
mpfr_t x;
int count;
- for(i = 0; i < numberof(tab_locale) && s == NULL; i++)
- s = setlocale (LC_ALL, tab_locale[i]);
+ for (i = 0; i < numberof(tab_locale); i++)
+ {
+ s = setlocale (LC_ALL, tab_locale[i]);
+
+ if (s != NULL && MPFR_THOUSANDS_SEPARATOR == ',')
+ break;
+ }
+
+ if (i == numberof(tab_locale))
+ {
+ if (getenv ("MPFR_CHECK_LOCALES") == NULL)
+ return;
- if (s == NULL || MPFR_THOUSANDS_SEPARATOR != ',')
- return;
+ fprintf (stderr, "Cannot find a locale with ',' thousands separator.\n"
+ "Please install one of the en_US based locales.\n");
+ exit (1);
+ }
mpfr_init2 (x, 113);
mpfr_set_ui (x, 10000, MPFR_RNDN);
@@ -515,7 +527,11 @@ test_locale (void)
static void
test_locale (void)
{
- /* Nothing */
+ if (getenv ("MPFR_CHECK_LOCALES") != NULL)
+ {
+ fprintf (stderr, "Cannot test locales.\n");
+ exit (1);
+ }
}
#endif
diff --git a/tests/tsprintf.c b/tests/tsprintf.c
index 2f0c33dbf..b9cd19991 100644
--- a/tests/tsprintf.c
+++ b/tests/tsprintf.c
@@ -869,7 +869,7 @@ mixed (void)
/* Check with locale "da_DK". On most platforms, decimal point is ','
and thousands separator is '.'; the test is not performed if this
is not the case or if the locale doesn't exist. */
-static int
+static void
locale_da_DK (void)
{
mpfr_prec_t p = 128;
@@ -878,7 +878,14 @@ locale_da_DK (void)
if (setlocale (LC_ALL, "da_DK") == 0 ||
localeconv()->decimal_point[0] != ',' ||
localeconv()->thousands_sep[0] != '.')
- return 0;
+ {
+ if (getenv ("MPFR_CHECK_LOCALES") == NULL)
+ return;
+
+ fprintf (stderr,
+ "Cannot test the da_DK locale (not found or inconsistent).\n");
+ exit (1);
+ }
mpfr_init2 (x, p);
@@ -917,7 +924,6 @@ locale_da_DK (void)
check_sprintf ("100" S2 "0000", "%'.4Rf", x);
mpfr_clear (x);
- return 0;
}
#endif /* MPFR_LCONV_DPTS */
@@ -1447,10 +1453,16 @@ main (int argc, char **argv)
decimal ();
#if defined(HAVE_LOCALE_H) && defined(HAVE_SETLOCALE)
-#if MPFR_LCONV_DPTS
+# if MPFR_LCONV_DPTS
locale_da_DK ();
/* Avoid a warning by doing the setlocale outside of this #if */
-#endif
+# else
+ if (getenv ("MPFR_CHECK_LOCALES") != NULL)
+ {
+ fprintf (stderr, "Cannot test locales.\n");
+ exit (1);
+ }
+# endif
setlocale (LC_ALL, "C");
#endif
}