From 44e73a498c5f3ad7e39dc70821c2d8316d3207f2 Mon Sep 17 00:00:00 2001 From: Michael Paquier Date: Tue, 4 Jul 2023 08:05:00 +0900 Subject: [PATCH] Fix regression tests of unaccent to work without UTF8 support The tests of unaccent rely on UTF8 characters, and unlike any other test suite in the tree (fuzzystrmatch, citext, hstore, etc.), they would fail if run on a database that does not support UTF8 encoding. This commit fixes the tests of unaccent so as these are skipped when run on a database without UTF8 support, using the same method as the other test suits based on \if, getdatabaseencoding() and an alternate output file. This has been broken for a long time, but nobody has complained about that either, so no backpatch is done. This can be reproduced with something like REGRESS_OPTS="--no-locale --encoding=sql_ascii", for instance. To defend against that, this module's Makefile and meson.build enforced a UTF8 encoding without locales, but it did not offer protection for options given by REGRESS_OPTS. This switch makes this regression test suite more consistent with all the others, as well. Reviewed-by: Peter Eisentraut Discussion: https://postgr.es/m/ZIq1HUnIV2ksW85x@paquier.xyz --- contrib/unaccent/Makefile | 4 ---- contrib/unaccent/expected/unaccent.out | 16 +++++++++------- contrib/unaccent/expected/unaccent_1.out | 8 ++++++++ contrib/unaccent/meson.build | 1 - contrib/unaccent/sql/unaccent.sql | 14 +++++++++++--- 5 files changed, 28 insertions(+), 15 deletions(-) create mode 100644 contrib/unaccent/expected/unaccent_1.out diff --git a/contrib/unaccent/Makefile b/contrib/unaccent/Makefile index d6c466e07a..652a3e774c 100644 --- a/contrib/unaccent/Makefile +++ b/contrib/unaccent/Makefile @@ -12,10 +12,6 @@ PGFILEDESC = "unaccent - text search dictionary that removes accents" REGRESS = unaccent -# We need a UTF8 database -ENCODING = UTF8 -NO_LOCALE = 1 - ifdef USE_PGXS PG_CONFIG = pg_config PGXS := $(shell $(PG_CONFIG) --pgxs) diff --git a/contrib/unaccent/expected/unaccent.out b/contrib/unaccent/expected/unaccent.out index ee0ac71a1c..f080707c4a 100644 --- a/contrib/unaccent/expected/unaccent.out +++ b/contrib/unaccent/expected/unaccent.out @@ -1,11 +1,13 @@ +/* + * This test must be run in a database with UTF-8 encoding, + * because other encodings don't support all the characters used. + */ +SELECT getdatabaseencoding() <> 'UTF8' + AS skip_test \gset +\if :skip_test +\quit +\endif CREATE EXTENSION unaccent; --- must have a UTF8 database -SELECT getdatabaseencoding(); - getdatabaseencoding ---------------------- - UTF8 -(1 row) - SET client_encoding TO 'UTF8'; SELECT unaccent('foobar'); unaccent diff --git a/contrib/unaccent/expected/unaccent_1.out b/contrib/unaccent/expected/unaccent_1.out new file mode 100644 index 0000000000..37aead89c0 --- /dev/null +++ b/contrib/unaccent/expected/unaccent_1.out @@ -0,0 +1,8 @@ +/* + * This test must be run in a database with UTF-8 encoding, + * because other encodings don't support all the characters used. + */ +SELECT getdatabaseencoding() <> 'UTF8' + AS skip_test \gset +\if :skip_test +\quit diff --git a/contrib/unaccent/meson.build b/contrib/unaccent/meson.build index bd629ec090..a93bf10468 100644 --- a/contrib/unaccent/meson.build +++ b/contrib/unaccent/meson.build @@ -37,6 +37,5 @@ tests += { 'sql': [ 'unaccent', ], - 'regress_args': ['--no-locale', '--encoding=UTF8'], }, } diff --git a/contrib/unaccent/sql/unaccent.sql b/contrib/unaccent/sql/unaccent.sql index 3fc0c706be..663646c1ac 100644 --- a/contrib/unaccent/sql/unaccent.sql +++ b/contrib/unaccent/sql/unaccent.sql @@ -1,7 +1,15 @@ -CREATE EXTENSION unaccent; +/* + * This test must be run in a database with UTF-8 encoding, + * because other encodings don't support all the characters used. + */ --- must have a UTF8 database -SELECT getdatabaseencoding(); +SELECT getdatabaseencoding() <> 'UTF8' + AS skip_test \gset +\if :skip_test +\quit +\endif + +CREATE EXTENSION unaccent; SET client_encoding TO 'UTF8';