Fix regression tests of unaccent to work without UTF8 support
authorMichael Paquier <[email protected]>
Mon, 3 Jul 2023 23:05:00 +0000 (08:05 +0900)
committerMichael Paquier <[email protected]>
Mon, 3 Jul 2023 23:05:00 +0000 (08:05 +0900)
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/[email protected]

contrib/unaccent/Makefile
contrib/unaccent/expected/unaccent.out
contrib/unaccent/expected/unaccent_1.out [new file with mode: 0644]
contrib/unaccent/meson.build
contrib/unaccent/sql/unaccent.sql

index d6c466e07adba1ef64de3e1614854e711c7ad15f..652a3e774c072ef7934d74fb7d1eed279ccb09b3 100644 (file)
@@ -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)
index ee0ac71a1cc7cc204e2f2e0d7b04366ff1d3a861..f080707c4acd3c4966617e8b89003ef2ef8cce12 100644 (file)
@@ -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 (file)
index 0000000..37aead8
--- /dev/null
@@ -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
index bd629ec090e4651f1d288ce6f6ce9e8119eb3256..a93bf10468d0174aaacd26b5891ddb49da6529ec 100644 (file)
@@ -37,6 +37,5 @@ tests += {
     'sql': [
       'unaccent',
     ],
-    'regress_args': ['--no-locale', '--encoding=UTF8'],
   },
 }
index 3fc0c706be388d9bc7213c8c047064e0d87ff343..663646c1ac43f7ec6a607795d571204658476a48 100644 (file)
@@ -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.
+ */
+
+SELECT getdatabaseencoding() <> 'UTF8'
+       AS skip_test \gset
+\if :skip_test
+\quit
+\endif
 
--- must have a UTF8 database
-SELECT getdatabaseencoding();
+CREATE EXTENSION unaccent;
 
 SET client_encoding TO 'UTF8';