From 838a560926ec978fc9673a019195e2142274265d Mon Sep 17 00:00:00 2001 From: Marina Polyakova Date: Wed, 8 Dec 2021 20:39:26 +0300 Subject: [PATCH] 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 checking if we can load new modules and loading the necessary 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. --- t/001_basic.pl | 47 +++++++++++++++++++++++++++++++++++++---------- 1 file changed, 37 insertions(+), 10 deletions(-) diff --git a/t/001_basic.pl b/t/001_basic.pl index f73348d..48e0f66 100644 --- a/t/001_basic.pl +++ b/t/001_basic.pl @@ -6,25 +6,52 @@ use strict; use warnings; -use PostgresNode; -use TestLib; use Test::More; +my $pg_15_modules; + +BEGIN +{ + $pg_15_modules = eval + { + require PostgreSQL::Test::Cluster; + require PostgreSQL::Test::Utils; + return 1; + }; + + unless (defined $pg_15_modules) + { + $pg_15_modules = 0; + + require PostgresNode; + require TestLib; + } +} + plan tests => 24; +note('PostgreSQL 15 modules are used: ' . ($pg_15_modules ? 'yes' : 'no')); + my $node; my $res; my $res_stdout; my $res_stderr; -# Initialize node -# Older version of PostgresNode.pm use get_new_node function. -# Newer use standard perl object constructor syntax -if (PostgresNode->can('get_new_node')) { - $node = get_new_node('node'); -} else { - $node = PostgresNode->new("node"); -} +# Create node. +# Older versions of PostgreSQL modules use get_new_node function. +# Newer use standard perl object constructor syntax. +eval +{ + if ($pg_15_modules) + { + $node = PostgreSQL::Test::Cluster->new("node"); + } + else + { + $node = PostgresNode::get_new_node("node"); + } +}; + $node->init; $node->start;