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/
[email protected]
Backpatch-through: 12
sub detects_heap_corruption
{
+ local $Test::Builder::Level = $Test::Builder::Level + 1;
+
my ($function, $testname) = @_;
detects_corruption(
sub detects_corruption
{
+ local $Test::Builder::Level = $Test::Builder::Level + 1;
+
my ($function, $testname, @re) = @_;
my $result = $node->safe_psql('postgres', qq(SELECT * FROM $function));
sub detects_no_corruption
{
+ local $Test::Builder::Level = $Test::Builder::Level + 1;
+
my ($function, $testname) = @_;
my $result = $node->safe_psql('postgres', qq(SELECT * FROM $function));
# and should be unique.
sub check_all_options_uncorrupted
{
+ local $Test::Builder::Level = $Test::Builder::Level + 1;
+
my ($relname, $prefix) = @_;
for my $stop (qw(true false))
# Check that replication slot stats are expected.
sub test_slot_stats
{
+ local $Test::Builder::Level = $Test::Builder::Level + 1;
+
my ($node, $expected, $msg) = @_;
my $result = $node->safe_psql(
sub run_check
{
+ local $Test::Builder::Level = $Test::Builder::Level + 1;
+
my ($suffix, $test_name) = @_;
create_files();
# Check for a pattern in the logs associated to one format.
sub check_log_pattern
{
+ local $Test::Builder::Level = $Test::Builder::Level + 1;
+
my $format = shift;
my $logfiles = shift;
my $pattern = shift;
sub test_parse_error
{
+ local $Test::Builder::Level = $Test::Builder::Level + 1;
+
my ($test_name, $manifest_contents) = @_;
test_bad_manifest($test_name,
sub test_fatal_error
{
+ local $Test::Builder::Level = $Test::Builder::Level + 1;
+
my ($test_name, $manifest_contents) = @_;
test_bad_manifest($test_name, qr/fatal: $test_name/, $manifest_contents);
sub test_bad_manifest
{
+ local $Test::Builder::Level = $Test::Builder::Level + 1;
+
my ($test_name, $regexp, $manifest_contents) = @_;
open(my $fh, '>', "$tempdir/backup_manifest") || die "open: $!";
# (won't work if we are inside a string literal!)
sub clear_query
{
+ local $Test::Builder::Level = $Test::Builder::Level + 1;
+
check_completion("\\r\n", qr/postgres=# /, "\\r works");
return;
}
# than clear_query because we lose evidence in the history file)
sub clear_line
{
+ local $Test::Builder::Level = $Test::Builder::Level + 1;
+
check_completion("\025\n", qr/postgres=# /, "control-U works");
return;
}
# 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
#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.:
# Expect to connect to $target_node (undef for failure) with given $status.
sub test_target_session_attrs
{
+ local $Test::Builder::Level = $Test::Builder::Level + 1;
+
my $node1 = shift;
my $node2 = shift;
my $target_node = shift;
# 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_primary = shift;
# 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))
sub configure_and_reload
{
+ local $Test::Builder::Level = $Test::Builder::Level + 1;
+
my ($node, $parameter) = @_;
my $name = $node->name;
sub check_orphan_relfilenodes
{
+ local $Test::Builder::Level = $Test::Builder::Level + 1;
+
my ($node, $test_name) = @_;
my $db_oid = $node->safe_psql('postgres',