Re: Small TAP improvements - Mailing list pgsql-hackers

From Michael Paquier
Subject Re: Small TAP improvements
Date
Msg-id YqkYkP67FyWC+JYI@paquier.xyz
Whole thread Raw
In response to Re: Small TAP improvements  (Tom Lane <tgl@sss.pgh.pa.us>)
Responses Re: Small TAP improvements
List pgsql-hackers
On Tue, Jun 14, 2022 at 05:08:28PM -0400, Tom Lane wrote:
> Andrew Dunstan <andrew@dunslane.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

Attachment

pgsql-hackers by date:

Previous
From: Michael Paquier
Date:
Subject: Re: Small TAP improvements
Next
From: Zheng Li
Date:
Subject: Re: Support logical replication of DDLs