Re: Small TAP improvements

From: Andrew Dunstan <andrew(at)dunslane(dot)net>
To: Michael Paquier <michael(at)paquier(dot)xyz>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Álvaro Herrera <alvherre(at)alvh(dot)no-ip(dot)org>, "pgsql-hackers(at)lists(dot)postgresql(dot)org" <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: Small TAP improvements
Date: 2022-06-15 11:59:10
Message-ID: 193b30e3-49a8-185c-e39f-5d2d9e3fdbff@dunslane.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers


On 2022-06-14 Tu 19:24, Michael Paquier wrote:
> On Tue, Jun 14, 2022 at 05:08:28PM -0400, Tom Lane wrote:
>> Andrew Dunstan <andrew(at)dunslane(dot)net> writes:
>>> 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;
>> Might be overkill, but since you wrote it already, looks OK to me.
> + # 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);
> + }
>
> This patch is able to handle the case of no option and one option
> specified by the caller of the routine. However, pg_config is able to
> return a set of values when specifying multiple switches, respecting
> the order of the switches, so wouldn't it be better to return a map
> made of ($option, $line)? For example, on a command like `pg_config
> --sysconfdir --`, we would get back:
> (('--sysconfdir', sysconfdir_val), ('--localedir', localedir_val))
>
> If this is not worth the trouble, I think that you'd better die() hard
> if the caller specifies more than two option switches.

My would we do that? If you want a map don't pass any switches. But as
written you could do:

my ($incdir, $localedir, $sharedir) = $node->config_data(qw(--includedir --localedir --sharedir));

No map needed to get what you want, in fact a map would get in the way.

cheers

andrew

--
Andrew Dunstan
EDB: https://www.enterprisedb.com

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Andrew Dunstan 2022-06-15 12:11:40 Re: Small TAP improvements
Previous Message Daniel Verite 2022-06-15 11:50:14 Re: Add header support to text format and matching feature