When a TAP file has non-zero exit status, retain temporary directories.
authorNoah Misch <noah@leadboat.com>
Wed, 5 Feb 2020 16:26:41 +0000 (08:26 -0800)
committerNoah Misch <noah@leadboat.com>
Wed, 5 Feb 2020 16:26:44 +0000 (08:26 -0800)
PostgresNode already retained base directories in such cases.  Stop
using $SIG{__DIE__}, which is redundant with the exit status check, in
lieu of proliferating it to TestLib.  Back-patch to 9.6, where commit
88802e068017bee8cea7a5502a712794e761c7b5 introduced retention on
failure.

Reviewed by Daniel Gustafsson.

Discussion: https://postgr.es/m/20200202170155.GA3264196@rfd.leadboat.com

src/test/perl/PostgresNode.pm
src/test/perl/TestLib.pm

index 32825414f8e8242cfce6cf8ccf505da592f940e0..bbb31d3a0d1776d1d6d2e66c9c9de7721e119402 100644 (file)
@@ -1157,20 +1157,6 @@ sub can_bind
    return $ret;
 }
 
-# Retain the errno on die() if set, else assume a generic errno of 1.
-# This will instruct the END handler on how to handle artifacts left
-# behind from tests.
-$SIG{__DIE__} = sub {
-   if ($!)
-   {
-       $died = $!;
-   }
-   else
-   {
-       $died = 1;
-   }
-};
-
 # Automatically shut down any still-running nodes when the test script exits.
 # Note that this just stops the postmasters (in the same order the nodes were
 # created in).  Any temporary directories are deleted, in an unspecified
@@ -1189,8 +1175,7 @@ END
        next if defined $ENV{'PG_TEST_NOCLEAN'};
 
        # clean basedir on clean test invocation
-       $node->clean_node
-         if TestLib::all_tests_passing() && !defined $died && !$exit_code;
+       $node->clean_node if $exit_code == 0 && TestLib::all_tests_passing();
    }
 
    $? = $exit_code;
index d6fe26c03694694618f4dcab704490cdceadb96e..9981265766966c3fa3059508beba47a2f9a8f180 100644 (file)
@@ -129,8 +129,13 @@ INIT
 END
 {
 
-   # Preserve temporary directory for this test on failure
-   $File::Temp::KEEP_ALL = 1 unless all_tests_passing();
+   # Test files have several ways of causing prove_check to fail:
+   # 1. Exit with a non-zero status.
+   # 2. Call ok(0) or similar, indicating that a constituent test failed.
+   # 3. Deviate from the planned number of tests.
+   #
+   # Preserve temporary directories after (1) and after (2).
+   $File::Temp::KEEP_ALL = 1 unless $? == 0 && all_tests_passing();
 }
 
 sub all_tests_passing