pgsql: 001_libpq_pipeline.pl: use Test::Differences if available

Started by Alvaro Herreraover 3 years ago4 messagescomitters
Jump to latest
#1Alvaro Herrera
alvherre@2ndquadrant.com

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: /messages/by-id/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(-)

#2Andrew Dunstan
andrew@dunslane.net
In reply to: Alvaro Herrera (#1)
Re: pgsql: 001_libpq_pipeline.pl: use Test::Differences if available

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: /messages/by-id/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

#3Alvaro Herrera
alvherre@2ndquadrant.com
In reply to: Andrew Dunstan (#2)
Re: pgsql: 001_libpq_pipeline.pl: use Test::Differences if available

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")

#4Alvaro Herrera
alvherre@2ndquadrant.com
In reply to: Alvaro Herrera (#3)
Re: pgsql: 001_libpq_pipeline.pl: use Test::Differences if available

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/