8000 For PostgreSQL::Test compatibility, alias entire package symbol tables. · postgres/postgres@c41edb3 · GitHub
[go: up one dir, main page]

Skip to content

Commit c41edb3

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 ed2a7a6 commit c41edb3

File tree

4 files changed

+21
-87
lines changed

4 files changed

+21
-87
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 & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +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-
pump_until
29-
30-
command_ok
31-
command_fails
32-
command_exit_is
33-
program_help_ok
34-
program_version_ok
35-
program_options_handling_ok
36-
command_like
37-
command_like_safe
38-
command_fails_like
39-
command_checks_all
40-
41-
$windows_os
42-
);
14+
use Exporter 'import';
4315

4416
1;

src/test/perl/PostgresNode.pm

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,17 @@ of finding port numbers, registering instances for cleanup, etc.
154154
sub new
155155
{
156156
my ($class, $name, $pghost, $pgport) = @_;
157+
158+
# Use release 15+ semantics when the arguments look like (node_name,
159+
# %params). We can't use $class to decide, because get_new_node() passes
160+
# a v14- argument list regardless of the class. $class might be an
161+
# out-of-core subclass. $class->isa('PostgresNode') returns true even for
162+
# descendants of PostgreSQL::Test::Cluster, so it doesn't help.
163+
return $class->get_new_node(@_[ 1 .. $#_ ])
164+
if !$pghost
165+
or !$pgport
166+
or $pghost =~ /^[a-zA-Z0-9_]$/;
167+
157168
my $testname = basename($0);
158169
$testname =~ s/\.[^.]+$//;
159170
my $self = {
@@ -2297,18 +2308,4 @@ sub corrupt_page_checksum
22972308
22982309
=cut
22992310

2300-
# support release 15+ perl module namespace
2301-
2302-
package PostgreSQL::Test::Cluster; ## no critic (ProhibitMultiplePackages)
2303-
2304-
sub new
2305-
{
2306-
shift; # remove class param from args
2307-
return PostgresNode->get_new_node(@_);
2308-
}
2309-
2310-
no warnings 'once';
2311-
2312-
*get_free_port = *PostgresNode::get_free_port;
2313-
23142311
1;

src/test/perl/TestLib.pm

Lines changed: 0 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -628,42 +628,4 @@ sub command_checks_all
628628
return;
629629
}
630630

631-
# support release 15+ perl module namespace
632-
633-
package PostgreSQL::Test::Utils; ## no critic (ProhibitMultiplePackages)
634-
635-
# we don't want to export anything here, but we want to support things called
636-
# via this package name explicitly.
637-
638-
# use typeglobs to alias these functions and variables
639-
640-
no warnings qw(once);
641-
642-
*generate_ascii_string = *TestLib::generate_ascii_string;
643-
*slurp_dir = *TestLib::slurp_dir;
644-
*slurp_file = *TestLib::slurp_file;
645-
*append_to_file = *TestLib::append_to_file;
646-
*check_mode_recursive = *TestLib::check_mode_recursive;
647-
*chmod_recursive = *TestLib::chmod_recursive;
648-
*check_pg_config = *TestLib::check_pg_config;
649-
*system_or_bail = *TestLib::system_or_bail;
650-
*system_log = *TestLib::system_log;
651-
*run_log = *TestLib::run_log;
652-
*command_ok = *TestLib::command_ok;
653-
*command_fails = *TestLib::command_fails;
654-
*command_exit_is = *TestLib::command_exit_is;
655-
*program_help_ok = *TestLib::program_help_ok;
656-
*program_version_ok = *TestLib::program_version_ok;
657-
*program_options_handling_ok = *TestLib::program_options_handling_ok;
658-
*command_like = *TestLib::command_like;
659-
*command_like_safe = *TestLib::command_like_safe;
660-
*command_fails_like = *TestLib::command_fails_like;
661-
*command_checks_all = *TestLib::command_checks_all;
662-
663-
*windows_os = *TestLib::windows_os;
664-
*timeout_default = *TestLib::timeout_default;
665-
*tmp_check = *TestLib::tmp_check;
666-
*log_path = *TestLib::log_path;
667-
*test_logfile = *TestLib::test_log_file;
668-
669631
1;

0 commit comments

Comments
 (0)
0