]> git.ipfire.org Git - thirdparty/postgresql.git/commitdiff
perl tap: Show die reason in TAP output
authorAndrew Dunstan <andrew@dunslane.net>
Wed, 1 Apr 2026 17:54:41 +0000 (13:54 -0400)
committerAndrew Dunstan <andrew@dunslane.net>
Thu, 2 Apr 2026 12:13:44 +0000 (08:13 -0400)
Install a $SIG{__DIE__} handler in the INIT block of Utils.pm that emits
the die message as a TAP diagnostic.  Previously, an unexpected die
(e.g. from safe_psql) produced only "no plan was declared" with no
indication of the actual error.  The handler also calls done_testing()
to suppress that confusing message.

Dies during compilation ($^S undefined) and inside eval ($^S == 1) are
left alone.

Author: Jelte Fennema-Nio <postgres@jeltef.nl>
Reviewed-by: Andrew Dunstan <andrew@dunslane.net>
Reviewed-by: Corey Huinker <corey.huinker@gmail.com>
Reviewed-by: Zsolt Parragi <zsolt.parragi@percona.com>
Reviewed-by: Nazir Bilal Yavuz <byavuz81@gmail.com>
Reviewed-by: Andres Freund <andres@anarazel.de>
Discussion: https://postgr.es/m/DFYFWM053WHS.10K8ZPJ605UFK@jeltef.nl
Discussion: https://postgr.es/m/20220222181924.eehi7o4pmneeb4hm%40alap3.anarazel.de

src/test/perl/PostgreSQL/Test/Utils.pm

index b781d76a98bfb2925981cfb07e712bd6ed49e053..e87df9b45e736f1168890534ca0faca7d88eb5e0 100644 (file)
@@ -244,6 +244,24 @@ INIT
        autoflush STDOUT 1;
        autoflush STDERR 1;
        autoflush $testlog 1;
+
+       # Because of the above redirection the tap output wouldn't contain
+       # information about tests failing due to die etc. Fix that by also
+       # printing the failure to the original stderr.
+       $SIG{__DIE__} = sub {
+               # Ignore dies because of syntax errors, those will be displayed
+               # correctly anyway.
+               return if !defined $^S;
+
+               # Ignore dies inside evals
+               return if $^S == 1;
+
+               diag("die: $_[0]");
+               # Also call done_testing() to avoid the confusing "no plan was declared"
+               # message in TAP output when a test dies.
+               eval { done_testing(); }
+       };
+
 }
 
 END