From 13de608315d495882d208012c9c55bae91dc75e6 Mon Sep 17 00:00:00 2001 From: Peter Eisentraut 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 @@ Extra Tests make check EXTRA_TESTS=numeric_big - To run the collation tests: - -make check EXTRA_TESTS='collate.linux.utf8 collate.icu.utf8' LANG=en_US.utf8 - - The collate.linux.utf8 test works only on Linux/glibc - platforms. The collate.icu.utf8 test only works when - support for ICU was built. Both tests will only succeed when run in a - database that uses UTF-8 encoding. 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