summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlvaro Herrera2023-03-08 17:31:55 +0000
committerAlvaro Herrera2023-03-08 17:31:55 +0000
commit87e4f24d82939ef532b68f37fc66e6a48cff2cd9 (patch)
tree3a5f7df1bb5831e2ac4f165bd2a215a74b6022a5
parent30a53b792959b36f07200dae246067b3adbcc0b9 (diff)
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/[email protected] Reviewed-by: Kyotaro Horiguchi <[email protected]>
-rw-r--r--src/test/modules/libpq_pipeline/README3
-rw-r--r--src/test/modules/libpq_pipeline/t/001_libpq_pipeline.pl15
2 files changed, 17 insertions, 1 deletions
diff --git a/src/test/modules/libpq_pipeline/README b/src/test/modules/libpq_pipeline/README
index 32ad5e91bdd..7278c761e53 100644
--- a/src/test/modules/libpq_pipeline/README
+++ b/src/test/modules/libpq_pipeline/README
@@ -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
diff --git a/src/test/modules/libpq_pipeline/t/001_libpq_pipeline.pl b/src/test/modules/libpq_pipeline/t/001_libpq_pipeline.pl
index e69066ee9b7..fbac405d0d1 100644
--- a/src/test/modules/libpq_pipeline/t/001_libpq_pipeline.pl
+++ b/src/test/modules/libpq_pipeline/t/001_libpq_pipeline.pl
@@ -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");
}
}