This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
applied suggested patch, modulo already applied parts
[perl5.git] / t / op / filetest.t
CommitLineData
42e55ab1
JH
1#!./perl
2
3# There are few filetest operators that are portable enough to test.
4# See pod/perlport.pod for details.
5
3eeba6fb 6use Config;
42e55ab1
JH
7BEGIN {
8 chdir 't' if -d 't';
9}
10
11print "1..10\n";
12
13print "not " unless -d 'op';
14print "ok 1\n";
15
16print "not " unless -f 'TEST';
17print "ok 2\n";
18
19print "not " if -f 'op';
20print "ok 3\n";
21
22print "not " if -d 'TEST';
23print "ok 4\n";
24
25print "not " unless -r 'TEST';
26print "ok 5\n";
27
22c35a8c
GS
28# make sure TEST is r-x
29eval { chmod 0555, 'TEST' };
846f25a3
GW
30$bad_chmod = $@;
31
32$oldeuid = $>; # root can read and write anything
33eval '$> = 1'; # so switch uid (may not be implemented)
34
35print "# oldeuid = $oldeuid, euid = $>\n";
36
37if ($bad_chmod) {
38 print "#[$@]\nok 6 #skipped\n";
22c35a8c
GS
39}
40else {
846f25a3
GW
41 print "not " if -w 'TEST';
42 print "ok 6\n";
22c35a8c 43}
42e55ab1 44
846f25a3 45# Scripts are not -x everywhere so cannot test that.
42e55ab1
JH
46
47print "not " unless -r 'op';
48print "ok 7\n";
49
846f25a3
GW
50eval '$> = $oldeuid'; # switch uid back (may not be implemented)
51
52# this would fail for the euid 1
53# (unless we have unpacked the source code as uid 1...)
3eeba6fb
CB
54if ($Config{d_seteuid}) {
55 print "not " unless -w 'op';
56 print "ok 8\n";
57} else {
58 print "ok 8 #skipped, no seteuid\n";
59}
42e55ab1
JH
60
61print "not " unless -x 'op'; # Hohum. Are directories -x everywhere?
62print "ok 9\n";
63
64print "not " unless "@{[grep -r, qw(foo io noo op zoo)]}" eq "io op";
65print "ok 10\n";