Following [0], I did a broader analysis of some dubious or nonsensical like/unlike combinations in the pg_dump tests.

This includes

1) Remove useless entries from "unlike" lists.  Runs that are not
   listed in "like" don't need to be excluded in "unlike".

2) Ensure there is always a "like" list, even if it is empty.  This
   makes the test more self-documenting.

3) Use predefined lists such as %full_runs where appropriate, instead
   of listing all runs separately.

I also added code that checks 1 and 2 automatically and issues a message
for violations. (This is currently done with "diag". We could also make it an error.)

The results are in the attached patch.

[0]: https://www.postgresql.org/message-id/3ddf79f2-8b7b-a093-11d2-5c739bc64...@eisentraut.org
From bf13888e63431c513e440982a72a76d1d7193777 Mon Sep 17 00:00:00 2001
From: Peter Eisentraut <pe...@eisentraut.org>
Date: Mon, 2 Oct 2023 08:58:23 +0200
Subject: [PATCH] Clean up some pg_dump tests

1) Remove useless entries from "unlike" lists.  Runs that are not
   listed in "like" don't need to be excluded in "unlike".

2) Ensure there is always a "like" list, even if it is empty.  This
   makes the test more self-documenting.

3) Use predefined lists such as %full_runs where appropriate, instead
   of listing all runs separately.

Also add code that checks 1 and 2 automatically and issues a message
for violations.
---
 src/bin/pg_dump/t/002_pg_dump.pl | 72 +++++++-------------------------
 1 file changed, 15 insertions(+), 57 deletions(-)

diff --git a/src/bin/pg_dump/t/002_pg_dump.pl b/src/bin/pg_dump/t/002_pg_dump.pl
index 55e98ec8e3..8a93910269 100644
--- a/src/bin/pg_dump/t/002_pg_dump.pl
+++ b/src/bin/pg_dump/t/002_pg_dump.pl
@@ -818,7 +818,7 @@
                regexp => qr/^\QALTER COLLATION public.test0 OWNER TO \E.+;/m,
                collation => 1,
                like => { %full_runs, section_pre_data => 1, },
-               unlike => { %dump_test_schema_runs, no_owner => 1, },
+               unlike => { no_owner => 1, },
        },
 
        'ALTER FOREIGN DATA WRAPPER dummy OWNER TO' => {
@@ -977,7 +977,7 @@
                create_sql =>
                  'ALTER SCHEMA public OWNER TO "regress_quoted  \"" role";',
                regexp => qr/^(GRANT|REVOKE)/m,
-               unlike => { defaults_public_owner => 1 },
+               like => {},
        },
 
        'ALTER SEQUENCE test_table_col1_seq' => {
@@ -1285,9 +1285,7 @@
                  { %full_runs, %dump_test_schema_runs, section_pre_data => 1, 
},
                unlike => {
                        exclude_dump_test_schema => 1,
-                       only_dump_test_table => 1,
                        no_owner => 1,
-                       role => 1,
                        only_dump_measurement => 1,
                },
        },
@@ -1351,7 +1349,6 @@
                        binary_upgrade => 1,
                        no_large_objects => 1,
                        schema_only => 1,
-                       section_pre_data => 1,
                },
        },
 
@@ -3210,7 +3207,6 @@
                        binary_upgrade => 1,
                        exclude_dump_test_schema => 1,
                        schema_only => 1,
-                       only_dump_measurement => 1,
                },
        },
 
@@ -3457,7 +3453,6 @@
        'Disabled trigger on partition is not created' => {
                regexp => qr/CREATE TRIGGER test_trigger.*ON 
dump_test_second_schema/,
                like => {},
-               unlike => { %full_runs, %dump_test_schema_runs },
        },
 
        # Triggers on partitions should not be dropped individually
@@ -3834,35 +3829,12 @@
                \QCREATE INDEX measurement_city_id_logdate_idx ON ONLY 
dump_test.measurement USING\E
                /xm,
                like => {
-                       binary_upgrade => 1,
-                       clean => 1,
-                       clean_if_exists => 1,
-                       compression => 1,
-                       createdb => 1,
-                       defaults => 1,
-                       exclude_test_table => 1,
-                       exclude_test_table_data => 1,
-                       no_toast_compression => 1,
-                       no_large_objects => 1,
-                       no_privs => 1,
-                       no_owner => 1,
-                       no_table_access_method => 1,
-                       only_dump_test_schema => 1,
-                       pg_dumpall_dbprivs => 1,
-                       pg_dumpall_exclude => 1,
-                       schema_only => 1,
+                       %full_runs,
+                       %dump_test_schema_runs,
                        section_post_data => 1,
-                       test_schema_plus_large_objects => 1,
-                       only_dump_measurement => 1,
-                       exclude_measurement_data => 1,
                },
                unlike => {
                        exclude_dump_test_schema => 1,
-                       only_dump_test_table => 1,
-                       pg_dumpall_globals => 1,
-                       pg_dumpall_globals_clean => 1,
-                       role => 1,
-                       section_pre_data => 1,
                        exclude_measurement => 1,
                },
        },
@@ -3913,7 +3885,6 @@
                        role => 1,
                        section_post_data => 1,
                        only_dump_measurement => 1,
-                       exclude_measurement_data => 1,
                },
                unlike => {
                        exclude_measurement => 1,
@@ -3927,35 +3898,12 @@
                \QALTER INDEX dump_test.measurement_pkey ATTACH PARTITION 
dump_test_second_schema.measurement_y2006m2_pkey\E
                /xm,
                like => {
-                       binary_upgrade => 1,
-                       clean => 1,
-                       clean_if_exists => 1,
-                       compression => 1,
-                       createdb => 1,
-                       defaults => 1,
-                       exclude_dump_test_schema => 1,
-                       exclude_test_table => 1,
-                       exclude_test_table_data => 1,
-                       no_toast_compression => 1,
-                       no_large_objects => 1,
-                       no_privs => 1,
-                       no_owner => 1,
-                       no_table_access_method => 1,
-                       pg_dumpall_dbprivs => 1,
-                       pg_dumpall_exclude => 1,
+                       %full_runs,
                        role => 1,
-                       schema_only => 1,
                        section_post_data => 1,
                        only_dump_measurement => 1,
-                       exclude_measurement_data => 1,
                },
                unlike => {
-                       only_dump_test_schema => 1,
-                       only_dump_test_table => 1,
-                       pg_dumpall_globals => 1,
-                       pg_dumpall_globals_clean => 1,
-                       section_pre_data => 1,
-                       test_schema_plus_large_objects => 1,
                        exclude_measurement => 1,
                },
        },
@@ -4951,6 +4899,16 @@
                        next;
                }
 
+               if (!defined($tests{$test}->{like}))
+               {
+                       diag "missing like in test \"$test\"";
+               }
+               if ($tests{$test}->{unlike}->{$test_key} &&
+                       !defined($tests{$test}->{like}->{$test_key}))
+               {
+                       diag "useless unlike \"$test_key\" in test \"$test\"";
+               }
+
                # Run the test listed as a like, unless it is specifically noted
                # as an unlike (generally due to an explicit exclusion or 
similar).
                if ($tests{$test}->{like}->{$test_key}

base-commit: c8ec5e0543b90372c8e6d5cc2cd3d2ff89ca0e82
-- 
2.42.0

Reply via email to