Skip to content

Commit 8c12838

Browse files
committed
Make PG_TEST_NOCLEAN work for temporary directories in TAP tests
When set, this environment variable was only effective for data directories but not for all the other temporary files created by PostgreSQL::Test::Utils. Keeping the temporary files after a successful run can be useful for debugging purposes. The documentation is updated to reflect the new behavior, with contents available in doc/ since v16 and in src/test/perl/README since v15. Author: Jacob Champion Reviewed-by: Daniel Gustafsson Discussion: https://postgr.es/m/CAAWbhmgHtDH1SGZ+Fw05CsXtE0mzTmjbuUxLB9mY9iPKgM6cUw@mail.gmail.com Discussion: https://postgr.es/m/YyPd9unV14SX2bLF@paquier.xyz Backpatch-through: 11
1 parent c651020 commit 8c12838

File tree

3 files changed

+9
-5
lines changed

3 files changed

+9
-5
lines changed

doc/src/sgml/regress.sgml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -818,6 +818,8 @@ make check PROVE_TESTS='t/001_test1.pl t/003_test3.pl'
818818
<programlisting>
819819
PG_TEST_NOCLEAN=1 make -C src/bin/pg_dump check
820820
</programlisting>
821+
This environment variable also prevents the test's temporary directories
822+
from being removed.
821823
</para>
822824

823825
<para>

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@ sub all_tests_passing
272272
273273
Securely create a temporary directory inside C<$tmp_check>, like C<mkdtemp>,
274274
and return its name. The directory will be removed automatically at the
275-
end of the tests.
275+
end of the tests, unless the environment variable PG_TEST_NOCLEAN is provided.
276276
277277
If C<prefix> is given, the new directory is templated as C<${prefix}_XXXX>.
278278
Otherwise the template is C<tmp_test_XXXX>.
@@ -286,7 +286,7 @@ sub tempdir
286286
return File::Temp::tempdir(
287287
$prefix . '_XXXX',
288288
DIR => $tmp_check,
289-
CLEANUP => 1);
289+
CLEANUP => not defined $ENV{'PG_TEST_NOCLEAN'});
290290
}
291291

292292
=pod
@@ -301,7 +301,8 @@ name, to avoid path length issues.
301301
sub tempdir_short
302302
{
303303

304-
return File::Temp::tempdir(CLEANUP => 1);
304+
return File::Temp::tempdir(
305+
CLEANUP => not defined $ENV{'PG_TEST_NOCLEAN'});
305306
}
306307

307308
=pod

src/test/perl/README

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,9 @@ some lesser number of seconds.
3131

3232
Data directories will also be left behind for analysis when a test fails;
3333
they are named according to the test filename. But if the environment
34-
variable PG_TEST_NOCLEAN is set, data directories will be retained
35-
regardless of test status.
34+
variable PG_TEST_NOCLEAN is set, the data directories will be retained
35+
regardless of test status. This environment variable also prevents the
36+
test's temporary directories from being removed.
3637

3738

3839
Writing tests

0 commit comments

Comments
 (0)