Skip to content

Commit 3f484de

Browse files
author
Marina Polyakova
committed
PGPRO-5983: fix Perl tests due to changes in PostgreSQL 15devel
The standard PostgreSQL Perl modules for testing have been moved and some have been renamed. Try to maintain both old and new modules by exporting the enviromental variable VERSION_NUM and conditionally loading the required modules at compile time. We cannot load these modules at runtime because they can have INIT blocks. Also use Perl's 'eval' function to call functions from these modules so we don't get compilation errors due to conditionally loading modules. The enviromental variable PG_15_PERL_MUDULES is for running tests on Windows using MSVC because I'm not sure if it would be better to try to find and export the variable VERSION_NUM in vcregress.pl.. It also seems to be easier to just export the variable VERSION_NUM in Makefile on Linux instead of creating a version check using shell commands..
1 parent b5d2c58 commit 3f484de

File tree

2 files changed

+36
-11
lines changed

2 files changed

+36
-11
lines changed

Makefile

+5
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,8 @@ top_builddir = ../..
2020
include $(top_builddir)/src/Makefile.global
2121
include $(top_srcdir)/contrib/contrib-global.mk
2222
endif
23+
24+
# Use the enviromental variable VERSION_NUM to specify which PostgreSQL Perl
25+
# modules to load into Perl tests at compile time (we cannot use the function
26+
# 'require' to load them at runtime because they can have INIT blocks).
27+
export VERSION_NUM

t/001_basic.pl

+31-11
Original file line numberDiff line numberDiff line change
@@ -6,25 +6,45 @@
66

77
use strict;
88
use warnings;
9-
use PostgresNode;
10-
use TestLib;
119
use Test::More;
1210

13-
plan tests => 24;
11+
# We cannot use the function 'require' to conditionally load PostgreSQL modules
12+
# at runtime because they can have INIT blocks.
13+
14+
use constant PG_15_PERL_MUDULES =>
15+
((defined $ENV{VERSION_NUM} and $ENV{VERSION_NUM} >= 150000) or
16+
defined $ENV{PG_15_PERL_MUDULES});
17+
18+
use if PG_15_PERL_MUDULES, "PostgreSQL::Test::Cluster";
19+
use if PG_15_PERL_MUDULES, "PostgreSQL::Test::Utils";
20+
21+
use if (not PG_15_PERL_MUDULES), "PostgresNode";
22+
use if (not PG_15_PERL_MUDULES), "TestLib";
23+
24+
plan tests => 25;
1425

1526
my $node;
1627
my $res;
1728
my $res_stdout;
1829
my $res_stderr;
1930

20-
# Initialize node
21-
# Older version of PostgresNode.pm use get_new_node function.
22-
# Newer use standard perl object constructor syntax
23-
if (PostgresNode->can('get_new_node')) {
24-
$node = get_new_node('node');
25-
} else {
26-
$node = PostgresNode->new("node");
27-
}
31+
# Create node.
32+
# Older versions of PostgreSQL modules use get_new_node function.
33+
# Newer use standard perl object constructor syntax.
34+
$res = eval
35+
{
36+
if (PG_15_PERL_MUDULES)
37+
{
38+
$node = PostgreSQL::Test::Cluster->new("node");
39+
}
40+
else
41+
{
42+
$node = get_new_node("node");
43+
}
44+
return 1;
45+
};
46+
is($res, 1, 'the node is created successfully');
47+
2848
$node->init;
2949
$node->start;
3050

0 commit comments

Comments
 (0)