diff options
author | Michael Paquier <michael@paquier.xyz> | 2021-10-12 11:16:30 +0900 |
---|---|---|
committer | Michael Paquier <michael@paquier.xyz> | 2021-10-12 11:16:30 +0900 |
commit | d5ab331a339d1a5f484e514e8cd231c291261dec (patch) | |
tree | 213ce32746c2970cd2083aef7618324b215ccd84 | |
parent | 2288973744e8bd4715d1daaaf2cd1d9b534aa1bf (diff) | |
download | postgresql-d5ab331a339d1a5f484e514e8cd231c291261dec.tar.gz postgresql-d5ab331a339d1a5f484e514e8cd231c291261dec.zip |
Add more $Test::Builder::Level in the TAP tests
Incrementing the level of the call stack reported is useful for
debugging purposes as it allows to control which part of the test is
exactly failing, especially if a test is structured with subroutines
that call routines from Test::More.
This adds more incrementations of $Test::Builder::Level where debugging
gets improved (for example it does not make sense for some paths like
pg_rewind where long subroutines are used).
A note is added to src/test/perl/README about that, based on a
suggestion from Andrew Dunstan and a wording coming from both of us.
Usage of Test::Builder::Level has spread in 12, so a backpatch down to
this version is done.
Reviewed-by: Andrew Dunstan, Peter Eisentraut, Daniel Gustafsson
Discussion: https://postgr.es/m/YV1CCFwgM1RV1LeS@paquier.xyz
Backpatch-through: 12
-rw-r--r-- | src/bin/pg_archivecleanup/t/010_pg_archivecleanup.pl | 2 | ||||
-rw-r--r-- | src/test/kerberos/t/001_auth.pl | 2 | ||||
-rw-r--r-- | src/test/perl/README | 10 | ||||
-rw-r--r-- | src/test/recovery/t/001_stream_rep.pl | 2 | ||||
-rw-r--r-- | src/test/recovery/t/003_recovery_targets.pl | 2 | ||||
-rw-r--r-- | src/test/recovery/t/007_sync_rep.pl | 2 | ||||
-rw-r--r-- | src/test/recovery/t/009_twophase.pl | 2 |
7 files changed, 21 insertions, 1 deletions
diff --git a/src/bin/pg_archivecleanup/t/010_pg_archivecleanup.pl b/src/bin/pg_archivecleanup/t/010_pg_archivecleanup.pl index 22782d30420..3d196c8d861 100644 --- a/src/bin/pg_archivecleanup/t/010_pg_archivecleanup.pl +++ b/src/bin/pg_archivecleanup/t/010_pg_archivecleanup.pl @@ -69,6 +69,8 @@ command_fails_like( sub run_check { + local $Test::Builder::Level = $Test::Builder::Level + 1; + my ($suffix, $test_name) = @_; create_files(); diff --git a/src/test/kerberos/t/001_auth.pl b/src/test/kerberos/t/001_auth.pl index 8d49847948c..4b22d3ccfaf 100644 --- a/src/test/kerberos/t/001_auth.pl +++ b/src/test/kerberos/t/001_auth.pl @@ -203,6 +203,8 @@ sub test_access # As above, but test for an arbitrary query result. sub test_query { + local $Test::Builder::Level = $Test::Builder::Level + 1; + my ($node, $role, $query, $expected, $gssencmode, $test_name) = @_; # need to connect over TCP/IP for Kerberos diff --git a/src/test/perl/README b/src/test/perl/README index c61c3f5e942..dc35204bb61 100644 --- a/src/test/perl/README +++ b/src/test/perl/README @@ -61,9 +61,17 @@ Test::More::like entails use of the qr// operator. Avoid Perl 5.8.8 bug #39185 by not using the "$" regular expression metacharacter in qr// when also using the "/m" modifier. Instead of "$", use "\n" or "(?=\n|\z)". -Read the Test::More documentation for more on how to write tests: +Test::Builder::Level controls how far up in the call stack a test will look +at when reporting a failure. This should be incremented by any subroutine +which directly or indirectly calls test routines from Test::More, such as +ok() or is(): + + local $Test::Builder::Level = $Test::Builder::Level + 1; + +Read the documentation for more on how to write tests: perldoc Test::More + perldoc Test::Builder For available PostgreSQL-specific test methods and some example tests read the perldoc for the test modules, e.g.: diff --git a/src/test/recovery/t/001_stream_rep.pl b/src/test/recovery/t/001_stream_rep.pl index be51fa0ffe3..e3fb22645bd 100644 --- a/src/test/recovery/t/001_stream_rep.pl +++ b/src/test/recovery/t/001_stream_rep.pl @@ -72,6 +72,8 @@ note "testing connection parameter \"target_session_attrs\""; # target_session_attrs with multiple nodes. sub test_target_session_attrs { + local $Test::Builder::Level = $Test::Builder::Level + 1; + my $node1 = shift; my $node2 = shift; my $target_node = shift; diff --git a/src/test/recovery/t/003_recovery_targets.pl b/src/test/recovery/t/003_recovery_targets.pl index f704320f803..2b4c6f4e720 100644 --- a/src/test/recovery/t/003_recovery_targets.pl +++ b/src/test/recovery/t/003_recovery_targets.pl @@ -10,6 +10,8 @@ use Test::More tests => 8; # count to reach $num_rows, yet not later than the recovery target. sub test_recovery_standby { + local $Test::Builder::Level = $Test::Builder::Level + 1; + my $test_name = shift; my $node_name = shift; my $node_master = shift; diff --git a/src/test/recovery/t/007_sync_rep.pl b/src/test/recovery/t/007_sync_rep.pl index eccde8f551f..b17ed3ac529 100644 --- a/src/test/recovery/t/007_sync_rep.pl +++ b/src/test/recovery/t/007_sync_rep.pl @@ -14,6 +14,8 @@ my $check_sql = # the configuration file is reloaded before the test. sub test_sync_state { + local $Test::Builder::Level = $Test::Builder::Level + 1; + my ($self, $expected, $msg, $setting) = @_; if (defined($setting)) diff --git a/src/test/recovery/t/009_twophase.pl b/src/test/recovery/t/009_twophase.pl index 1b748ad857b..4a79c5ebfdb 100644 --- a/src/test/recovery/t/009_twophase.pl +++ b/src/test/recovery/t/009_twophase.pl @@ -11,6 +11,8 @@ my $psql_rc = ''; sub configure_and_reload { + local $Test::Builder::Level = $Test::Builder::Level + 1; + my ($node, $parameter) = @_; my $name = $node->name; |