001_libpq_pipeline.pl: use Test::Differences if available
authorAlvaro Herrera <alvherre@alvh.no-ip.org>
Wed, 8 Mar 2023 17:31:55 +0000 (18:31 +0100)
committerAlvaro Herrera <alvherre@alvh.no-ip.org>
Wed, 8 Mar 2023 17:31:55 +0000 (18:31 +0100)
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>
src/test/modules/libpq_pipeline/README
src/test/modules/libpq_pipeline/t/001_libpq_pipeline.pl

index 32ad5e91bddb4a5e3c4df15165686f51f615acec..7278c761e5332d85fcea3966cc43e7f6f4b78033 100644 (file)
@@ -1,4 +1,7 @@
 Test programs and libraries for libpq
+
+If you have Test::Differences installed, any differences in the trace files
+are displayed in a format that's easier to read than the standard format.
 =====================================
 
 This module was developed to test libpq's "pipeline" mode, but it can
index e69066ee9b70de70c08e3e43736cd0e2aa7f1514..fbac405d0d16c6dec2ce26d4f44c9f2783ba394a 100644 (file)
@@ -8,6 +8,19 @@ use PostgreSQL::Test::Cluster;
 use PostgreSQL::Test::Utils;
 use Test::More;
 
+# Use Test::Differences if installed, and select unified diff output.
+# No decent way to select a context line count with this;
+# we could use a sub ref to allow that.
+BEGIN
+{
+   #<<< protect next line from pgperltidy
+   if (!eval q{ use Test::Differences; unified_diff(); 1 })    ## no critic (ProhibitStringyEval)
+   #>>>
+   {
+       *eq_or_diff = \&is;
+   }
+}
+
 my $node = PostgreSQL::Test::Cluster->new('main');
 $node->init;
 $node->start;
@@ -55,7 +68,7 @@ for my $testname (@tests)
        $result = slurp_file_eval($traceout);
        next unless $result ne "";
 
-       is($result, $expected, "$testname trace match");
+       eq_or_diff($result, $expected, "$testname trace match");
    }
 }