Mercurial > octave-antonio
comparison scripts/miscellaneous/tar.m @ 19925:ee7159d9a330
tar.m: Re-code BIST test restore working directory even when test fails (bug #44007).
* tar.m: Place 'chdir (orig_dir)' as first statement in unwind_protect_cleanup.
Check whether files/dirs exist before attempting to delete them in unwind_protect_cleanup.
author | Rik <rik@octave.org> |
---|---|
date | Tue, 10 Mar 2015 13:59:06 -0700 |
parents | 4197fc428c7d |
children | 0cc365dada52 |
comparison
equal
deleted
inserted
replaced
19924:277b12eed117 | 19925:ee7159d9a330 |
---|---|
74 | 74 |
75 endfunction | 75 endfunction |
76 | 76 |
77 | 77 |
78 %!xtest | 78 %!xtest |
79 %! ## test gzip together with gunzip | 79 %! ## test tar together with untar |
80 %! orig_dir = pwd (); | 80 %! orig_dir = pwd (); |
81 %! unwind_protect | 81 %! unwind_protect |
82 %! dirname = tempname; | 82 %! dirname = tarname = outdir = ""; |
83 %! dirname = tempname (); | |
83 %! assert (mkdir (dirname)); | 84 %! assert (mkdir (dirname)); |
84 %! chdir (dirname); | 85 %! chdir (dirname); |
85 %! dirname2 = "dir2"; | 86 %! dirname2 = "dir2"; |
86 %! assert (mkdir (dirname2)); | 87 %! assert (mkdir (dirname2)); |
87 %! fname1 = "f1"; | 88 %! fname1 = "file1"; |
88 %! fname2 = fullfile (dirname2, "f2"); | 89 %! fname2 = fullfile (dirname2, "file2"); |
89 %! fid = fopen (fname1, "wt"); | 90 %! fid = fopen (fname1, "wt"); |
90 %! assert (fid >= 0); | 91 %! assert (fid >= 0); |
91 %! fdisp (fid, "Hello World"); | 92 %! fdisp (fid, "Hello World"); |
92 %! fclose (fid); | 93 %! fclose (fid); |
93 %! fid = fopen (fname2, "wt"); | 94 %! fid = fopen (fname2, "wt"); |
94 %! assert (fid >= 0); | 95 %! assert (fid >= 0); |
95 %! fdisp (fid, "Goodbye World"); | 96 %! fdisp (fid, "Goodbye World"); |
96 %! fclose (fid); | 97 %! fclose (fid); |
97 %! tarname = [tempname ".tar"]; | 98 %! tarname = [tempname() ".tar"]; |
98 %! filelist = tar (tarname, {dirname2, fname1}); | 99 %! filelist = tar (tarname, {dirname2, fname1}); |
99 %! if (! strcmp (filelist{3}, fname1)) | 100 %! if (! strcmp (filelist{3}, fname1)) |
100 %! error ("tar file contents does not match expected file"); | 101 %! error ("tar file contents does not match expected file"); |
101 %! endif | 102 %! endif |
102 %! if (! exist (tarname, "file")) | 103 %! if (! exist (tarname, "file")) |
113 %! assert (fid >= 0); | 114 %! assert (fid >= 0); |
114 %! str = fgetl (fid); | 115 %! str = fgetl (fid); |
115 %! fclose (fid); | 116 %! fclose (fid); |
116 %! assert (str, "Goodbye World"); | 117 %! assert (str, "Goodbye World"); |
117 %! unwind_protect_cleanup | 118 %! unwind_protect_cleanup |
118 %! delete (tarname); | 119 %! chdir (orig_dir); |
120 %! if (exist (tarname)) | |
121 %! delete (tarname); | |
122 %! endif | |
119 %! confirm_recursive_rmdir (false, "local"); | 123 %! confirm_recursive_rmdir (false, "local"); |
120 %! rmdir (dirname, "s"); | 124 %! if (exist (dirname)) |
121 %! rmdir (outdir, "s"); | 125 %! rmdir (dirname, "s"); |
122 %! chdir (orig_dir); | 126 %! endif |
127 %! if (exist (outdir)) | |
128 %! rmdir (outdir, "s"); | |
129 %! endif | |
123 %! end_unwind_protect | 130 %! end_unwind_protect |
124 | 131 |
125 ## Test input validation | 132 ## Test input validation |
126 %!error tar () | 133 %!error tar () |
127 %!error tar (1) | 134 %!error tar (1) |