summaryrefslogtreecommitdiff
path: root/t/op/filetest.t
blob: e00d5fb7b06b82eeaf782d13f74f8f819d1080a6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#!./perl

# There are few filetest operators that are portable enough to test.
# See pod/perlport.pod for details.

BEGIN {
    chdir 't' if -d 't';
    unshift @INC, '../lib' if -d '../lib';
}

use Config;
print "1..10\n";

print "not " unless -d 'op';
print "ok 1\n";

print "not " unless -f 'TEST';
print "ok 2\n";

print "not " if -f 'op';
print "ok 3\n";

print "not " if -d 'TEST';
print "ok 4\n";

print "not " unless -r 'TEST';
print "ok 5\n";

# make sure TEST is r-x
eval { chmod 0555, 'TEST' };
$bad_chmod = $@;

$oldeuid = $>;		# root can read and write anything
eval '$> = 1';		# so switch uid (may not be implemented)

print "# oldeuid = $oldeuid, euid = $>\n";

if (!$Config{d_seteuid}) {
    print "ok 6 #skipped, no seteuid\n";
}
elsif ($bad_chmod) {
    print "#[$@]\nok 6 #skipped\n";
}
else {
    print "not " if -w 'TEST';
    print "ok 6\n";
}

# Scripts are not -x everywhere so cannot test that.

eval '$> = $oldeuid';	# switch uid back (may not be implemented)

# this would fail for the euid 1
# (unless we have unpacked the source code as uid 1...)
print "not " unless -r 'op';
print "ok 7\n";

# this would fail for the euid 1
# (unless we have unpacked the source code as uid 1...)
if ($Config{d_seteuid}) {
    print "not " unless -w 'op';
    print "ok 8\n";
} else {
    print "ok 8 #skipped, no seteuid\n";
}

print "not " unless -x 'op'; # Hohum.  Are directories -x everywhere?
print "ok 9\n";

print "not " unless "@{[grep -r, qw(foo io noo op zoo)]}" eq "io op";
print "ok 10\n";