Skip to content

Commit 462e247

Browse files
committed
Test PRI* macros even when we can't test NLS translation.
Further research shows that the reason commit 7db6809 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 f8715ec 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
1 parent bfe5c4b commit 462e247

File tree

5 files changed

+71
-40
lines changed

5 files changed

+71
-40
lines changed

src/test/regress/expected/nls.out

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -28,27 +28,22 @@ begin
2828
raise log 'NLS regression test: lc_messages = %',
2929
current_setting('lc_messages');
3030
end $$;
31-
SELECT current_setting('lc_messages') = 'C' AS failed \gset
32-
\if :failed
33-
\echo Could not find an acceptable spelling of es_ES locale
34-
\quit
35-
\endif
3631
SELECT test_translation();
3732
NOTICE: traducido PRId64 = 424242424242
3833
NOTICE: traducido PRId32 = -1234
39-
NOTICE: traducido PRIdMAX = -5678
40-
NOTICE: traducido PRIdPTR = 9999
34+
NOTICE: traducido PRIdMAX = -123456789012
35+
NOTICE: traducido PRIdPTR = -9999
4136
NOTICE: traducido PRIu64 = 424242424242
42-
NOTICE: traducido PRIu32 = 1234
43-
NOTICE: traducido PRIuMAX = 5678
37+
NOTICE: traducido PRIu32 = 4294966062
38+
NOTICE: traducido PRIuMAX = 123456789012
4439
NOTICE: traducido PRIuPTR = 9999
4540
NOTICE: traducido PRIx64 = 62c6d1a9b2
46-
NOTICE: traducido PRIx32 = 4d2
47-
NOTICE: traducido PRIxMAX = 162e
41+
NOTICE: traducido PRIx32 = fffffb2e
42+
NOTICE: traducido PRIxMAX = 1cbe991a14
4843
NOTICE: traducido PRIxPTR = 270f
4944
NOTICE: traducido PRIX64 = 62C6D1A9B2
50-
NOTICE: traducido PRIX32 = 4D2
51-
NOTICE: traducido PRIXMAX = 162E
45+
NOTICE: traducido PRIX32 = FFFFFB2E
46+
NOTICE: traducido PRIXMAX = 1CBE991A14
5247
NOTICE: traducido PRIXPTR = 270F
5348
test_translation
5449
------------------

src/test/regress/expected/nls_1.out

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,24 @@ begin
2828
raise log 'NLS regression test: lc_messages = %',
2929
current_setting('lc_messages');
3030
end $$;
31-
SELECT current_setting('lc_messages') = 'C' AS failed \gset
32-
\if :failed
33-
\echo Could not find an acceptable spelling of es_ES locale
34-
\quit
35-
\endif
3631
SELECT test_translation();
3732
NOTICE: NLS is not enabled
33+
NOTICE: translated PRId64 = 424242424242
34+
NOTICE: translated PRId32 = -1234
35+
NOTICE: translated PRIdMAX = -123456789012
36+
NOTICE: translated PRIdPTR = -9999
37+
NOTICE: translated PRIu64 = 424242424242
38+
NOTICE: translated PRIu32 = 4294966062
39+
NOTICE: translated PRIuMAX = 123456789012
40+
NOTICE: translated PRIuPTR = 9999
41+
NOTICE: translated PRIx64 = 62c6d1a9b2
42+
NOTICE: translated PRIx32 = fffffb2e
43+
NOTICE: translated PRIxMAX = 1cbe991a14
44+
NOTICE: translated PRIxPTR = 270f
45+
NOTICE: translated PRIX64 = 62C6D1A9B2
46+
NOTICE: translated PRIX32 = FFFFFB2E
47+
NOTICE: translated PRIXMAX = 1CBE991A14
48+
NOTICE: translated PRIXPTR = 270F
3849
test_translation
3950
------------------
4051

src/test/regress/expected/nls_2.out

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,27 @@ begin
2828
raise log 'NLS regression test: lc_messages = %',
2929
current_setting('lc_messages');
3030
end $$;
31-
SELECT current_setting('lc_messages') = 'C' AS failed \gset
32-
\if :failed
33-
\echo Could not find an acceptable spelling of es_ES locale
34-
Could not find an acceptable spelling of es_ES locale
35-
\quit
31+
SELECT test_translation();
32+
NOTICE: lc_messages is 'C'
33+
NOTICE: translated PRId64 = 424242424242
34+
NOTICE: translated PRId32 = -1234
35+
NOTICE: translated PRIdMAX = -123456789012
36+
NOTICE: translated PRIdPTR = -9999
37+
NOTICE: translated PRIu64 = 424242424242
38+
NOTICE: translated PRIu32 = 4294966062
39+
NOTICE: translated PRIuMAX = 123456789012
40+
NOTICE: translated PRIuPTR = 9999
41+
NOTICE: translated PRIx64 = 62c6d1a9b2
42+
NOTICE: translated PRIx32 = fffffb2e
43+
NOTICE: translated PRIxMAX = 1cbe991a14
44+
NOTICE: translated PRIxPTR = 270f
45+
NOTICE: translated PRIX64 = 62C6D1A9B2
46+
NOTICE: translated PRIX32 = FFFFFB2E
47+
NOTICE: translated PRIXMAX = 1CBE991A14
48+
NOTICE: translated PRIXPTR = 270F
49+
test_translation
50+
------------------
51+
52+
(1 row)
53+
54+
RESET lc_messages;

