On 2022-04-19 Tu 11:36, Andrew Dunstan wrote: > On 2022-04-18 Mo 14:07, Tom Lane wrote: >> Andrew Dunstan <and...@dunslane.net> writes: >>> No, I think we could probably just port the whole of src/test/PostreSQL >>> back if required, and have it live alongside the old modules. Each TAP >>> test is a separate miracle - see comments elsewhere about port >>> assignment in parallel TAP tests. >>> But that would mean we have some tests in the old flavor and some in the >>> new flavor in the back branches, which might get confusing. >> That works for back-patching entire new test scripts, but not for adding >> some cases to an existing script, which I think is more common. >> >> > > I think I've come up with a better scheme that I hope will fix all or > almost all of the pain complained of in this thread. I should note that > we deliberately delayed making these changes until fairly early in the > release 15 development cycle, and that was clearly a good decision. > > The attached three patches basically implement the new naming scheme for > the back branches without doing away with the old scheme or doing a > wholesale copy of the new modules. > > The first simply implements a proper "new" constructor for PostgresNode, > just like we have in PostgreSQL:Test::Cluster. It's not really essential > but it seems like a good idea. The second adds all the visible > functionality of the PostgresNode and TestLib modules to the > PostgreSQL::Test::Cluster and PostgreSQL::Test::Utils namespaces.. The > third adds dummy packages so that any code doing 'use > PostgreSQL::Test::Utils;' or 'use PostgreSQL::Test::Cluster;' will > actually import the old modules. This last piece is where there might be > some extra work needed, to export the names so that using an unqualified > function or variable, say, 'slurp_file("foo");' will work. But in > general, modulo that issue, I believe things should Just Work (tm). You > should basically just be able to backpatch any new or modified TAP test > without difficulty, sed script usage, etc. > > Comments welcome. > >
Here's a version with a fixed third patch that corrects a file misnaming and fixes the export issue referred to above. Passes my testing so far. cheers andrew -- Andrew Dunstan EDB: https://www.enterprisedb.com
diff --git a/src/test/perl/PostgresNode.pm b/src/test/perl/PostgresNode.pm index 92d9303e23..94b39341ce 100644 --- a/src/test/perl/PostgresNode.pm +++ b/src/test/perl/PostgresNode.pm @@ -137,16 +137,22 @@ INIT =over -=item PostgresNode::new($class, $name, $pghost, $pgport) +=item PostgresNode->new(node_name, %params) -Create a new PostgresNode instance. Does not initdb or start it. - -You should generally prefer to use get_new_node() instead since it takes care -of finding port numbers, registering instances for cleanup, etc. +Class oriented alias for get_new_node() =cut sub new +{ + my $class = $_[0]; + $class->isa(__PACKAGE__) || die "new() not called as a class method"; + return get_new_node(@_); +} + +# internal subroutine used by get_new_node(). SHould not be called by any +# external client of the module. +sub _new { my ($class, $name, $pghost, $pgport) = @_; my $testname = basename($0); @@ -1229,7 +1235,7 @@ sub get_new_node } # Lock port number found by creating a new node - my $node = $class->new($name, $host, $port); + my $node = _new($class, $name, $host, $port); if ($params{install_path}) {
diff --git a/src/test/perl/PostgresNode.pm b/src/test/perl/PostgresNode.pm index 92d9303e23..f5d2ba72e6 100644 --- a/src/test/perl/PostgresNode.pm +++ b/src/test/perl/PostgresNode.pm @@ -2761,4 +2761,16 @@ sub corrupt_page_checksum =cut +# support release 15+ perl module namespace + +package PostgreSQL::Test::Cluster; + +sub new +{ + shift; # remove class param from args + return PostgresNode->get_new_node(@_); +} + +sub get_free_port { return PostgresNode::get_free_port(); } + 1; diff --git a/src/test/perl/TestLib.pm b/src/test/perl/TestLib.pm index 0dfc414b07..92583f84b4 100644 --- a/src/test/perl/TestLib.pm +++ b/src/test/perl/TestLib.pm @@ -948,4 +948,46 @@ sub command_checks_all =cut +# support release 15+ perl module namespace + +package PostgreSQL::Test::Utils; + +# we don't want to export anything, but we want to support things called +# via this package name explicitly. + +# use typeglobs to alias these functions and variables + +*generate_ascii_string = *TestLib::generate_ascii_string; +*slurp_dir = *TestLib::slurp_dir; +*slurp_file = *TestLib::slurp_file; +*append_to_file = *TestLib::append_to_file; +*check_mode_recursive = *TestLib::check_mode_recursive; +*chmod_recursive = *TestLib::chmod_recursive; +*check_pg_config = *TestLib::check_pg_config; +*dir_symlink = *TestLib::dir_symlink; +*system_or_bail = *TestLib::system_or_bail; +*system_log = *TestLib::system_log; +*run_log = *TestLib::run_log; +*run_command = *TestLib::run_command; +sub pump_until { die "pump_until not implemented in TestLib"; } +*command_ok = *TestLib::command_ok; +*command_fails = *TestLib::command_fails; +*command_exit_is = *TestLib::command_exit_is; +*program_help_ok = *TestLib::program_help_ok; +*program_version_ok = *TestLib::program_version_ok; +*program_options_handling_ok = *TestLib::program_options_handling_ok; +*command_like = *TestLib::command_like; +*command_like_safe = *TestLib::command_like_safe; +*command_fails_like = *TestLib::command_fails_like; +*command_checks_all = *TestLib::command_checks_all; + +*windows_os = *TestLib::windows_os; +*is_msys2 = *TestLib::is_msys2; +*use_unix_sockets = *TestLib::use_unix_sockets; +*timeout_default = *TestLib::timeout_default; +*tmp_check = *TestLib::tmp_check; +*log_path = *TestLib::log_path; +*test_logfile = *TestLib::test_log_file; + + 1;
diff --git a/src/test/perl/PostgreSQL/Test/Cluster.pm b/src/test/perl/PostgreSQL/Test/Cluster.pm new file mode 100644 index 0000000000..1e2fb50d6d --- /dev/null +++ b/src/test/perl/PostgreSQL/Test/Cluster.pm @@ -0,0 +1,16 @@ + +# Copyright (c) 2022, PostgreSQL Global Development Group + +# allow use of release 15+ perl namespace in older branches +# just 'use' the older module name. +# See PostgresNode.pm for function implementations + +package PostgreSQL::Test::Cluster; + +use strict; +use warnings; + +use PostgresNode; + +1; + diff --git a/src/test/perl/PostgreSQL/Test/Utils.pm b/src/test/perl/PostgreSQL/Test/Utils.pm new file mode 100644 index 0000000000..bdbbd6e470 --- /dev/null +++ b/src/test/perl/PostgreSQL/Test/Utils.pm @@ -0,0 +1,48 @@ +# Copyright (c) 2022, PostgreSQL Global Development Group + +# allow use of release 15+ perl namespace in older branches +# just 'use' the older module name. +# We export the same names as the v15 module. +# See TestLib.pm for alias assignment that makes this all work. + +package PostgreSQL::Test::Utils; + +use strict; +use warnings; + +use Exporter 'import'; + +use TestLib; + +our @EXPORT = qw( + generate_ascii_string + slurp_dir + slurp_file + append_to_file + check_mode_recursive + chmod_recursive + check_pg_config + dir_symlink + system_or_bail + system_log + run_log + run_command + pump_until + + command_ok + command_fails + command_exit_is + program_help_ok + program_version_ok + program_options_handling_ok + command_like + command_like_safe + command_fails_like + command_checks_all + + $windows_os + $is_msys2 + $use_unix_sockets +); + +1;