Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 2091177

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 3238b5c commit 2091177

File tree

4 files changed

+21
-95
lines changed

4 files changed

+21
-95
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 & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +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-
dir_symlink
26-
system_or_bail
27-
system_log
28-
run_log
29-
run_command
30-
pump_until
31-
32-
command_ok
33-
command_fails
34-
command_exit_is
35-
program_help_ok
36-
program_version_ok
37-
program_options_handling_ok
38-
command_like
39-
command_like_safe
40-
command_fails_like
41-
command_checks_all
42-
43-
$windows_os
44-
$is_msys2
45-
$use_unix_sockets
46-
);
14+
use Exporter 'import';
4715

4816
1;

src/test/perl/PostgresNode.pm

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

2799-
# support release 15+ perl module namespace
2800-
2801-
package PostgreSQL::Test::Cluster; ## no critic (ProhibitMultiplePackages)
2802-
2803-
sub new
2804-
{
2805-
shift; # remove class param from args
2806-
return PostgresNode->get_new_node(@_);
2807-
}
2808-
2809-
no warnings 'once';
2810-
2811-
*get_free_port = *PostgresNode::get_free_port;
2812-
28132810
1;

src/test/perl/TestLib.pm

Lines changed: 0 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -979,46 +979,4 @@ sub command_checks_all
979979
980980
=cut
981981

982-
# support release 15+ perl module namespace
983-
984-
package PostgreSQL::Test::Utils; ## no critic (ProhibitMultiplePackages)
985-
986-
# we don't want to export anything here, but we want to support things called
987-
# via this package name explicitly.
988-
989-
# use typeglobs to alias these functions and variables
990-
991-
no warnings qw(once);
992-
993-
*generate_ascii_string = *TestLib::generate_ascii_string;
994-
*slurp_dir = *TestLib::slurp_dir;
995-
*slurp_file = *TestLib::slurp_file;
996-
*append_to_file = *TestLib::append_to_file;
997-
*check_mode_recursive = *TestLib::check_mode_recursive;
998-
*chmod_recursive = *TestLib::chmod_recursive;
999-
*check_pg_config = *TestLib::check_pg_config;
1000-
*dir_symlink = *TestLib::dir_symlink;
1001-
*system_or_bail = *TestLib::system_or_bail;
1002-
*system_log = *TestLib::system_log;
1003-
*run_log = *TestLib::run_log;
1004-
*run_command = *TestLib::run_command;
1005-
*command_ok = *TestLib::command_ok;
1006-
*command_fails = *TestLib::command_fails;
1007-
*command_exit_is = *TestLib::command_exit_is;
1008-
*program_help_ok = *TestLib::program_help_ok;
1009-
*program_version_ok = *TestLib::program_version_ok;
1010-
*program_options_handling_ok = *TestLib::program_options_handling_ok;
1011-
*command_like = *TestLib::command_like;
1012-
*command_like_safe = *TestLib::command_like_safe;
1013-
*command_fails_like = *TestLib::command_fails_like;
1014-
*command_checks_all = *TestLib::command_checks_all;
1015-
1016-
*windows_os = *TestLib::windows_os;
1017-
*is_msys2 = *TestLib::is_msys2;
1018-
*use_unix_sockets = *TestLib::use_unix_sockets;
1019-
*timeout_default = *TestLib::timeout_default;
1020-
*tmp_check = *TestLib::tmp_check;
1021-
*log_path = *TestLib::log_path;
1022-
*test_logfile = *TestLib::test_log_file;
1023-
1024982
1;

0 commit comments

Comments
 (0)