Skip to content

Commit e8f037a

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 3a6ef0c commit e8f037a

File tree

4 files changed

+21
-91
lines changed

4 files changed

+21
-91
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 & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +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-
$use_unix_sockets
44-
);
14+
use Exporter 'import';
4515

4616
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 = {
@@ -2416,18 +2427,4 @@ sub corrupt_page_checksum
24162427
24172428
=cut
24182429

2419-
# support release 15+ perl module namespace
2420-
2421-
package PostgreSQL::Test::Cluster; ## no critic (ProhibitMultiplePackages)
2422-
2423-
sub new
2424-
{
2425-
shift; # remove class param from args
2426-
return PostgresNode->get_new_node(@_);
2427-
}
2428-
2429-
no warnings 'once';
2430-
2431-
*get_free_port = *PostgresNode::get_free_port;
2432-
24332430
1;

src/test/perl/TestLib.pm

Lines changed: 0 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -931,44 +931,4 @@ sub command_checks_all
931931
932932
=cut
933933

934-
# support release 15+ perl module namespace
935-
936-
package PostgreSQL::Test::Utils; ## no critic (ProhibitMultiplePackages)
937-
938-
# we don't want to export anything here, but we want to support things called
939-
# via this package name explicitly.
940-
941-
# use typeglobs to alias these functions and variables
942-
943-
no warnings qw(once);
944-
945-
*generate_ascii_string = *TestLib::generate_ascii_string;
946-
*slurp_dir = *TestLib::slurp_dir;
947-
*slurp_file = *TestLib::slurp_file;
948-
*append_to_file = *TestLib::append_to_file;
949-
*check_mode_recursive = *TestLib::check_mode_recursive;
950-
*chmod_recursive = *TestLib::chmod_recursive;
951-
*check_pg_config = *TestLib::check_pg_config;
952-
*system_or_bail = *TestLib::system_or_bail;
953-
*system_log = *TestLib::system_log;
954-
*run_log = *TestLib::run_log;
955-
*run_command = *TestLib::run_command;
956-
*command_ok = *TestLib::command_ok;
957-
*command_fails = *TestLib::command_fails;
958-
*command_exit_is = *TestLib::command_exit_is;
959-
*program_help_ok = *TestLib::program_help_ok;
960-
*program_version_ok = *TestLib::program_version_ok;
961-
*program_options_handling_ok = *TestLib::program_options_handling_ok;
962-
*command_like = *TestLib::command_like;
963-
*command_like_safe = *TestLib::command_like_safe;
964-
*command_fails_like = *TestLib::command_fails_like;
965-
*command_checks_all = *TestLib::command_checks_all;
966-
967-
*windows_os = *TestLib::windows_os;
968-
*use_unix_sockets = *TestLib::use_unix_sockets;
969-
*timeout_default = *TestLib::timeout_default;
970-
*tmp_check = *TestLib::tmp_check;
971-
*log_path = *TestLib::log_path;
972-
*test_logfile = *TestLib::test_log_file;
973-
974934
1;

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy