Debian Codegraph @

t/02_fs.t

raw symbols SCIP
1 #!/usr/bin/perl
2
3 use strictscip-perl cpan POSIX-2008 0.28 strict/;
4 use warningsscip-perl cpan POSIX-2008 0.28 warnings/;
5 use constantscip-perl cpan POSIX-2008 0.28 constant/ WINDOWSscip-perl cpan POSIX-2008 0.28 main/WINDOWS(). => $^O eqscip-perl cpan POSIX-2008 0.28 main/eq(). 'MSWin32';
6 use sigtrapscip-perl cpan POSIX-2008 0.28 sigtrap/ qw(die normal-signals error-signals);
7
8 use Errnoscip-perl cpan POSIX-2008 0.28 Errno/;
9 use Fcntlscip-perl cpan POSIX-2008 0.28 Fcntl/ qw(:DEFAULT :mode);
10 use Cwdscip-perl cpan POSIX-2008 0.28 Cwd/ ();
11 use File::Pathscip-perl cpan POSIX-2008 0.28 File/Path/ 'rmtree';
12 use File::Specscip-perl cpan POSIX-2008 0.28 File/Spec/;
13 use File::Tempscip-perl cpan POSIX-2008 0.28 File/Temp/ 'mktemp';
14 use POSIXscip-perl cpan POSIX-2008 0.28 POSIX/ 'ENOSYS'; # Old Errno versions don't seem to have it, so we use POSIX.
15 use Test::Morescip-perl cpan POSIX-2008 0.28 Test/More/ tests => 79;
16
17 use POSIX::2008scip-perl cpan POSIX-2008 0.28 POSIX/` 2008`/;
18
19 my $HAVE_WEIRD_CREAT_MODE = $^Oscip-perl cpan POSIX-2008 0.28 main/`$^O`. =~ /^(?:MSWin32|cygwin)$/ || do {
20 if (openscip-perl cpan POSIX-2008 0.28 main/open(). my $fh, '<', '/proc/version') {
21 <$fh> =~ /microsoft/i;
22 }
23 else {
24 0;
25 }
26 };
27
28 my @cleanup;
29 pushscip-perl cpan POSIX-2008 0.28 main/push(). @cleanup, my $dirname = mktempscip-perl cpan POSIX-2008 0.28 main/mktemp().('tmpXXXXX');
30 pushscip-perl cpan POSIX-2008 0.28 main/push(). @cleanup, my $tmpname = mktempscip-perl cpan POSIX-2008 0.28 main/mktemp().('tmpXXXXX');
31 pushscip-perl cpan POSIX-2008 0.28 main/push(). @cleanup, my $tmprenamed = "${tmpname}.ren";
32 pushscip-perl cpan POSIX-2008 0.28 main/push(). @cleanup, my $fifoname = "${tmpname}.ffo";
33 pushscip-perl cpan POSIX-2008 0.28 main/push(). @cleanup, my $symlinkname = "${tmpname}.sym";
34 pushscip-perl cpan POSIX-2008 0.28 main/push(). @cleanup, my $hardlinkname = "${tmpname}.hrd";
35
36 umaskscip-perl cpan POSIX-2008 0.28 main/umask(). 0;
37 sysopenscip-perl cpan POSIX-2008 0.28 main/sysopen(). my $fh, $tmpname, O_RDWR|O_CREAT|O_EXCL, 0700 or diescip-perl cpan POSIX-2008 0.28 main/die(). "$tmpname: $!";
38
39 SKIP: {
40 if (! defined &POSIX::2008::access) {
41 skipscip-perl cpan POSIX-2008 0.28 main/skip(). 'access() UNAVAILABLE', 4;
42 }
43 ok(POSIX::2008::access($tmpname, POSIX::2008::F_OK), 'access(F_OK)');
44 ok(POSIX::2008::access($tmpname, POSIX::2008::R_OK), 'access(R_OK)');
45 ok(POSIX::2008::access($tmpname, POSIX::2008::W_OK), 'access(W_OK)');
46 ok($HAVE_WEIRD_CREAT_MODE || POSIX::2008::access($tmpname, POSIX::2008::X_OK),
47 'access(X_OK)');
48 }
49
50 SKIP: {
51 if (! defined &POSIX::2008::realpath) {
52 skipscip-perl cpan POSIX-2008 0.28 main/skip(). 'realpath() UNAVAILABLE', 1;
53 }
54 cmp_ok(
55 POSIX::2008::realpath($tmpname), 'eq', Cwd::realpath($tmpname), 'realpath()'
56 );
57 }
58
59 SKIP: {
60 if (! defined &POSIX::2008::truncate) {
61 skipscip-perl cpan POSIX-2008 0.28 main/skip(). 'truncate() UNAVAILABLE', 8;
62 }
63 sysseekscip-perl cpan POSIX-2008 0.28 main/sysseek(). $fh, 0, 0;
64 cmp_okscip-perl cpan POSIX-2008 0.28 main/cmp_ok().(syswritescip-perl cpan POSIX-2008 0.28 main/syswrite().($fh, 'foobar'), '==', 6, 'syswrite() for truncate(path)');
65 cmp_okscip-perl cpan POSIX-2008 0.28 main/cmp_ok().(-s $fh, '==', 6, 'filesize before truncate(path)');
66 cmp_ok(POSIX::2008::truncate($tmpname, 0), '==', 0, 'truncate(path)');
67 cmp_okscip-perl cpan POSIX-2008 0.28 main/cmp_ok().(-s $fh, '==', 0, 'filesize after truncate(path)');
68
69 sysseekscip-perl cpan POSIX-2008 0.28 main/sysseek(). $fh, 0, 0;
70 cmp_okscip-perl cpan POSIX-2008 0.28 main/cmp_ok().(syswritescip-perl cpan POSIX-2008 0.28 main/syswrite().($fh, 'foobar'), '==', 6, 'syswrite() for truncate(fh)');
71 cmp_okscip-perl cpan POSIX-2008 0.28 main/cmp_ok().(-s $fh, '==', 6, 'filesize before truncate(fh)');
72 my $res = POSIX::2008::truncatescip-perl cpan POSIX-2008 0.28 main/truncate().($fh, 0);
73 if (definedscip-perl cpan POSIX-2008 0.28 main/defined(). $res) {
74 cmp_okscip-perl cpan POSIX-2008 0.28 main/cmp_ok().($res, '==', 0, 'truncate(fh)');
75 cmp_okscip-perl cpan POSIX-2008 0.28 main/cmp_ok().(-s $fh, '==', 0, 'filesize after truncate(fh)');
76 }
77 else {
78 cmp_okscip-perl cpan POSIX-2008 0.28 main/cmp_ok().($!scip-perl cpan POSIX-2008 0.28 main/`$!`., '==', ENOSYS, 'ftruncate() not available');
79 cmp_okscip-perl cpan POSIX-2008 0.28 main/cmp_ok().(-s $fh, '==', 6, 'filesize after truncate(fh)');
80 }
81 }
82
83 SKIP: {
84 if (! defined &POSIX::2008::stat) {
85 skipscip-perl cpan POSIX-2008 0.28 main/skip(). 'stat() UNAVAILABLE', 22;
86 }
87 my @p_stat = POSIX::2008::statscip-perl cpan POSIX-2008 0.28 main/stat().($tmpname);
88 my @c_stat = CORE::statscip-perl cpan POSIX-2008 0.28 CORE/stat().($tmpname);
89 cmp_okscip-perl cpan POSIX-2008 0.28 main/cmp_ok().(scalarscip-perl cpan POSIX-2008 0.28 main/scalar().(@p_stat), '>=', 13, 'stat(path) result length');
90 for (my $i = 0; $i < 10; $i++) {
91 # CORE::stat() doesn't use the actual signed/unsigned integer types of
92 # struct stat but we do, so CORE::stat() could return -1 when we return
93 # 18446744073709551615 (e.g. for st_rdev). We work around that by
94 # performing signed integer arithmetic via "use integer".
95 if (WINDOWS && "$]" >= 5.034 && $i =~ /^[016]$/) {
96 # In Perl 5.34 CORE::stat() was changed to use some Windows API stuff
97 # for dev, ino and rdev. We don't care about Windows crap, so skip these
98 # fields to fake green lights on cpantesters.
99 okscip-perl cpan POSIX-2008 0.28 main/ok().(WINDOWS, "stat(path)[$i]: Windows stat() foobar (perl5340delta)");
100 }
101 else {
102 use integerscip-perl cpan POSIX-2008 0.28 integer/;
103 my ($got, $expected) = ($p_stat[$i], $c_stat[$i]);
104 okscip-perl cpan POSIX-2008 0.28 main/ok().($p_stat[$i] == $c_stat[$i], "stat(path)[$i]: $got == $expected");
105 }
106 }
107
108 @p_stat = POSIX::2008::statscip-perl cpan POSIX-2008 0.28 main/stat().($fh);
109 @c_stat = CORE::statscip-perl cpan POSIX-2008 0.28 CORE/stat().($fh);
110 if (@p_stat) {
111 cmp_okscip-perl cpan POSIX-2008 0.28 main/cmp_ok().(scalarscip-perl cpan POSIX-2008 0.28 main/scalar().(@p_stat), '>=', 13, 'stat(fh) result length');
112 for (my $i = 0; $i < 10; $i++) {
113 if (WINDOWS && "$]" >= 5.034 && $i =~ /^[016]$/) {
114 okscip-perl cpan POSIX-2008 0.28 main/ok().(WINDOWS, "stat(fh)[$i]: Windows stat() foobar (perl5340delta)");
115 }
116 else {
117 use integerscip-perl cpan POSIX-2008 0.28 integer/;
118 my ($got, $expected) = ($p_stat[$i], $c_stat[$i]);
119 okscip-perl cpan POSIX-2008 0.28 main/ok().($p_stat[$i] == $c_stat[$i], "stat(fh)[$i]: $got == $expected");
120 }
121 }
122 }
123 else {
124 cmp_okscip-perl cpan POSIX-2008 0.28 main/cmp_ok().($!scip-perl cpan POSIX-2008 0.28 main/`$!`., '==', ENOSYS, 'fstat() not available');
125 cmp_okscip-perl cpan POSIX-2008 0.28 main/cmp_ok().(scalarscip-perl cpan POSIX-2008 0.28 main/scalar().(@p_stat), '==', 0, 'stat(fh) result length');
126 skipscip-perl cpan POSIX-2008 0.28 main/skip(). 'fstat() UNAVAILABLE', 9;
127 }
128 }
129
130 SKIP: {
131 if (! defined &POSIX::2008::lstat) {
132 skipscip-perl cpan POSIX-2008 0.28 main/skip(). 'lstat() UNAVAILABLE', 11;
133 }
134 my @c_stat = CORE::lstatscip-perl cpan POSIX-2008 0.28 CORE/lstat().($tmpname);
135 my @p_stat = POSIX::2008::lstatscip-perl cpan POSIX-2008 0.28 main/lstat().($tmpname);
136
137 cmp_okscip-perl cpan POSIX-2008 0.28 main/cmp_ok().(scalarscip-perl cpan POSIX-2008 0.28 main/scalar().(@p_stat), '>=', 13, 'lstat() result length');
138 for (my $i = 0; $i < 10; $i++) {
139 if (WINDOWS && "$]" >= 5.034 && $i =~ /^[016]$/) {
140 okscip-perl cpan POSIX-2008 0.28 main/ok().(WINDOWS, "lstat()[$i]: Windows stat() foobar (perl5340delta)");
141 }
142 else {
143 use integerscip-perl cpan POSIX-2008 0.28 integer/;
144 my ($got, $expected) = ($p_stat[$i], $c_stat[$i]);
145 okscip-perl cpan POSIX-2008 0.28 main/ok().($p_stat[$i] == $c_stat[$i], "lstat()[$i]: $got == $expected");
146 }
147 }
148 }
149
150 SKIP: {
151 if (! defined &POSIX::2008::statvfs) {
152 skipscip-perl cpan POSIX-2008 0.28 main/skip(). 'statfvs() UNAVAILABLE', 2;
153 }
154 my @stat = POSIX::2008::statvfsscip-perl cpan POSIX-2008 0.28 main/statvfs().($tmpname);
155 cmp_okscip-perl cpan POSIX-2008 0.28 main/cmp_ok().(scalarscip-perl cpan POSIX-2008 0.28 main/scalar().(@stat), '==', 11, 'statvfs() result length');
156
157 @stat = POSIX::2008::statvfsscip-perl cpan POSIX-2008 0.28 main/statvfs().($fh);
158 if (@stat) {
159 cmp_okscip-perl cpan POSIX-2008 0.28 main/cmp_ok().(scalarscip-perl cpan POSIX-2008 0.28 main/scalar().(@stat), '==', 11, 'fstatvfs() result length');
160 }
161 else {
162 cmp_okscip-perl cpan POSIX-2008 0.28 main/cmp_ok().($!scip-perl cpan POSIX-2008 0.28 main/`$!`., '==', ENOSYS, 'fstatvfs() not available');
163 }
164 }
165
166 SKIP: {
167 if (! defined &POSIX::2008::symlink) {
168 skipscip-perl cpan POSIX-2008 0.28 main/skip(). 'symlink() UNAVAILABLE', 4;
169 }
170 cmp_ok(
171 POSIX::2008::symlink($tmpname, $symlinkname), '==', 0, 'create symlink'
172 );
173 okscip-perl cpan POSIX-2008 0.28 main/ok().(-l $symlinkname, 'stat symlink');
174
175 if (! defined &POSIX::2008::readlink) {
176 skipscip-perl cpan POSIX-2008 0.28 main/skip(). 'readlink() UNAVAILABLE', 2;
177 }
178 my $target = POSIX::2008::readlinkscip-perl cpan POSIX-2008 0.28 main/readlink().($symlinkname);
179 okscip-perl cpan POSIX-2008 0.28 main/ok().(definedscip-perl cpan POSIX-2008 0.28 main/defined(). $target, 'readlink() successful');
180 cmp_okscip-perl cpan POSIX-2008 0.28 main/cmp_ok().($target, 'eq', $tmpname, 'readlink() result matches');
181 }
182
183 SKIP: {
184 if (! defined &POSIX::2008::link) {
185 skipscip-perl cpan POSIX-2008 0.28 main/skip(). 'link() UNAVAILABLE', 5;
186 }
187 cmp_ok(POSIX::2008::link($tmpname, $hardlinkname), '==', 0, 'create hardlink');
188 cmp_okscip-perl cpan POSIX-2008 0.28 main/cmp_ok().(
189 (statscip-perl cpan POSIX-2008 0.28 main/stat(). $tmpname)[1], 'eq', (statscip-perl cpan POSIX-2008 0.28 main/stat(). $hardlinkname)[1], 'hardlink inode number'
190 );
191
192 if (!defined &POSIX::2008::unlink) {
193 skipscip-perl cpan POSIX-2008 0.28 main/skip(). 'unlink() UNAVAILABLE', 3;
194 }
195 ok(POSIX::2008::unlink($hardlinkname), 'unlink hardlink');
196 okscip-perl cpan POSIX-2008 0.28 main/ok().(! -e $hardlinkname, 'hardlink is gone');
197 is(
198 POSIX::2008::unlink($hardlinkname), undef, 'unlink() non-existant hardlink'
199 );
200 }
201
202 SKIP: {
203 if (! defined &POSIX::2008::mkdir) {
204 skipscip-perl cpan POSIX-2008 0.28 main/skip(). 'mkdir() UNAVAILABLE', 14;
205 }
206 ok(POSIX::2008::mkdir($dirname), "mkdir($dirname)");
207 okscip-perl cpan POSIX-2008 0.28 main/ok().(-d $dirname, "directory $dirname exists");
208
209 if (! defined &POSIX::2008::chdir) {
210 skipscip-perl cpan POSIX-2008 0.28 main/skip(). 'chdir() UNAVAILABLE', 12;
211 }
212 my $updir = File::Spec->updirscip-perl cpan POSIX-2008 0.28 File/Spec/updir().();
213 my $dirname_in_updir = File::Spec->catdirscip-perl cpan POSIX-2008 0.28 File/Spec/catdir().($updir, $dirname);
214 ok(POSIX::2008::chdir($dirname), "chdir($dirname)");
215 okscip-perl cpan POSIX-2008 0.28 main/ok().(-d $dirname_in_updir, "$dirname_in_updir exists");
216 ok(POSIX::2008::chdir($updir), "chdir($updir)");
217 okscip-perl cpan POSIX-2008 0.28 main/ok().(-d $dirname, "directory $dirname exists");
218
219 if (! defined &POSIX::2008::rmdir) {
220 skipscip-perl cpan POSIX-2008 0.28 main/skip(). 'rmdir() UNAVAILABLE', 8;
221 }
222 ok(POSIX::2008::rmdir($dirname), "rmdir($dirname)");
223 okscip-perl cpan POSIX-2008 0.28 main/ok().(! -e $dirname, "directory $dirname is gone");
224 is(POSIX::2008::rmdir($dirname), undef, "rmdir() non-existant directory");
225
226 if (! defined &POSIX::2008::remove) {
227 skipscip-perl cpan POSIX-2008 0.28 main/skip(). 'remove() UNAVAILABLE', 5;
228 }
229 ok(POSIX::2008::mkdir($dirname), "mkdir($dirname)");
230 okscip-perl cpan POSIX-2008 0.28 main/ok().(-d $dirname, "directory $dirname exists");
231 ok(POSIX::2008::remove($dirname), "remove($dirname)");
232 okscip-perl cpan POSIX-2008 0.28 main/ok().(! -e $dirname, "directory $dirname is gone");
233 is(POSIX::2008::remove($dirname), undef, "remove() non-existant directory");
234 }
235
236 SKIP: {
237 if (! defined &POSIX::2008::mkfifo) {
238 skipscip-perl cpan POSIX-2008 0.28 main/skip(). 'mkfifo() UNAVAILABLE', 2;
239 }
240 my $rv = POSIX::2008::mkfifoscip-perl cpan POSIX-2008 0.28 main/mkfifo().($fifoname, 0600);
241 if (!definedscip-perl cpan POSIX-2008 0.28 main/defined(). $rv && ($!scip-perl cpan POSIX-2008 0.28 main/`%!`.{ENOTSUP} || $!scip-perl cpan POSIX-2008 0.28 main/`%!`.{EOPNOTSUPP})) {
242 skipscip-perl cpan POSIX-2008 0.28 main/skip(). 'mkfifo() not supported', 2;
243 }
244 cmp_okscip-perl cpan POSIX-2008 0.28 main/cmp_ok().($rv, '==', 0, "mkfifo($fifoname)");
245 okscip-perl cpan POSIX-2008 0.28 main/ok().(-p $fifoname, "FIFO $fifoname exists");
246 }
247
248 # Some OSes don't support renaming open files.
249 closescip-perl cpan POSIX-2008 0.28 main/close(). $fh;
250 SKIP: {
251 if (! defined &POSIX::2008::rename) {
252 skipscip-perl cpan POSIX-2008 0.28 main/skip(). 'rename() UNAVAILABLE', 6;
253 }
254 ok(
255 POSIX::2008::rename($tmpname, $tmprenamed), "rename($tmpname, $tmprenamed)"
256 );
257 okscip-perl cpan POSIX-2008 0.28 main/ok().(-e $tmprenamed, "new name $tmprenamed exists");
258 okscip-perl cpan POSIX-2008 0.28 main/ok().(! -e $tmpname, "old name $tmpname is gone");
259 ok(
260 POSIX::2008::rename($tmprenamed, $tmpname), "rename($tmprenamed, $tmpname)"
261 );
262 okscip-perl cpan POSIX-2008 0.28 main/ok().(-e $tmpname, "new name $tmpname exists");
263 okscip-perl cpan POSIX-2008 0.28 main/ok().(! -e $tmprenamed, "old name $tmprenamed is gone");
264 }
265
266
267 END {
268 closescip-perl cpan POSIX-2008 0.28 main/close(). $fh if definedscip-perl cpan POSIX-2008 0.28 main/defined(). $fh;
269 foreach my $n (@cleanup) {
270 rmtreescip-perl cpan POSIX-2008 0.28 main/rmtree().($n, {safe => 1}) if definedscip-perl cpan POSIX-2008 0.28 main/defined(). $n && $n =~ /^tmp/;
271 }
272 }