how to run encoding-dependent tests by default
There is a fair amount of collation-related functionality that is only
being tested by sql/collate.icu.utf8.sql and sql/collate.linux.utf8.sql,
which are not run by default. There is more functionality planned in
this area, so making the testing more straightforward would be useful.
The reason these tests cannot be run by default (other than that they
don't apply to each build, which is easy to figure out) is that
a) They contain UTF8 non-ASCII characters that might not convert to
every server-side encoding, and
b) The error messages mention the encoding name ('ERROR: collation
"foo" for encoding "UTF8" does not exist')
The server encoding can be set more-or-less arbitrarily for each test
run, and moreover it is computed from the locale, so it's not easy to
determine ahead of time from a makefile, say.
What would be a good way to sort this out? None of these problems are
terribly difficult on their own, but I'm struggling to come up with a
coherent solution.
--
Peter Eisentraut http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services
Peter Eisentraut <peter.eisentraut@2ndquadrant.com> writes:
There is a fair amount of collation-related functionality that is only
being tested by sql/collate.icu.utf8.sql and sql/collate.linux.utf8.sql,
which are not run by default. There is more functionality planned in
this area, so making the testing more straightforward would be useful.
The reason these tests cannot be run by default (other than that they
don't apply to each build, which is easy to figure out) is that
a) They contain UTF8 non-ASCII characters that might not convert to
every server-side encoding, and
b) The error messages mention the encoding name ('ERROR: collation
"foo" for encoding "UTF8" does not exist')
The server encoding can be set more-or-less arbitrarily for each test
run, and moreover it is computed from the locale, so it's not easy to
determine ahead of time from a makefile, say.
What would be a good way to sort this out? None of these problems are
terribly difficult on their own, but I'm struggling to come up with a
coherent solution.
Perhaps set up a separate test run (not part of the core tests) in which
the database is forced to have UTF8 encoding? That could be expanded
to other encodings too if anyone cares.
regards, tom lane
On 6/17/19 11:32 AM, Tom Lane wrote:
Peter Eisentraut <peter.eisentraut@2ndquadrant.com> writes:
There is a fair amount of collation-related functionality that is only
being tested by sql/collate.icu.utf8.sql and sql/collate.linux.utf8.sql,
which are not run by default. There is more functionality planned in
this area, so making the testing more straightforward would be useful.
The reason these tests cannot be run by default (other than that they
don't apply to each build, which is easy to figure out) is that
a) They contain UTF8 non-ASCII characters that might not convert to
every server-side encoding, and
b) The error messages mention the encoding name ('ERROR: collation
"foo" for encoding "UTF8" does not exist')
The server encoding can be set more-or-less arbitrarily for each test
run, and moreover it is computed from the locale, so it's not easy to
determine ahead of time from a makefile, say.
What would be a good way to sort this out? None of these problems are
terribly difficult on their own, but I'm struggling to come up with a
coherent solution.Perhaps set up a separate test run (not part of the core tests) in which
the database is forced to have UTF8 encoding? That could be expanded
to other encodings too if anyone cares.
I should point out that the buildfarm does run these tests for every
utf8 locale it's configured for if the TestICU module is enabled. At the
moment the only animal actually running those tests is prion, for
en_US.utf8.
cheers
andrew
--
Andrew Dunstan https://www.2ndQuadrant.com
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services
Hi,
On 2019-06-17 16:56:00 +0200, Peter Eisentraut wrote:
There is a fair amount of collation-related functionality that is only
being tested by sql/collate.icu.utf8.sql and sql/collate.linux.utf8.sql,
which are not run by default. There is more functionality planned in
this area, so making the testing more straightforward would be useful.The reason these tests cannot be run by default (other than that they
don't apply to each build, which is easy to figure out) is thata) They contain UTF8 non-ASCII characters that might not convert to
every server-side encoding, andb) The error messages mention the encoding name ('ERROR: collation
"foo" for encoding "UTF8" does not exist')The server encoding can be set more-or-less arbitrarily for each test
run, and moreover it is computed from the locale, so it's not easy to
determine ahead of time from a makefile, say.What would be a good way to sort this out? None of these problems are
terribly difficult on their own, but I'm struggling to come up with a
coherent solution.
I wonder if using alternative output files and psql's \if could be good
enough here. It's not that hard to maintain an alternative output file
if it's nearly empty.
Basically something like:
\gset SELECT my_encodings_are_compatible() AS compatible
\if :compatible
test;
contents;
\endif
That won't get rid of b) in its entirety, but even just running the test
automatically on platforms it works without problems would be an
improvement.
We probably also could just have a wrapper function in those tests that
catch the exception and print a more anodyne message.
Greetings,
Andres Freund
On 2019-06-17 18:39, Andres Freund wrote:
Basically something like:
\gset SELECT my_encodings_are_compatible() AS compatible
\if :compatible
test;
contents;
\endif
Cool, that works out quite well. See attached patch. I flipped the
logic around to make it \quit if not compatible. That way the
alternative expected file is shorter and doesn't need to be updated all
the time. But it gets the job done either way.
--
Peter Eisentraut http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services
Attachments:
0001-Run-UTF8-requiring-collation-tests-by-default.patchtext/plain; charset=UTF-8; name=0001-Run-UTF8-requiring-collation-tests-by-default.patch; x-mac-creator=0; x-mac-type=0Download
From 1fd55c0a64b11ea23ab0c3791e21c21879a1b1de Mon Sep 17 00:00:00 2001
From: Peter Eisentraut <peter@eisentraut.org>
Date: Sun, 23 Jun 2019 21:40:53 +0200
Subject: [PATCH] Run UTF8-requiring collation tests by default
The tests collate.icu.utf8 and collate.linux.utf8 were previously only
run when explicitly selected via EXTRA_TESTS. They require a UTF8
database, because the error messages in the expected files refer to
that, and they use some non-ASCII characters in the tests. Since
users can select any locale and encoding for the regression test run,
it was not possible to include these tests automatically.
To fix, use psql's \if facility to check the server encoding and quit
the tests at the very beginning if a server encoding other than UTF8
is set. We then need to maintain alternative expected files for these
tests, but they are very tiny and never need to change after this.
These two tests are now run automatically as part of the regression
tests, given an appropriate build environment (Linux or ICU enabled,
respectively).
Discussion: https://www.postgresql.org/message-id/flat/052295c2-a2e1-9a21-bd36-8fbff8686cf3%402ndquadrant.com
---
doc/src/sgml/regress.sgml | 8 --------
src/test/regress/GNUmakefile | 8 ++++++++
src/test/regress/expected/collate.icu.utf8.out | 5 +++++
src/test/regress/expected/collate.icu.utf8_1.out | 7 +++++++
src/test/regress/expected/collate.linux.utf8.out | 4 ++++
src/test/regress/expected/collate.linux.utf8_1.out | 8 ++++++++
src/test/regress/sql/collate.icu.utf8.sql | 6 ++++++
src/test/regress/sql/collate.linux.utf8.sql | 5 +++++
8 files changed, 43 insertions(+), 8 deletions(-)
create mode 100644 src/test/regress/expected/collate.icu.utf8_1.out
create mode 100644 src/test/regress/expected/collate.linux.utf8_1.out
diff --git a/doc/src/sgml/regress.sgml b/doc/src/sgml/regress.sgml
index 448e2d19f7..101dc659e4 100644
--- a/doc/src/sgml/regress.sgml
+++ b/doc/src/sgml/regress.sgml
@@ -316,14 +316,6 @@ <title>Extra Tests</title>
<screen>
make check EXTRA_TESTS=numeric_big
</screen>
- To run the collation tests:
-<screen>
-make check EXTRA_TESTS='collate.linux.utf8 collate.icu.utf8' LANG=en_US.utf8
-</screen>
- The <literal>collate.linux.utf8</literal> test works only on Linux/glibc
- platforms. The <literal>collate.icu.utf8</literal> test only works when
- support for ICU was built. Both tests will only succeed when run in a
- database that uses UTF-8 encoding.
</para>
</sect2>
diff --git a/src/test/regress/GNUmakefile b/src/test/regress/GNUmakefile
index a24cfd4e01..80d515003c 100644
--- a/src/test/regress/GNUmakefile
+++ b/src/test/regress/GNUmakefile
@@ -128,6 +128,14 @@ tablespace-setup:
REGRESS_OPTS = --dlpath=. --max-concurrent-tests=20 $(EXTRA_REGRESS_OPTS)
+ifeq ($(PORTNAME),linux)
+EXTRA_TESTS += collate.linux.utf8
+endif
+
+ifeq ($(with_icu),yes)
+EXTRA_TESTS += collate.icu.utf8
+endif
+
check: all tablespace-setup
$(pg_regress_check) $(REGRESS_OPTS) --schedule=$(srcdir)/parallel_schedule $(MAXCONNOPT) $(EXTRA_TESTS)
diff --git a/src/test/regress/expected/collate.icu.utf8.out b/src/test/regress/expected/collate.icu.utf8.out
index 01bd9fb5dd..2a927771a2 100644
--- a/src/test/regress/expected/collate.icu.utf8.out
+++ b/src/test/regress/expected/collate.icu.utf8.out
@@ -1,6 +1,11 @@
/*
* This test is for ICU collations.
*/
+/* skip test if not UTF8 server encoding */
+select getdatabaseencoding() <> 'UTF8' AS server_encoding_incompatible \gset
+\if :server_encoding_incompatible
+\quit
+\endif
SET client_encoding TO UTF8;
CREATE SCHEMA collate_tests;
SET search_path = collate_tests;
diff --git a/src/test/regress/expected/collate.icu.utf8_1.out b/src/test/regress/expected/collate.icu.utf8_1.out
new file mode 100644
index 0000000000..a622b35fb4
--- /dev/null
+++ b/src/test/regress/expected/collate.icu.utf8_1.out
@@ -0,0 +1,7 @@
+/*
+ * This test is for ICU collations.
+ */
+/* skip test if not UTF8 server encoding */
+select getdatabaseencoding() <> 'UTF8' AS server_encoding_incompatible \gset
+\if :server_encoding_incompatible
+\quit
diff --git a/src/test/regress/expected/collate.linux.utf8.out b/src/test/regress/expected/collate.linux.utf8.out
index 619688f851..000d883e70 100644
--- a/src/test/regress/expected/collate.linux.utf8.out
+++ b/src/test/regress/expected/collate.linux.utf8.out
@@ -3,6 +3,10 @@
* locales is installed. It must be run in a database with UTF-8 encoding,
* because other encodings don't support all the characters used.
*/
+select getdatabaseencoding() <> 'UTF8' AS server_encoding_incompatible \gset
+\if :server_encoding_incompatible
+\quit
+\endif
SET client_encoding TO UTF8;
CREATE SCHEMA collate_tests;
SET search_path = collate_tests;
diff --git a/src/test/regress/expected/collate.linux.utf8_1.out b/src/test/regress/expected/collate.linux.utf8_1.out
new file mode 100644
index 0000000000..c613c88d4d
--- /dev/null
+++ b/src/test/regress/expected/collate.linux.utf8_1.out
@@ -0,0 +1,8 @@
+/*
+ * This test is for Linux/glibc systems and assumes that a full set of
+ * locales is installed. It must be run in a database with UTF-8 encoding,
+ * because other encodings don't support all the characters used.
+ */
+select getdatabaseencoding() <> 'UTF8' AS server_encoding_incompatible \gset
+\if :server_encoding_incompatible
+\quit
diff --git a/src/test/regress/sql/collate.icu.utf8.sql b/src/test/regress/sql/collate.icu.utf8.sql
index 2be7759c92..ecbc549006 100644
--- a/src/test/regress/sql/collate.icu.utf8.sql
+++ b/src/test/regress/sql/collate.icu.utf8.sql
@@ -2,6 +2,12 @@
* This test is for ICU collations.
*/
+/* skip test if not UTF8 server encoding */
+select getdatabaseencoding() <> 'UTF8' AS server_encoding_incompatible \gset
+\if :server_encoding_incompatible
+\quit
+\endif
+
SET client_encoding TO UTF8;
CREATE SCHEMA collate_tests;
diff --git a/src/test/regress/sql/collate.linux.utf8.sql b/src/test/regress/sql/collate.linux.utf8.sql
index c009fd2372..13ef659fd6 100644
--- a/src/test/regress/sql/collate.linux.utf8.sql
+++ b/src/test/regress/sql/collate.linux.utf8.sql
@@ -4,6 +4,11 @@
* because other encodings don't support all the characters used.
*/
+select getdatabaseencoding() <> 'UTF8' AS server_encoding_incompatible \gset
+\if :server_encoding_incompatible
+\quit
+\endif
+
SET client_encoding TO UTF8;
CREATE SCHEMA collate_tests;
--
2.22.0
On 2019-06-23 21:44, Peter Eisentraut wrote:
On 2019-06-17 18:39, Andres Freund wrote:
Basically something like:
\gset SELECT my_encodings_are_compatible() AS compatible
\if :compatible
test;
contents;
\endifCool, that works out quite well. See attached patch. I flipped the
logic around to make it \quit if not compatible. That way the
alternative expected file is shorter and doesn't need to be updated all
the time. But it gets the job done either way.
Small patch update: The collate.linux.utf8 test also needs to check in a
similar manner that all the locales it is using are installed. This
should get the cfbot run passing.
--
Peter Eisentraut http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services
Attachments:
v2-0001-Run-UTF8-requiring-collation-tests-by-default.patchtext/plain; charset=UTF-8; name=v2-0001-Run-UTF8-requiring-collation-tests-by-default.patch; x-mac-creator=0; x-mac-type=0Download
From 13de608315d495882d208012c9c55bae91dc75e6 Mon Sep 17 00:00:00 2001
From: Peter Eisentraut <peter@eisentraut.org>
Date: Fri, 5 Jul 2019 11:30:11 +0000
Subject: [PATCH v2] Run UTF8-requiring collation tests by default
The tests collate.icu.utf8 and collate.linux.utf8 were previously only
run when explicitly selected via EXTRA_TESTS. They require a UTF8
database, because the error messages in the expected files refer to
that, and they use some non-ASCII characters in the tests. Since
users can select any locale and encoding for the regression test run,
it was not possible to include these tests automatically.
To fix, use psql's \if facility to check the server encoding and quit
the tests at the very beginning if a server encoding other than UTF8
is set. We then need to maintain alternative expected files for these
tests, but they are very tiny and never need to change after this.
These two tests are now run automatically as part of the regression
tests, given an appropriate build environment (Linux or ICU enabled,
respectively).
Discussion: https://www.postgresql.org/message-id/flat/052295c2-a2e1-9a21-bd36-8fbff8686cf3%402ndquadrant.com
---
doc/src/sgml/regress.sgml | 8 --------
src/test/regress/GNUmakefile | 8 ++++++++
src/test/regress/expected/collate.icu.utf8.out | 5 +++++
src/test/regress/expected/collate.icu.utf8_1.out | 7 +++++++
src/test/regress/expected/collate.linux.utf8.out | 6 ++++++
src/test/regress/expected/collate.linux.utf8_1.out | 10 ++++++++++
src/test/regress/sql/collate.icu.utf8.sql | 6 ++++++
src/test/regress/sql/collate.linux.utf8.sql | 7 +++++++
8 files changed, 49 insertions(+), 8 deletions(-)
create mode 100644 src/test/regress/expected/collate.icu.utf8_1.out
create mode 100644 src/test/regress/expected/collate.linux.utf8_1.out
diff --git a/doc/src/sgml/regress.sgml b/doc/src/sgml/regress.sgml
index 7b68213266..d98187c970 100644
--- a/doc/src/sgml/regress.sgml
+++ b/doc/src/sgml/regress.sgml
@@ -363,14 +363,6 @@ <title>Extra Tests</title>
<screen>
make check EXTRA_TESTS=numeric_big
</screen>
- To run the collation tests:
-<screen>
-make check EXTRA_TESTS='collate.linux.utf8 collate.icu.utf8' LANG=en_US.utf8
-</screen>
- The <literal>collate.linux.utf8</literal> test works only on Linux/glibc
- platforms. The <literal>collate.icu.utf8</literal> test only works when
- support for ICU was built. Both tests will only succeed when run in a
- database that uses UTF-8 encoding.
</para>
</sect2>
diff --git a/src/test/regress/GNUmakefile b/src/test/regress/GNUmakefile
index a24cfd4e01..80d515003c 100644
--- a/src/test/regress/GNUmakefile
+++ b/src/test/regress/GNUmakefile
@@ -128,6 +128,14 @@ tablespace-setup:
REGRESS_OPTS = --dlpath=. --max-concurrent-tests=20 $(EXTRA_REGRESS_OPTS)
+ifeq ($(PORTNAME),linux)
+EXTRA_TESTS += collate.linux.utf8
+endif
+
+ifeq ($(with_icu),yes)
+EXTRA_TESTS += collate.icu.utf8
+endif
+
check: all tablespace-setup
$(pg_regress_check) $(REGRESS_OPTS) --schedule=$(srcdir)/parallel_schedule $(MAXCONNOPT) $(EXTRA_TESTS)
diff --git a/src/test/regress/expected/collate.icu.utf8.out b/src/test/regress/expected/collate.icu.utf8.out
index 01bd9fb5dd..addbc20f6f 100644
--- a/src/test/regress/expected/collate.icu.utf8.out
+++ b/src/test/regress/expected/collate.icu.utf8.out
@@ -1,6 +1,11 @@
/*
* This test is for ICU collations.
*/
+/* skip test if not UTF8 server encoding */
+SELECT getdatabaseencoding() <> 'UTF8' AS server_encoding_incompatible \gset
+\if :server_encoding_incompatible
+\quit
+\endif
SET client_encoding TO UTF8;
CREATE SCHEMA collate_tests;
SET search_path = collate_tests;
diff --git a/src/test/regress/expected/collate.icu.utf8_1.out b/src/test/regress/expected/collate.icu.utf8_1.out
new file mode 100644
index 0000000000..2afd90f34f
--- /dev/null
+++ b/src/test/regress/expected/collate.icu.utf8_1.out
@@ -0,0 +1,7 @@
+/*
+ * This test is for ICU collations.
+ */
+/* skip test if not UTF8 server encoding */
+SELECT getdatabaseencoding() <> 'UTF8' AS server_encoding_incompatible \gset
+\if :server_encoding_incompatible
+\quit
diff --git a/src/test/regress/expected/collate.linux.utf8.out b/src/test/regress/expected/collate.linux.utf8.out
index 619688f851..0cb7bb1386 100644
--- a/src/test/regress/expected/collate.linux.utf8.out
+++ b/src/test/regress/expected/collate.linux.utf8.out
@@ -3,6 +3,12 @@
* locales is installed. It must be run in a database with UTF-8 encoding,
* because other encodings don't support all the characters used.
*/
+SELECT getdatabaseencoding() <> 'UTF8' OR
+ (SELECT count(*) FROM pg_collation WHERE collname IN ('de_DE', 'en_US', 'sv_SE', 'tr_TR') AND collencoding = pg_char_to_encoding('UTF8')) <> 4
+ AS server_encoding_incompatible_or_locales_missing \gset
+\if :server_encoding_incompatible_or_locales_missing
+\quit
+\endif
SET client_encoding TO UTF8;
CREATE SCHEMA collate_tests;
SET search_path = collate_tests;
diff --git a/src/test/regress/expected/collate.linux.utf8_1.out b/src/test/regress/expected/collate.linux.utf8_1.out
new file mode 100644
index 0000000000..54f6ac969c
--- /dev/null
+++ b/src/test/regress/expected/collate.linux.utf8_1.out
@@ -0,0 +1,10 @@
+/*
+ * This test is for Linux/glibc systems and assumes that a full set of
+ * locales is installed. It must be run in a database with UTF-8 encoding,
+ * because other encodings don't support all the characters used.
+ */
+SELECT getdatabaseencoding() <> 'UTF8' OR
+ (SELECT count(*) FROM pg_collation WHERE collname IN ('de_DE', 'en_US', 'sv_SE', 'tr_TR') AND collencoding = pg_char_to_encoding('UTF8')) <> 4
+ AS server_encoding_incompatible_or_locales_missing \gset
+\if :server_encoding_incompatible_or_locales_missing
+\quit
diff --git a/src/test/regress/sql/collate.icu.utf8.sql b/src/test/regress/sql/collate.icu.utf8.sql
index 2be7759c92..d8a5deae18 100644
--- a/src/test/regress/sql/collate.icu.utf8.sql
+++ b/src/test/regress/sql/collate.icu.utf8.sql
@@ -2,6 +2,12 @@
* This test is for ICU collations.
*/
+/* skip test if not UTF8 server encoding */
+SELECT getdatabaseencoding() <> 'UTF8' AS server_encoding_incompatible \gset
+\if :server_encoding_incompatible
+\quit
+\endif
+
SET client_encoding TO UTF8;
CREATE SCHEMA collate_tests;
diff --git a/src/test/regress/sql/collate.linux.utf8.sql b/src/test/regress/sql/collate.linux.utf8.sql
index c009fd2372..73e36fea42 100644
--- a/src/test/regress/sql/collate.linux.utf8.sql
+++ b/src/test/regress/sql/collate.linux.utf8.sql
@@ -4,6 +4,13 @@
* because other encodings don't support all the characters used.
*/
+SELECT getdatabaseencoding() <> 'UTF8' OR
+ (SELECT count(*) FROM pg_collation WHERE collname IN ('de_DE', 'en_US', 'sv_SE', 'tr_TR') AND collencoding = pg_char_to_encoding('UTF8')) <> 4
+ AS server_encoding_incompatible_or_locales_missing \gset
+\if :server_encoding_incompatible_or_locales_missing
+\quit
+\endif
+
SET client_encoding TO UTF8;
CREATE SCHEMA collate_tests;
--
2.11.0
Peter Eisentraut <peter.eisentraut@2ndquadrant.com> writes:
Cool, that works out quite well. See attached patch. I flipped the
logic around to make it \quit if not compatible. That way the
alternative expected file is shorter and doesn't need to be updated all
the time. But it gets the job done either way.
I took a look at this and did some light testing. It seems to work
as advertised, but I do have one gripe, which is the dependency on
the EXTRA_TESTS mechanism. There are a few things not to like about
doing it that way:
* need additional hacking for Windows (admittedly, moot for
collate.linux.utf8, but I hope it's not for collate.icu.utf8).
* can't put these tests into a parallel group, they run by themselves;
* if user specifies EXTRA_TESTS on make command line, that overrides
the Makefile so these tests aren't run.
So I wish we could get rid of the Makefile changes, have the test
scripts be completely responsible for whether to run themselves or
not, and put them into the schedule files normally.
It's pretty obvious how we might do this for collate.icu.utf8:
make it look to see if there are any ICU-supplied collations in
pg_collation.
I'm less clear on a reasonable way to detect a glibc platform
from SQL. The best I can think of is to see if the string
"linux" appears in the output of version(), and that's probably
none too robust. Can we do anything based on the content of
pg_collation? Probably not :-(.
Still, even if you only fixed collate.icu.utf8 this way, that
would be a step forward since it would solve the Windows aspect.
regards, tom lane
I wrote:
I'm less clear on a reasonable way to detect a glibc platform
from SQL. The best I can think of is to see if the string
"linux" appears in the output of version(), and that's probably
none too robust. Can we do anything based on the content of
pg_collation? Probably not :-(.
Actually, scraping the buildfarm database suggests that checking
version() for "linux" or even "linux-gnu" would work very well.
regards, tom lane
Attachments:
Oh ... one other thought, based on forcing the collate.linux.utf8
test to run on platforms where it can be expected to fail: I think
you'd be well advised to make that test verify that the required
collations are present, the same as you did in the collate.icu.utf8
test. I noticed for instance that it fails if en_US.utf8 is not
present (or not spelled exactly like that), but I doubt that that
locale is necessarily present on every Linux platform. tr_TR is
even more likely to be subject to packagers' whims.
regards, tom lane
On 2019-07-28 20:12, Tom Lane wrote:
So I wish we could get rid of the Makefile changes, have the test
scripts be completely responsible for whether to run themselves or
not, and put them into the schedule files normally.It's pretty obvious how we might do this for collate.icu.utf8:
make it look to see if there are any ICU-supplied collations in
pg_collation.I'm less clear on a reasonable way to detect a glibc platform
from SQL. The best I can think of is to see if the string
"linux" appears in the output of version(), and that's probably
none too robust. Can we do anything based on the content of
pg_collation? Probably not :-(.Still, even if you only fixed collate.icu.utf8 this way, that
would be a step forward since it would solve the Windows aspect.
Good points. Updated patch attach.
(The two tests create the same schema name, so they cannot be run in
parallel. I opted against changing that here, since it would blow up
the patch and increase the diff between the two tests.)
--
Peter Eisentraut http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services
Attachments:
v3-0001-Run-UTF8-requiring-collation-tests-by-default.patchtext/plain; charset=UTF-8; name=v3-0001-Run-UTF8-requiring-collation-tests-by-default.patch; x-mac-creator=0; x-mac-type=0Download
From 0a4abb39d68406313e373aac82faa101bb62b5dd Mon Sep 17 00:00:00 2001
From: Peter Eisentraut <peter@eisentraut.org>
Date: Mon, 29 Jul 2019 07:10:42 +0200
Subject: [PATCH v3] Run UTF8-requiring collation tests by default
The tests collate.icu.utf8 and collate.linux.utf8 were previously only
run when explicitly selected via EXTRA_TESTS. They require a UTF8
database, because the error messages in the expected files refer to
that, and they use some non-ASCII characters in the tests. Since
users can select any locale and encoding for the regression test run,
it was not possible to include these tests automatically.
To fix, use psql's \if facility to check various prerequisites such as
platform and the server encoding and quit the tests at the very
beginning if the configuration is not adequate. We then need to
maintain alternative expected files for these tests, but they are very
tiny and never need to change after this.
These two tests are now run automatically as part of the regression
tests.
Discussion: https://www.postgresql.org/message-id/flat/052295c2-a2e1-9a21-bd36-8fbff8686cf3%402ndquadrant.com
---
doc/src/sgml/regress.sgml | 8 --------
src/test/regress/expected/collate.icu.utf8.out | 7 +++++++
src/test/regress/expected/collate.icu.utf8_1.out | 9 +++++++++
src/test/regress/expected/collate.linux.utf8.out | 7 +++++++
src/test/regress/expected/collate.linux.utf8_1.out | 11 +++++++++++
src/test/regress/parallel_schedule | 5 +++--
src/test/regress/serial_schedule | 2 ++
src/test/regress/sql/collate.icu.utf8.sql | 8 ++++++++
src/test/regress/sql/collate.linux.utf8.sql | 8 ++++++++
9 files changed, 55 insertions(+), 10 deletions(-)
create mode 100644 src/test/regress/expected/collate.icu.utf8_1.out
create mode 100644 src/test/regress/expected/collate.linux.utf8_1.out
diff --git a/doc/src/sgml/regress.sgml b/doc/src/sgml/regress.sgml
index 7b68213266..d98187c970 100644
--- a/doc/src/sgml/regress.sgml
+++ b/doc/src/sgml/regress.sgml
@@ -363,14 +363,6 @@ <title>Extra Tests</title>
<screen>
make check EXTRA_TESTS=numeric_big
</screen>
- To run the collation tests:
-<screen>
-make check EXTRA_TESTS='collate.linux.utf8 collate.icu.utf8' LANG=en_US.utf8
-</screen>
- The <literal>collate.linux.utf8</literal> test works only on Linux/glibc
- platforms. The <literal>collate.icu.utf8</literal> test only works when
- support for ICU was built. Both tests will only succeed when run in a
- database that uses UTF-8 encoding.
</para>
</sect2>
diff --git a/src/test/regress/expected/collate.icu.utf8.out b/src/test/regress/expected/collate.icu.utf8.out
index 01bd9fb5dd..51262e0bf4 100644
--- a/src/test/regress/expected/collate.icu.utf8.out
+++ b/src/test/regress/expected/collate.icu.utf8.out
@@ -1,6 +1,13 @@
/*
* This test is for ICU collations.
*/
+/* skip test if not UTF8 server encoding or no ICU collations installed */
+SELECT getdatabaseencoding() <> 'UTF8' OR
+ (SELECT count(*) FROM pg_collation WHERE collprovider = 'i') = 0
+ AS skip_test \gset
+\if :skip_test
+\quit
+\endif
SET client_encoding TO UTF8;
CREATE SCHEMA collate_tests;
SET search_path = collate_tests;
diff --git a/src/test/regress/expected/collate.icu.utf8_1.out b/src/test/regress/expected/collate.icu.utf8_1.out
new file mode 100644
index 0000000000..a6a33b39ab
--- /dev/null
+++ b/src/test/regress/expected/collate.icu.utf8_1.out
@@ -0,0 +1,9 @@
+/*
+ * This test is for ICU collations.
+ */
+/* skip test if not UTF8 server encoding or no ICU collations installed */
+SELECT getdatabaseencoding() <> 'UTF8' OR
+ (SELECT count(*) FROM pg_collation WHERE collprovider = 'i') = 0
+ AS skip_test \gset
+\if :skip_test
+\quit
diff --git a/src/test/regress/expected/collate.linux.utf8.out b/src/test/regress/expected/collate.linux.utf8.out
index 619688f851..ad56ff9caa 100644
--- a/src/test/regress/expected/collate.linux.utf8.out
+++ b/src/test/regress/expected/collate.linux.utf8.out
@@ -3,6 +3,13 @@
* locales is installed. It must be run in a database with UTF-8 encoding,
* because other encodings don't support all the characters used.
*/
+SELECT getdatabaseencoding() <> 'UTF8' OR
+ (SELECT count(*) FROM pg_collation WHERE collname IN ('de_DE', 'en_US', 'sv_SE', 'tr_TR') AND collencoding = pg_char_to_encoding('UTF8')) <> 4 OR
+ version() !~ 'linux-gnu'
+ AS skip_test \gset
+\if :skip_test
+\quit
+\endif
SET client_encoding TO UTF8;
CREATE SCHEMA collate_tests;
SET search_path = collate_tests;
diff --git a/src/test/regress/expected/collate.linux.utf8_1.out b/src/test/regress/expected/collate.linux.utf8_1.out
new file mode 100644
index 0000000000..ede5fdb5dc
--- /dev/null
+++ b/src/test/regress/expected/collate.linux.utf8_1.out
@@ -0,0 +1,11 @@
+/*
+ * This test is for Linux/glibc systems and assumes that a full set of
+ * locales is installed. It must be run in a database with UTF-8 encoding,
+ * because other encodings don't support all the characters used.
+ */
+SELECT getdatabaseencoding() <> 'UTF8' OR
+ (SELECT count(*) FROM pg_collation WHERE collname IN ('de_DE', 'en_US', 'sv_SE', 'tr_TR') AND collencoding = pg_char_to_encoding('UTF8')) <> 4 OR
+ version() !~ 'linux-gnu'
+ AS skip_test \gset
+\if :skip_test
+\quit
diff --git a/src/test/regress/parallel_schedule b/src/test/regress/parallel_schedule
index 8fb55f045e..fc0f14122b 100644
--- a/src/test/regress/parallel_schedule
+++ b/src/test/regress/parallel_schedule
@@ -78,11 +78,12 @@ test: brin gin gist spgist privileges init_privs security_label collate matview
# ----------
# Another group of parallel tests
# ----------
-test: create_table_like alter_generic alter_operator misc async dbsize misc_functions sysviews tsrf tidscan
+test: create_table_like alter_generic alter_operator misc async dbsize misc_functions sysviews tsrf tidscan collate.icu.utf8
# rules cannot run concurrently with any test that creates
# a view or rule in the public schema
-test: rules psql psql_crosstab amutils stats_ext
+# collate.*.utf8 tests cannot be run in parallel with each other
+test: rules psql psql_crosstab amutils stats_ext collate.linux.utf8
# run by itself so it can run parallel workers
test: select_parallel
diff --git a/src/test/regress/serial_schedule b/src/test/regress/serial_schedule
index a39ca1012a..05b9f9c2b3 100644
--- a/src/test/regress/serial_schedule
+++ b/src/test/regress/serial_schedule
@@ -133,6 +133,8 @@ test: misc_functions
test: sysviews
test: tsrf
test: tidscan
+test: collate.icu.utf8
+test: collate.linux.utf8
test: rules
test: psql
test: psql_crosstab
diff --git a/src/test/regress/sql/collate.icu.utf8.sql b/src/test/regress/sql/collate.icu.utf8.sql
index 2be7759c92..46999fb926 100644
--- a/src/test/regress/sql/collate.icu.utf8.sql
+++ b/src/test/regress/sql/collate.icu.utf8.sql
@@ -2,6 +2,14 @@
* This test is for ICU collations.
*/
+/* skip test if not UTF8 server encoding or no ICU collations installed */
+SELECT getdatabaseencoding() <> 'UTF8' OR
+ (SELECT count(*) FROM pg_collation WHERE collprovider = 'i') = 0
+ AS skip_test \gset
+\if :skip_test
+\quit
+\endif
+
SET client_encoding TO UTF8;
CREATE SCHEMA collate_tests;
diff --git a/src/test/regress/sql/collate.linux.utf8.sql b/src/test/regress/sql/collate.linux.utf8.sql
index c009fd2372..eac2f90014 100644
--- a/src/test/regress/sql/collate.linux.utf8.sql
+++ b/src/test/regress/sql/collate.linux.utf8.sql
@@ -4,6 +4,14 @@
* because other encodings don't support all the characters used.
*/
+SELECT getdatabaseencoding() <> 'UTF8' OR
+ (SELECT count(*) FROM pg_collation WHERE collname IN ('de_DE', 'en_US', 'sv_SE', 'tr_TR') AND collencoding = pg_char_to_encoding('UTF8')) <> 4 OR
+ version() !~ 'linux-gnu'
+ AS skip_test \gset
+\if :skip_test
+\quit
+\endif
+
SET client_encoding TO UTF8;
CREATE SCHEMA collate_tests;
--
2.22.0
On 2019-07-28 21:42, Tom Lane wrote:
Oh ... one other thought, based on forcing the collate.linux.utf8
test to run on platforms where it can be expected to fail: I think
you'd be well advised to make that test verify that the required
collations are present, the same as you did in the collate.icu.utf8
test. I noticed for instance that it fails if en_US.utf8 is not
present (or not spelled exactly like that), but I doubt that that
locale is necessarily present on every Linux platform. tr_TR is
even more likely to be subject to packagers' whims.
This was already done in my v2 test posted in this thread.
--
Peter Eisentraut http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services
Peter Eisentraut <peter.eisentraut@2ndquadrant.com> writes:
On 2019-07-28 20:12, Tom Lane wrote:
So I wish we could get rid of the Makefile changes, have the test
scripts be completely responsible for whether to run themselves or
not, and put them into the schedule files normally.
Good points. Updated patch attach.
v3 looks good and passes local testing. I've marked it RFC.
(The two tests create the same schema name, so they cannot be run in
parallel. I opted against changing that here, since it would blow up
the patch and increase the diff between the two tests.)
This does create one tiny nit, which is that the order of the
parallel and serial schedule files don't match. Possibly I'm
overly anal-retentive about that, but I think it's confusing
when they don't.
regards, tom lane
On 2019-07-29 16:47, Tom Lane wrote:
(The two tests create the same schema name, so they cannot be run in
parallel. I opted against changing that here, since it would blow up
the patch and increase the diff between the two tests.)This does create one tiny nit, which is that the order of the
parallel and serial schedule files don't match. Possibly I'm
overly anal-retentive about that, but I think it's confusing
when they don't.
Right. Committed with adjustment to keep these consistent.
--
Peter Eisentraut http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services