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