src/test/regress/regress.c

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1156,6 +1156,10 @@ test_relpath(PG_FUNCTION_ARGS)
11561156

11571157
/*
11581158
* Simple test to verify NLS support, particularly that the PRI* macros work.
1159+
*
1160+
* A secondary objective is to verify that <inttypes.h>'s values for the
1161+
* PRI* macros match what our snprintf.c code will do. Therefore, we run
1162+
* the ereport() calls even when we know that translation will not happen.
11591163
*/
11601164
PG_FUNCTION_INFO_V1(test_translation);
11611165
Datum
@@ -1185,44 +1189,52 @@ test_translation(PG_FUNCTION_ARGS)
11851189
inited = true;
11861190
}
11871191

1192+
/*
1193+
* If nls.sql failed to select a non-C locale, no translation will happen.
1194+
* Report that so that we can distinguish this outcome from brokenness.
1195+
* (We do this here, not in nls.sql, so as to need only 3 expected files.)
1196+
*/
1197+
if (strcmp(GetConfigOption("lc_messages", false, false), "C") == 0)
1198+
elog(NOTICE, "lc_messages is 'C'");
1199+
#else
1200+
elog(NOTICE, "NLS is not enabled");
1201+
#endif
1202+
11881203
ereport(NOTICE,
11891204
errmsg("translated PRId64 = %" PRId64, (int64) 424242424242));
11901205
ereport(NOTICE,
11911206
errmsg("translated PRId32 = %" PRId32, (int32) -1234));
11921207
ereport(NOTICE,
1193-
errmsg("translated PRIdMAX = %" PRIdMAX, (intmax_t) -5678));
1208+
errmsg("translated PRIdMAX = %" PRIdMAX, (intmax_t) -123456789012));
11941209
ereport(NOTICE,
1195-
errmsg("translated PRIdPTR = %" PRIdPTR, (intptr_t) 9999));
1210+
errmsg("translated PRIdPTR = %" PRIdPTR, (intptr_t) -9999));
11961211

11971212
ereport(NOTICE,
11981213
errmsg("translated PRIu64 = %" PRIu64, (uint64) 424242424242));
11991214
ereport(NOTICE,
1200-
errmsg("translated PRIu32 = %" PRIu32, (uint32) 1234));
1215+
errmsg("translated PRIu32 = %" PRIu32, (uint32) -1234));
12011216
ereport(NOTICE,
1202-
errmsg("translated PRIuMAX = %" PRIuMAX, (uintmax_t) 5678));
1217+
errmsg("translated PRIuMAX = %" PRIuMAX, (uintmax_t) 123456789012));
12031218
ereport(NOTICE,
12041219
errmsg("translated PRIuPTR = %" PRIuPTR, (uintptr_t) 9999));
12051220

12061221
ereport(NOTICE,
12071222
errmsg("translated PRIx64 = %" PRIx64, (uint64) 424242424242));
12081223
ereport(NOTICE,
1209-
errmsg("translated PRIx32 = %" PRIx32, (uint32) 1234));
1224+
errmsg("translated PRIx32 = %" PRIx32, (uint32) -1234));
12101225
ereport(NOTICE,
1211-
errmsg("translated PRIxMAX = %" PRIxMAX, (uintmax_t) 5678));
1226+
errmsg("translated PRIxMAX = %" PRIxMAX, (uintmax_t) 123456789012));
12121227
ereport(NOTICE,
12131228
errmsg("translated PRIxPTR = %" PRIxPTR, (uintptr_t) 9999));
12141229

12151230
ereport(NOTICE,
12161231
errmsg("translated PRIX64 = %" PRIX64, (uint64) 424242424242));
12171232
ereport(NOTICE,
1218-
errmsg("translated PRIX32 = %" PRIX32, (uint32) 1234));
1233+
errmsg("translated PRIX32 = %" PRIX32, (uint32) -1234));
12191234
ereport(NOTICE,
1220-
errmsg("translated PRIXMAX = %" PRIXMAX, (uintmax_t) 5678));
1235+
errmsg("translated PRIXMAX = %" PRIXMAX, (uintmax_t) 123456789012));
12211236
ereport(NOTICE,
12221237
errmsg("translated PRIXPTR = %" PRIXPTR, (uintptr_t) 9999));
1223-
#else
1224-
elog(NOTICE, "NLS is not enabled");
1225-
#endif
12261238

12271239
PG_RETURN_VOID();
12281240
}

src/test/regress/sql/nls.sql

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,6 @@ begin
3333
current_setting('lc_messages');
3434
end $$;
3535

36-
SELECT current_setting('lc_messages') = 'C' AS failed \gset
37-
\if :failed
38-
\echo Could not find an acceptable spelling of es_ES locale
39-
\quit
40-
\endif
41-
4236
SELECT test_translation();
4337

4438
RESET lc_messages;

0 commit comments

Comments
 (0)