summaryrefslogtreecommitdiff
path: root/src/test/modules
diff options
context:
space:
mode:
authorMichael Paquier2025-10-17 05:39:09 +0000
committerMichael Paquier2025-10-17 05:39:09 +0000
commitfabb33b351c2504a1985f9a1cdf697924cd5f023 (patch)
tree07eb3a2e976720adcfe310dce5592e880734488a /src/test/modules
parente64aa1a39d4b8a9502be8ed8dfd67efd6f6acf28 (diff)
Improve TAP tests by replacing ok() with better Test::More functions
The TAP tests whose ok() calls are changed in this commit were relying on perl operators, rather than equivalents available in Test::More. For example, rather than the following: ok($data =~ qr/expr/m, "expr matching"); ok($data !~ qr/expr/m, "expr not matching"); The new test code uses this equivalent: like($data, qr/expr/m, "expr matching"); unlike($data, qr/expr/m, "expr not matching"); A huge benefit of the new formulation is that it is possible to know about the values we are checking if a failure happens, making debugging easier, should the test runs happen in the buildfarm, in the CI or locally. This change leads to more test code overall as perltidy likes to make the code pretty the way it is in this commit. Author: Sadhuprasad Patro <b.sadhu@gmail.com> Discussion: https://postgr.es/m/CAFF0-CHhwNx_Cv2uy7tKjODUbeOgPrJpW4Rpf1jqB16_1bU2sg@mail.gmail.com
Diffstat (limited to 'src/test/modules')
-rw-r--r--src/test/modules/test_aio/t/002_io_workers.pl5
-rw-r--r--src/test/modules/test_misc/t/001_constraint_validation.pl123
-rw-r--r--src/test/modules/test_misc/t/002_tablespace.pl40
-rw-r--r--src/test/modules/test_pg_dump/t/001_base.pl6
-rw-r--r--src/test/modules/xid_wraparound/t/002_limits.pl2
5 files changed, 101 insertions, 75 deletions
diff --git a/src/test/modules/test_aio/t/002_io_workers.pl b/src/test/modules/test_aio/t/002_io_workers.pl
index af5fae15ea7..22914385df3 100644
--- a/src/test/modules/test_aio/t/002_io_workers.pl
+++ b/src/test/modules/test_aio/t/002_io_workers.pl
@@ -67,8 +67,9 @@ sub change_number_of_io_workers
if ($expect_failure)
{
- ok( $stderr =~
- /$worker_count is outside the valid range for parameter "io_workers"/,
+ like(
+ $stderr,
+ qr/$worker_count is outside the valid range for parameter "io_workers"/,
"updating number of io_workers to $worker_count failed, as expected"
);
diff --git a/src/test/modules/test_misc/t/001_constraint_validation.pl b/src/test/modules/test_misc/t/001_constraint_validation.pl
index 1d86936ec69..bdc751724f4 100644
--- a/src/test/modules/test_misc/t/001_constraint_validation.pl
+++ b/src/test/modules/test_misc/t/001_constraint_validation.pl
@@ -58,8 +58,9 @@ run_sql_command(
# normal run will verify table data
$output = run_sql_command('alter table atacc1 alter test_a set not null;');
ok(!is_table_verified($output), 'with constraint will not scan table');
-ok( $output =~
- m/existing constraints on column "atacc1.test_a" are sufficient to prove that it does not contain nulls/,
+like(
+ $output,
+ qr/existing constraints on column "atacc1.test_a" are sufficient to prove that it does not contain nulls/,
'test_a proved by constraints');
run_sql_command('alter table atacc1 alter test_a drop not null;');
@@ -70,9 +71,9 @@ $output = run_sql_command(
);
ok(is_table_verified($output), 'table was scanned');
# we may miss debug message for test_a constraint because we need verify table due test_b
-ok( !( $output =~
- m/existing constraints on column "atacc1.test_b" are sufficient to prove that it does not contain nulls/
- ),
+unlike(
+ $output,
+ qr/existing constraints on column "atacc1.test_b" are sufficient to prove that it does not contain nulls/,
'test_b not proved by wrong constraints');
run_sql_command(
'alter table atacc1 alter test_a drop not null, alter test_b drop not null;'
@@ -86,11 +87,13 @@ $output = run_sql_command(
'alter table atacc1 alter test_b set not null, alter test_a set not null;'
);
ok(!is_table_verified($output), 'table was not scanned for both columns');
-ok( $output =~
- m/existing constraints on column "atacc1.test_a" are sufficient to prove that it does not contain nulls/,
+like(
+ $output,
+ qr/existing constraints on column "atacc1.test_a" are sufficient to prove that it does not contain nulls/,
'test_a proved by constraints');
-ok( $output =~
- m/existing constraints on column "atacc1.test_b" are sufficient to prove that it does not contain nulls/,
+like(
+ $output,
+ qr/existing constraints on column "atacc1.test_b" are sufficient to prove that it does not contain nulls/,
'test_b proved by constraints');
run_sql_command('drop table atacc1;');
@@ -119,8 +122,9 @@ $output = run_sql_command(
'ALTER TABLE list_parted2 ATTACH PARTITION part_3_4 FOR VALUES IN (3, 4);'
);
ok(!is_table_verified($output), 'table part_3_4 not scanned');
-ok( $output =~
- m/partition constraint for table "part_3_4" is implied by existing constraints/,
+like(
+ $output,
+ qr/partition constraint for table "part_3_4" is implied by existing constraints/,
'part_3_4 verified by existing constraints');
# test attach default partition
@@ -131,16 +135,18 @@ run_sql_command(
$output = run_sql_command(
'ALTER TABLE list_parted2 ATTACH PARTITION list_parted2_def default;');
ok(!is_table_verified($output), 'table list_parted2_def not scanned');
-ok( $output =~
- m/partition constraint for table "list_parted2_def" is implied by existing constraints/,
+like(
+ $output,
+ qr/partition constraint for table "list_parted2_def" is implied by existing constraints/,
'list_parted2_def verified by existing constraints');
$output = run_sql_command(
'CREATE TABLE part_55_66 PARTITION OF list_parted2 FOR VALUES IN (55, 66);'
);
ok(!is_table_verified($output), 'table list_parted2_def not scanned');
-ok( $output =~
- m/updated partition constraint for default partition "list_parted2_def" is implied by existing constraints/,
+like(
+ $output,
+ qr/updated partition constraint for default partition "list_parted2_def" is implied by existing constraints/,
'updated partition constraint for default partition list_parted2_def');
# test attach another partitioned table
@@ -153,11 +159,14 @@ run_sql_command(
);
$output = run_sql_command(
'ALTER TABLE list_parted2 ATTACH PARTITION part_5 FOR VALUES IN (5);');
-ok(!($output =~ m/verifying table "part_5"/), 'table part_5 not scanned');
-ok($output =~ m/verifying table "list_parted2_def"/,
+unlike($output, qr/verifying table "part_5"/, 'table part_5 not scanned');
+like(
+ $output,
+ qr/verifying table "list_parted2_def"/,
'list_parted2_def scanned');
-ok( $output =~
- m/partition constraint for table "part_5" is implied by existing constraints/,
+like(
+ $output,
+ qr/partition constraint for table "part_5" is implied by existing constraints/,
'part_5 verified by existing constraints');
run_sql_command(
@@ -171,11 +180,14 @@ run_sql_command(
);
$output = run_sql_command(
'ALTER TABLE list_parted2 ATTACH PARTITION part_5 FOR VALUES IN (5);');
-ok(!($output =~ m/verifying table "part_5"/), 'table part_5 not scanned');
-ok($output =~ m/verifying table "list_parted2_def"/,
+unlike($output, qr/verifying table "part_5"/, 'table part_5 not scanned');
+like(
+ $output,
+ qr/verifying table "list_parted2_def"/,
'list_parted2_def scanned');
-ok( $output =~
- m/partition constraint for table "part_5" is implied by existing constraints/,
+like(
+ $output,
+ qr/partition constraint for table "part_5" is implied by existing constraints/,
'part_5 verified by existing constraints');
# Check the case where attnos of the partitioning columns in the table being
@@ -190,11 +202,14 @@ run_sql_command(
ALTER TABLE part_6 DROP c;');
$output = run_sql_command(
'ALTER TABLE list_parted2 ATTACH PARTITION part_6 FOR VALUES IN (6);');
-ok(!($output =~ m/verifying table "part_6"/), 'table part_6 not scanned');
-ok($output =~ m/verifying table "list_parted2_def"/,
+unlike($output, qr/verifying table "part_6"/, 'table part_6 not scanned');
+like(
+ $output,
+ qr/verifying table "list_parted2_def"/,
'list_parted2_def scanned');
-ok( $output =~
- m/partition constraint for table "part_6" is implied by existing constraints/,
+like(
+ $output,
+ qr/partition constraint for table "part_6" is implied by existing constraints/,
'part_6 verified by existing constraints');
# Similar to above, but the table being attached is a partitioned table
@@ -219,17 +234,20 @@ $output = run_sql_command(
'ALTER TABLE part_7 ATTACH PARTITION part_7_a_null FOR VALUES IN (\'a\', null);'
);
ok(!is_table_verified($output), 'table not scanned');
-ok( $output =~
- m/partition constraint for table "part_7_a_null" is implied by existing constraints/,
+like(
+ $output,
+ qr/partition constraint for table "part_7_a_null" is implied by existing constraints/,
'part_7_a_null verified by existing constraints');
$output = run_sql_command(
'ALTER TABLE list_parted2 ATTACH PARTITION part_7 FOR VALUES IN (7);');
ok(!is_table_verified($output), 'tables not scanned');
-ok( $output =~
- m/partition constraint for table "part_7" is implied by existing constraints/,
+like(
+ $output,
+ qr/partition constraint for table "part_7" is implied by existing constraints/,
'part_7 verified by existing constraints');
-ok( $output =~
- m/updated partition constraint for default partition "list_parted2_def" is implied by existing constraints/,
+like(
+ $output,
+ qr/updated partition constraint for default partition "list_parted2_def" is implied by existing constraints/,
'updated partition constraint for default partition list_parted2_def');
run_sql_command(
@@ -245,9 +263,9 @@ $output = run_sql_command(
'ALTER TABLE range_parted ATTACH PARTITION range_part1 FOR VALUES FROM (1, 1) TO (1, 10);'
);
ok(is_table_verified($output), 'table range_part1 scanned');
-ok( !( $output =~
- m/partition constraint for table "range_part1" is implied by existing constraints/
- ),
+unlike(
+ $output,
+ qr/partition constraint for table "range_part1" is implied by existing constraints/,
'range_part1 not verified by existing constraints');
run_sql_command(
@@ -259,8 +277,9 @@ $output = run_sql_command(
'ALTER TABLE range_parted ATTACH PARTITION range_part2 FOR VALUES FROM (1, 10) TO (1, 20);'
);
ok(!is_table_verified($output), 'table range_part2 not scanned');
-ok( $output =~
- m/partition constraint for table "range_part2" is implied by existing constraints/,
+like(
+ $output,
+ qr/partition constraint for table "range_part2" is implied by existing constraints/,
'range_part2 verified by existing constraints');
# If a partitioned table being created or an existing table being attached
@@ -278,19 +297,22 @@ run_sql_command(
$output = run_sql_command(
'ALTER TABLE quuux ATTACH PARTITION quuux1 FOR VALUES IN (1);');
ok(is_table_verified($output), 'quuux1 table scanned');
-ok( !( $output =~
- m/partition constraint for table "quuux1" is implied by existing constraints/
- ),
+unlike(
+ $output,
+ qr/partition constraint for table "quuux1" is implied by existing constraints/,
'quuux1 verified by existing constraints');
run_sql_command('CREATE TABLE quuux2 (a int, b text);');
$output = run_sql_command(
'ALTER TABLE quuux ATTACH PARTITION quuux2 FOR VALUES IN (2);');
-ok(!($output =~ m/verifying table "quuux_default1"/),
+unlike(
+ $output,
+ qr/verifying table "quuux_default1"/,
'quuux_default1 not scanned');
-ok($output =~ m/verifying table "quuux2"/, 'quuux2 scanned');
-ok( $output =~
- m/updated partition constraint for default partition "quuux_default1" is implied by existing constraints/,
+like($output, qr/verifying table "quuux2"/, 'quuux2 scanned');
+like(
+ $output,
+ qr/updated partition constraint for default partition "quuux_default1" is implied by existing constraints/,
'updated partition constraint for default partition quuux_default1');
run_sql_command('DROP TABLE quuux1, quuux2;');
@@ -298,15 +320,16 @@ run_sql_command('DROP TABLE quuux1, quuux2;');
$output = run_sql_command(
'CREATE TABLE quuux1 PARTITION OF quuux FOR VALUES IN (1);');
ok(!is_table_verified($output), 'tables not scanned');
-ok( !( $output =~
- m/partition constraint for table "quuux1" is implied by existing constraints/
- ),
+unlike(
+ $output,
+ qr/partition constraint for table "quuux1" is implied by existing constraints/,
'quuux1 verified by existing constraints');
$output = run_sql_command(
'CREATE TABLE quuux2 PARTITION OF quuux FOR VALUES IN (2);');
ok(!is_table_verified($output), 'tables not scanned');
-ok( $output =~
- m/updated partition constraint for default partition "quuux_default1" is implied by existing constraints/,
+like(
+ $output,
+ qr/updated partition constraint for default partition "quuux_default1" is implied by existing constraints/,
'updated partition constraint for default partition quuux_default1');
run_sql_command('DROP TABLE quuux;');
diff --git a/src/test/modules/test_misc/t/002_tablespace.pl b/src/test/modules/test_misc/t/002_tablespace.pl
index b8a5617c788..972215b76c6 100644
--- a/src/test/modules/test_misc/t/002_tablespace.pl
+++ b/src/test/modules/test_misc/t/002_tablespace.pl
@@ -29,69 +29,69 @@ my $result;
# Create a tablespace with an absolute path
$result = $node->psql('postgres',
"CREATE TABLESPACE regress_ts1 LOCATION '$TS1_LOCATION'");
-ok($result == 0, 'create tablespace with absolute path');
+is($result, 0, 'create tablespace with absolute path');
# Can't create a tablespace where there is one already
$result = $node->psql('postgres',
"CREATE TABLESPACE regress_ts1 LOCATION '$TS1_LOCATION'");
-ok($result != 0, 'clobber tablespace with absolute path');
+isnt($result, 0, 'clobber tablespace with absolute path');
# Create table in it
$result = $node->psql('postgres', "CREATE TABLE t () TABLESPACE regress_ts1");
-ok($result == 0, 'create table in tablespace with absolute path');
+is($result, 0, 'create table in tablespace with absolute path');
# Can't drop a tablespace that still has a table in it
$result = $node->psql('postgres', "DROP TABLESPACE regress_ts1");
-ok($result != 0, 'drop tablespace with absolute path');
+isnt($result, 0, 'drop tablespace with absolute path');
# Drop the table
$result = $node->psql('postgres', "DROP TABLE t");
-ok($result == 0, 'drop table in tablespace with absolute path');
+is($result, 0, 'drop table in tablespace with absolute path');
# Drop the tablespace
$result = $node->psql('postgres', "DROP TABLESPACE regress_ts1");
-ok($result == 0, 'drop tablespace with absolute path');
+is($result, 0, 'drop tablespace with absolute path');
# Create two absolute tablespaces and two in-place tablespaces, so we can
# testing various kinds of tablespace moves.
$result = $node->psql('postgres',
"CREATE TABLESPACE regress_ts1 LOCATION '$TS1_LOCATION'");
-ok($result == 0, 'create tablespace 1 with absolute path');
+is($result, 0, 'create tablespace 1 with absolute path');
$result = $node->psql('postgres',
"CREATE TABLESPACE regress_ts2 LOCATION '$TS2_LOCATION'");
-ok($result == 0, 'create tablespace 2 with absolute path');
+is($result, 0, 'create tablespace 2 with absolute path');
$result = $node->psql('postgres',
"SET allow_in_place_tablespaces=on; CREATE TABLESPACE regress_ts3 LOCATION ''"
);
-ok($result == 0, 'create tablespace 3 with in-place directory');
+is($result, 0, 'create tablespace 3 with in-place directory');
$result = $node->psql('postgres',
"SET allow_in_place_tablespaces=on; CREATE TABLESPACE regress_ts4 LOCATION ''"
);
-ok($result == 0, 'create tablespace 4 with in-place directory');
+is($result, 0, 'create tablespace 4 with in-place directory');
# Create a table and test moving between absolute and in-place tablespaces
$result = $node->psql('postgres', "CREATE TABLE t () TABLESPACE regress_ts1");
-ok($result == 0, 'create table in tablespace 1');
+is($result, 0, 'create table in tablespace 1');
$result = $node->psql('postgres', "ALTER TABLE t SET tablespace regress_ts2");
-ok($result == 0, 'move table abs->abs');
+is($result, 0, 'move table abs->abs');
$result = $node->psql('postgres', "ALTER TABLE t SET tablespace regress_ts3");
-ok($result == 0, 'move table abs->in-place');
+is($result, 0, 'move table abs->in-place');
$result = $node->psql('postgres', "ALTER TABLE t SET tablespace regress_ts4");
-ok($result == 0, 'move table in-place->in-place');
+is($result, 0, 'move table in-place->in-place');
$result = $node->psql('postgres', "ALTER TABLE t SET tablespace regress_ts1");
-ok($result == 0, 'move table in-place->abs');
+is($result, 0, 'move table in-place->abs');
# Drop everything
$result = $node->psql('postgres', "DROP TABLE t");
-ok($result == 0, 'create table in tablespace 1');
+is($result, 0, 'create table in tablespace 1');
$result = $node->psql('postgres', "DROP TABLESPACE regress_ts1");
-ok($result == 0, 'drop tablespace 1');
+is($result, 0, 'drop tablespace 1');
$result = $node->psql('postgres', "DROP TABLESPACE regress_ts2");
-ok($result == 0, 'drop tablespace 2');
+is($result, 0, 'drop tablespace 2');
$result = $node->psql('postgres', "DROP TABLESPACE regress_ts3");
-ok($result == 0, 'drop tablespace 3');
+is($result, 0, 'drop tablespace 3');
$result = $node->psql('postgres', "DROP TABLESPACE regress_ts4");
-ok($result == 0, 'drop tablespace 4');
+is($result, 0, 'drop tablespace 4');
$node->stop;
diff --git a/src/test/modules/test_pg_dump/t/001_base.pl b/src/test/modules/test_pg_dump/t/001_base.pl
index adcaa419616..1d84b86ad9a 100644
--- a/src/test/modules/test_pg_dump/t/001_base.pl
+++ b/src/test/modules/test_pg_dump/t/001_base.pl
@@ -981,7 +981,8 @@ foreach my $run (sort keys %pgdump_runs)
if ($tests{$test}->{like}->{$test_key}
&& !defined($tests{$test}->{unlike}->{$test_key}))
{
- if (!ok($output_file =~ $tests{$test}->{regexp},
+ if (!like(
+ $output_file, $tests{$test}->{regexp},
"$run: should dump $test"))
{
diag("Review $run results in $tempdir");
@@ -989,7 +990,8 @@ foreach my $run (sort keys %pgdump_runs)
}
else
{
- if (!ok($output_file !~ $tests{$test}->{regexp},
+ if (!unlike(
+ $output_file, $tests{$test}->{regexp},
"$run: should not dump $test"))
{
diag("Review $run results in $tempdir");
diff --git a/src/test/modules/xid_wraparound/t/002_limits.pl b/src/test/modules/xid_wraparound/t/002_limits.pl
index aa1d8765d3a..8dd7f89a7d3 100644
--- a/src/test/modules/xid_wraparound/t/002_limits.pl
+++ b/src/test/modules/xid_wraparound/t/002_limits.pl
@@ -90,7 +90,7 @@ for my $i (1 .. 15)
last;
}
}
-ok($warn_limit == 1, "warn-limit reached");
+is($warn_limit, 1, "warn-limit reached");
# We can still INSERT, despite the warnings.
$node->safe_psql('postgres',