Further research shows that the reason commit
7db6809ce failed
is that recent glibc versions short-circuit translation attempts
when LC_MESSAGES is 'C.<encoding>', not only when it's 'C'.
There seems no way around that, so we'll have to live with only
testing NLS when a suitable real locale is installed.
However, something can still be salvaged: it still seems like a
good idea to verify that the PRI* macros work as-expected even when
we can't check their translations (see
f8715ec86 for motivation).
Hence, adjust the test to always run the ereport calls, and tweak
the parameter values in hopes of detecting any cases where there's
confusion about the actual widths of the parameters.
Discussion: https://postgr.es/m/
1991599.
1765818338@sss.pgh.pa.us
raise log 'NLS regression test: lc_messages = %',
current_setting('lc_messages');
end $$;
-SELECT current_setting('lc_messages') = 'C' AS failed \gset
-\if :failed
-\echo Could not find an acceptable spelling of es_ES locale
-\quit
-\endif
SELECT test_translation();
NOTICE: traducido PRId64 = 424242424242
NOTICE: traducido PRId32 = -1234
-NOTICE: traducido PRIdMAX = -5678
-NOTICE: traducido PRIdPTR = 9999
+NOTICE: traducido PRIdMAX = -123456789012
+NOTICE: traducido PRIdPTR = -9999
NOTICE: traducido PRIu64 = 424242424242
-NOTICE: traducido PRIu32 = 1234
-NOTICE: traducido PRIuMAX = 5678
+NOTICE: traducido PRIu32 = 4294966062
+NOTICE: traducido PRIuMAX = 123456789012
NOTICE: traducido PRIuPTR = 9999
NOTICE: traducido PRIx64 = 62c6d1a9b2
-NOTICE: traducido PRIx32 = 4d2
-NOTICE: traducido PRIxMAX = 162e
+NOTICE: traducido PRIx32 = fffffb2e
+NOTICE: traducido PRIxMAX = 1cbe991a14
NOTICE: traducido PRIxPTR = 270f
NOTICE: traducido PRIX64 = 62C6D1A9B2
-NOTICE: traducido PRIX32 = 4D2
-NOTICE: traducido PRIXMAX = 162E
+NOTICE: traducido PRIX32 = FFFFFB2E
+NOTICE: traducido PRIXMAX = 1CBE991A14
NOTICE: traducido PRIXPTR = 270F
test_translation
------------------
raise log 'NLS regression test: lc_messages = %',
current_setting('lc_messages');
end $$;
-SELECT current_setting('lc_messages') = 'C' AS failed \gset
-\if :failed
-\echo Could not find an acceptable spelling of es_ES locale
-\quit
-\endif
SELECT test_translation();
NOTICE: NLS is not enabled
+NOTICE: translated PRId64 = 424242424242
+NOTICE: translated PRId32 = -1234
+NOTICE: translated PRIdMAX = -123456789012
+NOTICE: translated PRIdPTR = -9999
+NOTICE: translated PRIu64 = 424242424242
+NOTICE: translated PRIu32 = 4294966062
+NOTICE: translated PRIuMAX = 123456789012
+NOTICE: translated PRIuPTR = 9999
+NOTICE: translated PRIx64 = 62c6d1a9b2
+NOTICE: translated PRIx32 = fffffb2e
+NOTICE: translated PRIxMAX = 1cbe991a14
+NOTICE: translated PRIxPTR = 270f
+NOTICE: translated PRIX64 = 62C6D1A9B2
+NOTICE: translated PRIX32 = FFFFFB2E
+NOTICE: translated PRIXMAX = 1CBE991A14
+NOTICE: translated PRIXPTR = 270F
test_translation
------------------
raise log 'NLS regression test: lc_messages = %',
current_setting('lc_messages');
end $$;
-SELECT current_setting('lc_messages') = 'C' AS failed \gset
-\if :failed
-\echo Could not find an acceptable spelling of es_ES locale
-Could not find an acceptable spelling of es_ES locale
-\quit
+SELECT test_translation();
+NOTICE: lc_messages is 'C'
+NOTICE: translated PRId64 = 424242424242
+NOTICE: translated PRId32 = -1234
+NOTICE: translated PRIdMAX = -123456789012
+NOTICE: translated PRIdPTR = -9999
+NOTICE: translated PRIu64 = 424242424242
+NOTICE: translated PRIu32 = 4294966062
+NOTICE: translated PRIuMAX = 123456789012
+NOTICE: translated PRIuPTR = 9999
+NOTICE: translated PRIx64 = 62c6d1a9b2
+NOTICE: translated PRIx32 = fffffb2e
+NOTICE: translated PRIxMAX = 1cbe991a14
+NOTICE: translated PRIxPTR = 270f
+NOTICE: translated PRIX64 = 62C6D1A9B2
+NOTICE: translated PRIX32 = FFFFFB2E
+NOTICE: translated PRIXMAX = 1CBE991A14
+NOTICE: translated PRIXPTR = 270F
+ test_translation
+------------------
+
+(1 row)
+
+RESET lc_messages;
/*
* Simple test to verify NLS support, particularly that the PRI* macros work.
+ *
+ * A secondary objective is to verify that <inttypes.h>'s values for the
+ * PRI* macros match what our snprintf.c code will do. Therefore, we run
+ * the ereport() calls even when we know that translation will not happen.
*/
PG_FUNCTION_INFO_V1(test_translation);
Datum
inited = true;
}
+ /*
+ * If nls.sql failed to select a non-C locale, no translation will happen.
+ * Report that so that we can distinguish this outcome from brokenness.
+ * (We do this here, not in nls.sql, so as to need only 3 expected files.)
+ */
+ if (strcmp(GetConfigOption("lc_messages", false, false), "C") == 0)
+ elog(NOTICE, "lc_messages is 'C'");
+#else
+ elog(NOTICE, "NLS is not enabled");
+#endif
+
ereport(NOTICE,
errmsg("translated PRId64 = %" PRId64, (int64) 424242424242));
ereport(NOTICE,
errmsg("translated PRId32 = %" PRId32, (int32) -1234));
ereport(NOTICE,
- errmsg("translated PRIdMAX = %" PRIdMAX, (intmax_t) -5678));
+ errmsg("translated PRIdMAX = %" PRIdMAX, (intmax_t) -123456789012));
ereport(NOTICE,
- errmsg("translated PRIdPTR = %" PRIdPTR, (intptr_t) 9999));
+ errmsg("translated PRIdPTR = %" PRIdPTR, (intptr_t) -9999));
ereport(NOTICE,
errmsg("translated PRIu64 = %" PRIu64, (uint64) 424242424242));
ereport(NOTICE,
- errmsg("translated PRIu32 = %" PRIu32, (uint32) 1234));
+ errmsg("translated PRIu32 = %" PRIu32, (uint32) -1234));
ereport(NOTICE,
- errmsg("translated PRIuMAX = %" PRIuMAX, (uintmax_t) 5678));
+ errmsg("translated PRIuMAX = %" PRIuMAX, (uintmax_t) 123456789012));
ereport(NOTICE,
errmsg("translated PRIuPTR = %" PRIuPTR, (uintptr_t) 9999));
ereport(NOTICE,
errmsg("translated PRIx64 = %" PRIx64, (uint64) 424242424242));
ereport(NOTICE,
- errmsg("translated PRIx32 = %" PRIx32, (uint32) 1234));
+ errmsg("translated PRIx32 = %" PRIx32, (uint32) -1234));
ereport(NOTICE,
- errmsg("translated PRIxMAX = %" PRIxMAX, (uintmax_t) 5678));
+ errmsg("translated PRIxMAX = %" PRIxMAX, (uintmax_t) 123456789012));
ereport(NOTICE,
errmsg("translated PRIxPTR = %" PRIxPTR, (uintptr_t) 9999));
ereport(NOTICE,
errmsg("translated PRIX64 = %" PRIX64, (uint64) 424242424242));
ereport(NOTICE,
- errmsg("translated PRIX32 = %" PRIX32, (uint32) 1234));
+ errmsg("translated PRIX32 = %" PRIX32, (uint32) -1234));
ereport(NOTICE,
- errmsg("translated PRIXMAX = %" PRIXMAX, (uintmax_t) 5678));
+ errmsg("translated PRIXMAX = %" PRIXMAX, (uintmax_t) 123456789012));
ereport(NOTICE,
errmsg("translated PRIXPTR = %" PRIXPTR, (uintptr_t) 9999));
-#else
- elog(NOTICE, "NLS is not enabled");
-#endif
PG_RETURN_VOID();
}
current_setting('lc_messages');
end $$;
-SELECT current_setting('lc_messages') = 'C' AS failed \gset
-\if :failed
-\echo Could not find an acceptable spelling of es_ES locale
-\quit
-\endif
-
SELECT test_translation();
RESET lc_messages;