Skip to content

Commit f9c4cb6

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 e3e29ce commit f9c4cb6

File tree

13 files changed

+45
-1
lines changed

13 files changed

+45
-1
lines changed

contrib/amcheck/t/001_verify_heapam.pl

+8
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,8 @@ sub corrupt_first_page
209209

210210
sub detects_heap_corruption
211211
{
212+
local $Test::Builder::Level = $Test::Builder::Level + 1;
213+
212214
my ($function, $testname) = @_;
213215

214216
detects_corruption(
@@ -224,6 +226,8 @@ sub detects_heap_corruption
224226

225227
sub detects_corruption
226228
{
229+
local $Test::Builder::Level = $Test::Builder::Level + 1;
230+
227231
my ($function, $testname, @re) = @_;
228232

229233
my $result = $node->safe_psql('postgres', qq(SELECT * FROM $function));
@@ -232,6 +236,8 @@ sub detects_corruption
232236

233237
sub detects_no_corruption
234238
{
239+
local $Test::Builder::Level = $Test::Builder::Level + 1;
240+
235241
my ($function, $testname) = @_;
236242

237243
my $result = $node->safe_psql('postgres', qq(SELECT * FROM $function));
@@ -247,6 +253,8 @@ sub detects_no_corruption
247253
# and should be unique.
248254
sub check_all_options_uncorrupted
249255
{
256+
local $Test::Builder::Level = $Test::Builder::Level + 1;
257+
250258
my ($relname, $prefix) = @_;
251259

252260
for my $stop (qw(true false))

contrib/test_decoding/t/001_repl_stats.pl

+2
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
# Check that replication slot stats are expected.
2020
sub test_slot_stats
2121
{
22+
local $Test::Builder::Level = $Test::Builder::Level + 1;
23+
2224
my ($node, $expected, $msg) = @_;
2325

2426
my $result = $node->safe_psql(

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

+2
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,8 @@ sub create_files
7272

7373
sub run_check
7474
{
75+
local $Test::Builder::Level = $Test::Builder::Level + 1;
76+
7577
my ($suffix, $test_name) = @_;
7678

7779
create_files();

src/bin/pg_ctl/t/004_logrotate.pl

+2
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ sub fetch_file_name
3131
# Check for a pattern in the logs associated to one format.
3232
sub check_log_pattern
3333
{
34+
local $Test::Builder::Level = $Test::Builder::Level + 1;
35+
3436
my $format = shift;
3537
my $logfiles = shift;
3638
my $pattern = shift;

src/bin/pg_verifybackup/t/005_bad_manifest.pl

+6
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,8 @@
176176

177177
sub test_parse_error
178178
{
179+
local $Test::Builder::Level = $Test::Builder::Level + 1;
180+
179181
my ($test_name, $manifest_contents) = @_;
180182

181183
test_bad_manifest($test_name,
@@ -186,6 +188,8 @@ sub test_parse_error
186188

187189
sub test_fatal_error
188190
{
191+
local $Test::Builder::Level = $Test::Builder::Level + 1;
192+
189193
my ($test_name, $manifest_contents) = @_;
190194

191195
test_bad_manifest($test_name, qr/fatal: $test_name/, $manifest_contents);
@@ -194,6 +198,8 @@ sub test_fatal_error
194198

195199
sub test_bad_manifest
196200
{
201+
local $Test::Builder::Level = $Test::Builder::Level + 1;
202+
197203
my ($test_name, $regexp, $manifest_contents) = @_;
198204

199205
open(my $fh, '>', "$tempdir/backup_manifest") || die "open: $!";

src/bin/psql/t/010_tab_completion.pl

+4
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,8 @@ sub check_completion
127127
# (won't work if we are inside a string literal!)
128128
sub clear_query
129129
{
130+
local $Test::Builder::Level = $Test::Builder::Level + 1;
131+
130132
check_completion("\\r\n", qr/postgres=# /, "\\r works");
131133
return;
132134
}
@@ -136,6 +138,8 @@ sub clear_query
136138
# than clear_query because we lose evidence in the history file)
137139
sub clear_line
138140
{
141+
local $Test::Builder::Level = $Test::Builder::Level + 1;
142+
139143
check_completion("\025\n", qr/postgres=# /, "control-U works");
140144
return;
141145
}

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

+2
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,8 @@ sub test_access
221221
# As above, but test for an arbitrary query result.
222222
sub test_query
223223
{
224+
local $Test::Builder::Level = $Test::Builder::Level + 1;
225+
224226
my ($node, $role, $query, $expected, $gssencmode, $test_name) = @_;
225227

226228
# need to connect over TCP/IP for Kerberos

src/test/perl/README

+9-1
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

+2
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,8 @@
7575
# Expect to connect to $target_node (undef for failure) with given $status.
7676
sub test_target_session_attrs
7777
{
78+
local $Test::Builder::Level = $Test::Builder::Level + 1;
79+
7880
my $node1 = shift;
7981
my $node2 = shift;
8082
my $target_node = shift;

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

+2
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
# count to reach $num_rows, yet not later than the recovery target.
1515
sub test_recovery_standby
1616
{
17+
local $Test::Builder::Level = $Test::Builder::Level + 1;
18+
1719
my $test_name = shift;
1820
my $node_name = shift;
1921
my $node_primary = shift;

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

+2
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
# the configuration file is reloaded before the test.
1818
sub test_sync_state
1919
{
20+
local $Test::Builder::Level = $Test::Builder::Level + 1;
21+
2022
my ($self, $expected, $msg, $setting) = @_;
2123

2224
if (defined($setting))

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

+2
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414

1515
sub configure_and_reload
1616
{
17+
local $Test::Builder::Level = $Test::Builder::Level + 1;
18+
1719
my ($node, $parameter) = @_;
1820
my $name = $node->name;
1921

src/test/recovery/t/018_wal_optimize.pl

+2
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818

1919
sub check_orphan_relfilenodes
2020
{
21+
local $Test::Builder::Level = $Test::Builder::Level + 1;
22+
2123
my ($node, $test_name) = @_;
2224

2325
my $db_oid = $node->safe_psql('postgres',

0 commit comments

Comments
 (0)