On 2022-06-14 Tu 12:44, Álvaro Herrera wrote: > The comment atop config_data still mentions $option, but after the patch > that's no longer a name used in the function. (I have to admit that using @_ > in the body of the function was a little bit confusing to me at first. Did > you do that in order to allow multiple options to be passed?) > > Also: if you give an option to pg_config, the output is not prefixed with the > variable name. So you don't need to strip the "SHAREDIR =" bit: there isn't > any. This is true even if you give multiple options: > > schmee: master 0$ pg_config --sharedir --includedir > /home/alvherre/Code/pgsql-install/REL9_6_STABLE/share > /home/alvherre/Code/pgsql-install/REL9_6_STABLE/include
OK, here's a more principled couple of patches. For config_data, if you give multiple options it gives you back the list of values. If you don't specify any, in scalar context it just gives you back all of pg_config's output, but in array context it gives you a map, so you should be able to say things like: my %node_config = $node->config_data; cheers andrew -- Andrew Dunstan EDB: https://www.enterprisedb.com
From 0cd2682561f37bfe9b316c5806db1d3526aa21c9 Mon Sep 17 00:00:00 2001 From: Andrew Dunstan <and...@dunslane.net> Date: Mon, 13 Jun 2022 18:16:33 -0400 Subject: [PATCH v2 1/2] Make config_data method more flexible. If given a single option, return the value as now. If given multiple options return the list of values. If given no options at all return the output in a single string in scalar context, or a map in array context. --- src/test/perl/PostgreSQL/Test/Cluster.pm | 35 ++++++++++++++++++------ 1 file changed, 27 insertions(+), 8 deletions(-) diff --git a/src/test/perl/PostgreSQL/Test/Cluster.pm b/src/test/perl/PostgreSQL/Test/Cluster.pm index c8c7bc5045..2a142e97f5 100644 --- a/src/test/perl/PostgreSQL/Test/Cluster.pm +++ b/src/test/perl/PostgreSQL/Test/Cluster.pm @@ -345,27 +345,46 @@ sub pg_version =pod -=item $node->config_data($option) +=item $node->config_data( option ...) -Return a string holding configuration data from pg_config, with $option -being the option switch used with the pg_config command. +Return configuration data from pg_config, using options (if supplied). +The options will be things like '--sharedir'. + +If no options are supplied, return a string in scalar context or a map in +array context. + +If options are supplied, return the list of values. =cut sub config_data { - my ($self, $option) = @_; + my ($self, @options) = @_; local %ENV = $self->_get_env(); my ($stdout, $stderr); my $result = - IPC::Run::run [ $self->installed_command('pg_config'), $option ], + IPC::Run::run [ $self->installed_command('pg_config'), @options ], '>', \$stdout, '2>', \$stderr or die "could not execute pg_config"; + # standardize line endings + $stdout =~ s/\r(?=\n)//g; + # no options, scalar context: just hand back the output + return $stdout unless (wantarray || @options); chomp($stdout); - $stdout =~ s/\r$//; - - return $stdout; + # exactly one option: hand back the output (minus LF) + return $stdout if (@options == 1); + my @lines = split(/\n/, $stdout); + # more than one option: hand back the list of values; + return @lines if (@options); + # no options, array context: return a map + my @map; + foreach my $line (@lines) + { + my ($k,$v) = split (/ = /,$line,2); + push(@map, $k, $v); + } + return @map; } =pod -- 2.25.1
From ef9dad29f31469fb3f4befd02258c97d32670ac7 Mon Sep 17 00:00:00 2001 From: Andrew Dunstan <and...@dunslane.net> Date: Mon, 13 Jun 2022 18:19:39 -0400 Subject: [PATCH v2 2/2] Use installed postgresql.conf.sample for GUC sanity TAP test The current code looks for the sample file in the source directory, but it seems better to test against the installed sample file. --- src/test/modules/test_misc/t/003_check_guc.pl | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/test/modules/test_misc/t/003_check_guc.pl b/src/test/modules/test_misc/t/003_check_guc.pl index 60459ef759..1786cd1929 100644 --- a/src/test/modules/test_misc/t/003_check_guc.pl +++ b/src/test/modules/test_misc/t/003_check_guc.pl @@ -33,10 +33,9 @@ my $not_in_sample = $node->safe_psql( ORDER BY 1"); my @not_in_sample_array = split("\n", lc($not_in_sample)); -# TAP tests are executed in the directory of the test, in the source tree, -# even for VPATH builds, so rely on that to find postgresql.conf.sample. -my $rootdir = "../../../.."; -my $sample_file = "$rootdir/src/backend/utils/misc/postgresql.conf.sample"; +# use the sample file from the temp install +my $share_dir = $node->config_data('--sharedir'); +my $sample_file = "$share_dir/postgresql.conf.sample"; # List of all the GUCs found in the sample file. my @gucs_in_file; -- 2.25.1