Обсуждение: pgsql: 001_libpq_pipeline.pl: use Test::Differences if available
001_libpq_pipeline.pl: use Test::Differences if available When one of these tests fails to match the trace, this better shows what the problem is. Discussion: https://postgr.es/m/20220617183150.ilgokxp22mzywnhh@alvherre.pgsql Reviewed-by: Kyotaro Horiguchi <horikyota.ntt@gmail.com> Branch ------ master Details ------- https://git.postgresql.org/pg/commitdiff/87e4f24d82939ef532b68f37fc66e6a48cff2cd9 Modified Files -------------- src/test/modules/libpq_pipeline/README | 3 +++ src/test/modules/libpq_pipeline/t/001_libpq_pipeline.pl | 15 ++++++++++++++- 2 files changed, 17 insertions(+), 1 deletion(-)
On 2023-03-08 We 12:42, Alvaro Herrera wrote: > 001_libpq_pipeline.pl: use Test::Differences if available > > When one of these tests fails to match the trace, this better shows what > the problem is. > > Discussion: https://postgr.es/m/20220617183150.ilgokxp22mzywnhh@alvherre.pgsql > Reviewed-by: Kyotaro Horiguchi <horikyota.ntt@gmail.com> I don't think you need a stringy eval here, and they are something to be avoided in general. If you use `require` instead of `use` it should be unnecessary, and you can avoid all the perltidy ugliness. something like this should do the trick: eval { require Test::Differences; Test::Differences->import; unified_diff; 1; }; *eq_or_diff = \&is if $@; I wonder if it's worth centralizing this. cheers andrew -- Andrew Dunstan EDB: https://www.enterprisedb.com
On 2023-Mar-08, Andrew Dunstan wrote:
> I don't think you need a stringy eval here, and they are something to be
> avoided in general. If you use `require` instead of `use` it should be
> unnecessary, and you can avoid all the perltidy ugliness.
>
> something like this should do the trick:
>
>
> eval { require Test::Differences; Test::Differences->import;
> unified_diff; 1; };
>
> *eq_or_diff = \&is if $@;
Hmm, I just grabbed the code from the Test::Differences manual, but I
agree that avoiding the stringy eval is better. Let me try it out.
> I wonder if it's worth centralizing this.
I had a look around to see what might benefit from this. At first I
thought the ugly pg_dump test would, but it doesn't because it uses
like/unlike, not 'is'. Same with PostgreSQL::Test::Utils' command_like
and such: AFAICS they are all matching stdout on regexps.
--
Álvaro Herrera PostgreSQL Developer — https://www.EnterpriseDB.com/
"El que vive para el futuro es un iluso, y el que vive para el pasado,
un imbécil" (Luis Adler, "Los tripulantes de la noche")
On 2023-Mar-09, Alvaro Herrera wrote:
> On 2023-Mar-08, Andrew Dunstan wrote:
>
> > something like this should do the trick:
> >
> >
> > eval { require Test::Differences; Test::Differences->import;
> > unified_diff; 1; };
> >
> > *eq_or_diff = \&is if $@;
>
> Hmm, I just grabbed the code from the Test::Differences manual, but I
> agree that avoiding the stringy eval is better. Let me try it out.
It seemed to work fine for me, so pushed. Thanks for the suggestion.
--
Álvaro Herrera 48°01'N 7°57'E — https://www.EnterpriseDB.com/