changeset 32739:d91569397285 stable

io.tst: Use random prefix for temporary files in test (bug #65150). * test/io.tst: Use random prefix for temporary files in test. Use unwind_protect block to clean up after the test.
author Markus Mützel <markus.muetzel@gmx.de>
date Sat, 13 Jan 2024 15:52:31 +0100
parents 1c40194c7b1f
children 20724f5b80ac 511a0571abcc
files test/io.tst
diffstat 1 files changed, 14 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/test/io.tst	Thu Jan 11 14:40:27 2024 -0500
+++ b/test/io.tst	Sat Jan 13 15:52:31 2024 +0100
@@ -27,7 +27,7 @@
 ## saving sparse matrices to MAT files when using 64-bit indexing since
 ## that is not implemented yet.
 
-%!function [ret, files] = testls (input)
+%!function [ret, files] = testls (input, t_pfix)
 %!  ## flag a1 global so as to test the storage of global flags
 %!  global a1;
 %!
@@ -81,9 +81,7 @@
 %!
 %!  ret = 0;
 %!
-%!  files = cellfun (@fullfile, {P_tmpdir},
-%!                   {"text.mat", "binary.mat", "mat5.mat", "mat7.mat"},
-%!                   "UniformOutput", false);
+%!  files = fullfile (t_pfix, {"text.mat", "binary.mat", "mat5.mat", "mat7.mat"});
 %!  opts = {"-z -text", "-z -binary", "-z -mat", "-v7"};
 %!  tols = {2*eps, 0, 0, 0};
 %!
@@ -192,15 +190,21 @@
 
 %!testif HAVE_ZLIB
 %!
-%! [save_status, save_files] = testls (0);
-%! [load_status, load_files] = testls (1);
+%! ## Random prefix for files
+%! t_pfix = tempname ();
+%! mkdir (t_pfix);
 %!
-%! for f = [save_files, load_files]
-%!   sts = unlink (f{1});
-%! endfor
+%! unwind_protect
+%!   [save_status, save_files] = testls (0, t_pfix);
+%!   [load_status, load_files] = testls (1, t_pfix);
+%! unwind_protect_cleanup
+%!   ## cleanup after test
+%!   confirm_recursive_rmdir (false, "local");
+%!   rmdir (t_pfix, "s");
+%!   clear -global a1;
+%! end_unwind_protect
 %!
 %! assert (save_status && load_status);
-%! clear -global a1;  # cleanup after test
 
 %!testif HAVE_HDF5
 %!