Re: Small TAP improvements

From: Michael Paquier <michael(at)paquier(dot)xyz>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Andrew Dunstan <andrew(at)dunslane(dot)net>, Á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-14 23:24:00
Message-ID: YqkYkP67FyWC+JYI@paquier.xyz
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

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.
--
Michael

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Zheng Li 2022-06-15 00:14:14 Re: Support logical replication of DDLs
Previous Message Michael Paquier 2022-06-14 23:13:02 Re: Small TAP improvements