Skip to content

Commit ec26f44

Browse files
committed
For PostgreSQL::Test compatibility, alias entire package symbol tables.
Remove the need to edit back-branch-specific code sites when back-patching the addition of a PostgreSQL::Test::Utils symbol. Replace per-symbol, incomplete alias lists. Give old and new package names the same EXPORT and EXPORT_OK semantics. Back-patch to v10 (all supported versions). Reviewed by Andrew Dunstan. Discussion: https://postgr.es/m/20220622072144.GD4167527@rfd.leadboat.com
1 parent 9e0d9a2 commit ec26f44

File tree

4 files changed

+21
-89
lines changed

4 files changed

+21
-89
lines changed
Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,18 @@
11

22
# Copyright (c) 2022, PostgreSQL Global Development Group
33

4-
# allow use of release 15+ perl namespace in older branches
5-
# just 'use' the older module name.
6-
# See PostgresNode.pm for function implementations
4+
# Allow use of release 15+ Perl package name in older branches, by giving that
5+
# package the same symbol table as the older package. See PostgresNode::new
6+
# for supporting heuristics.
77

88
package PostgreSQL::Test::Cluster;
99

1010
use strict;
1111
use warnings;
1212

1313
use PostgresNode;
14+
BEGIN { *PostgreSQL::Test::Cluster:: = \*PostgresNode::; }
15+
16+
use Exporter 'import';
1417

1518
1;
Lines changed: 4 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,16 @@
11
# Copyright (c) 2022, PostgreSQL Global Development Group
22

3-
# allow use of release 15+ perl namespace in older branches
4-
# just 'use' the older module name.
5-
# We export the same names as the v15 module.
6-
# See TestLib.pm for alias assignment that makes this all work.
3+
# Allow use of release 15+ Perl package name in older branches, by giving that
4+
# package the same symbol table as the older package.
75

86
package PostgreSQL::Test::Utils;
97

108
use strict;
119
use warnings;
1210

13-
use Exporter 'import';
14-
1511
use TestLib;
12+
BEGIN { *PostgreSQL::Test::Utils:: = \*TestLib::; }
1613

17-
our @EXPORT = qw(
18-
generate_ascii_string
19-
slurp_dir
20-
slurp_file
21-
append_to_file
22-
check_mode_recursive
23-
chmod_recursive
24-
check_pg_config
25-
system_or_bail
26-
system_log
27-
run_log
28-
run_command
29-
pump_until
30-
31-
command_ok
32-
command_fails
33-
command_exit_is
34-
program_help_ok
35-
program_version_ok
36-
program_options_handling_ok
37-
command_like
38-
command_like_safe
39-
command_fails_like
40-
command_checks_all
41-
42-
$windows_os
43-
);
14+
use Exporter 'import';
4415

4516
1;

src/test/perl/PostgresNode.pm

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,17 @@ of finding port numbers, registering instances for cleanup, etc.
146146
sub new
147147
{
148148
my ($class, $name, $pghost, $pgport) = @_;
149+
150+
# Use release 15+ semantics when the arguments look like (node_name,
151+
# %params). We can't use $class to decide, because get_new_node() passes
152+
# a v14- argument list regardless of the class. $class might be an
153+
# out-of-core subclass. $class->isa('PostgresNode') returns true even for
154+
# descendants of PostgreSQL::Test::Cluster, so it doesn't help.
155+
return $class->get_new_node(@_[ 1 .. $#_ ])
156+
if !$pghost
157+
or !$pgport
158+
or $pghost =~ /^[a-zA-Z0-9_]$/;
159+
149160
my $testname = basename($0);
150161
$testname =~ s/\.[^.]+$//;
151162
my $self = {
@@ -2307,18 +2318,4 @@ sub corrupt_page_checksum
23072318
23082319
=cut
23092320

2310-
# support release 15+ perl module namespace
2311-
2312-
package PostgreSQL::Test::Cluster; ## no critic (ProhibitMultiplePackages)
2313-
2314-
sub new
2315-
{
2316-
shift; # remove class param from args
2317-
return PostgresNode->get_new_node(@_);
2318-
}
2319-
2320-
no warnings 'once';
2321-
2322-
*get_free_port = *PostgresNode::get_free_port;
2323-
23242321
1;

src/test/perl/TestLib.pm

Lines changed: 0 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -652,43 +652,4 @@ sub command_checks_all
652652
return;
653653
}
654654

655-
# support release 15+ perl module namespace
656-
657-
package PostgreSQL::Test::Utils; ## no critic (ProhibitMultiplePackages)
658-
659-
# we don't want to export anything here, but we want to support things called
660-
# via this package name explicitly.
661-
662-
# use typeglobs to alias these functions and variables
663-
664-
no warnings qw(once);
665-
666-
*generate_ascii_string = *TestLib::generate_ascii_string;
667-
*slurp_dir = *TestLib::slurp_dir;
668-
*slurp_file = *TestLib::slurp_file;
669-
*append_to_file = *TestLib::append_to_file;
670-
*check_mode_recursive = *TestLib::check_mode_recursive;
671-
*chmod_recursive = *TestLib::chmod_recursive;
672-
*check_pg_config = *TestLib::check_pg_config;
673-
*system_or_bail = *TestLib::system_or_bail;
674-
*system_log = *TestLib::system_log;
675-
*run_log = *TestLib::run_log;
676-
*run_command = *TestLib::run_command;
677-
*command_ok = *TestLib::command_ok;
678-
*command_fails = *TestLib::command_fails;
679-
*command_exit_is = *TestLib::command_exit_is;
680-
*program_help_ok = *TestLib::program_help_ok;
681-
*program_version_ok = *TestLib::program_version_ok;
682-
*program_options_handling_ok = *TestLib::program_options_handling_ok;
683-
*command_like = *TestLib::command_like;
684-
*command_like_safe = *TestLib::command_like_safe;
685-
*command_fails_like = *TestLib::command_fails_like;
686-
*command_checks_all = *TestLib::command_checks_all;
687-
688-
*windows_os = *TestLib::windows_os;
689-
*timeout_default = *TestLib::timeout_default;
690-
*tmp_check = *TestLib::tmp_check;
691-
*log_path = *TestLib::log_path;
692-
*test_logfile = *TestLib::test_log_file;
693-
694655
1;

0 commit comments

Comments
 (0)