Skip to content

Commit d5ab331

Browse files
committed
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
1 parent 2288973 commit d5ab331

File tree

7 files changed

+21
-1
lines changed

7 files changed

+21
-1
lines changed

src/bin/pg_archivecleanup/t/010_pg_archivecleanup.pl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,8 @@ sub create_files
6969

7070
sub run_check
7171
{
72+
local $Test::Builder::Level = $Test::Builder::Level + 1;
73+
7274
my ($suffix, $test_name) = @_;
7375

7476
create_files();

src/test/kerberos/t/001_auth.pl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,8 @@ sub test_access
203203
# As above, but test for an arbitrary query result.
204204
sub test_query
205205
{
206+
local $Test::Builder::Level = $Test::Builder::Level + 1;
207+
206208
my ($node, $role, $query, $expected, $gssencmode, $test_name) = @_;
207209

208210
# need to connect over TCP/IP for Kerberos

src/test/perl/README

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,17 @@ Test::More::like entails use of the qr// operator. Avoid Perl 5.8.8 bug
6161
#39185 by not using the "$" regular expression metacharacter in qr// when also
6262
using the "/m" modifier. Instead of "$", use "\n" or "(?=\n|\z)".
6363

64-
Read the Test::More documentation for more on how to write tests:
64+
Test::Builder::Level controls how far up in the call stack a test will look
65+
at when reporting a failure. This should be incremented by any subroutine
66+
which directly or indirectly calls test routines from Test::More, such as
67+
ok() or is():
68+
69+
local $Test::Builder::Level = $Test::Builder::Level + 1;
70+
71+
Read the documentation for more on how to write tests:
6572

6673
perldoc Test::More
74+
perldoc Test::Builder
6775

6876
For available PostgreSQL-specific test methods and some example tests read the
6977
perldoc for the test modules, e.g.:

src/test/recovery/t/001_stream_rep.pl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,8 @@
7272
# target_session_attrs with multiple nodes.
7373
sub test_target_session_attrs
7474
{
75+
local $Test::Builder::Level = $Test::Builder::Level + 1;
76+
7577
my $node1 = shift;
7678
my $node2 = shift;
7779
my $target_node = shift;

src/test/recovery/t/003_recovery_targets.pl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
# count to reach $num_rows, yet not later than the recovery target.
1111
sub test_recovery_standby
1212
{
13+
local $Test::Builder::Level = $Test::Builder::Level + 1;
14+
1315
my $test_name = shift;
1416
my $node_name = shift;
1517
my $node_master = shift;

src/test/recovery/t/007_sync_rep.pl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
# the configuration file is reloaded before the test.
1515
sub test_sync_state
1616
{
17+
local $Test::Builder::Level = $Test::Builder::Level + 1;
18+
1719
my ($self, $expected, $msg, $setting) = @_;
1820

1921
if (defined($setting))

src/test/recovery/t/009_twophase.pl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111

1212
sub configure_and_reload
1313
{
14+
local $Test::Builder::Level = $Test::Builder::Level + 1;
15+
1416
my ($node, $parameter) = @_;
1517
my $name = $node->name;
1618

0 commit comments

Comments
 (0)