9 use Test::More tests => 15;
11 # these two should be kept in sync with the pragma itself
12 # if hint bits are changed there, other things *will* break
13 my $hint_bits = 0x00400000;
14 my $error = "filetest: the only implemented subpragma is 'access'.\n";
16 # can't use it yet, because of the import death
17 ok( require filetest, 'required pragma successfully' );
19 # and here's one culprit, right here
20 eval { filetest->import('bad subpragma') };
21 is( $@, $error, 'filetest dies with bad subpragma on import' );
23 is( $^H & $hint_bits, 0, 'hint bits not set without pragma in place' );
25 # now try the normal usage
26 # can't check $^H here; it's lexically magic (see perlvar)
27 # the test harness unintentionally hoards the goodies for itself
28 use_ok( 'filetest', 'access' );
30 # and import again, to see it here
31 filetest->import('access');
32 ok( $^H & $hint_bits, 'hint bits set with pragma loaded' );
34 # and now get rid of it
35 filetest->unimport('access');
36 is( $^H & $hint_bits, 0, 'hint bits not set with pragma unimported' );
38 eval { filetest->unimport() };
39 is( $@, $error, 'filetest dies without subpragma on unimport' );
41 # there'll be a compilation aborted failure here, with the eval string
42 eval "no filetest 'fake pragma'";
43 like( $@, qr/^$error/, 'filetest dies with bad subpragma on unuse' );
45 eval "use filetest 'bad subpragma'";
46 like( $@, qr/^$error/, 'filetest dies with bad subpragma on use' );
49 like( $@, qr/^$error/, 'filetest dies with missing subpragma on use' );
52 like( $@, qr/^$error/, 'filetest dies with missing subpragma on unuse' );
55 # A real test for filetest.
56 # This works for systems with /usr/bin/chflags (i.e. BSD4.4 systems).
57 my $chflags = "/usr/bin/chflags";
58 my $tstfile = "filetest.tst";
59 skip("No $chflags available", 4) if !-x $chflags;
61 my $skip_eff_user_tests = (!$Config{d_setreuid} && !$Config{d_setresuid})
63 (!$Config{d_setregid} && !$Config{d_setresgid});
67 open(T, ">$tstfile") or die "Can't create $tstfile: $!";
70 system($chflags, "uchg", $tstfile);
71 die "Can't exec $chflags uchg" if $? != 0;
73 skip("Errors in test using chflags: $@", 4) if $@;
76 use filetest 'access';
78 skip("No tests on effective user id", 1)
79 if $skip_eff_user_tests;
80 is(-w $tstfile, undef, "$tstfile should not be recognized as writable");
82 is(-W $tstfile, undef, "$tstfile should not be recognized as writable");
88 skip("No tests on effective user id", 1)
89 if $skip_eff_user_tests;
90 is(-w $tstfile, 1, "$tstfile should be recognized as writable");
92 is(-W $tstfile, 1, "$tstfile should be recognized as writable");
96 system($chflags, "nouchg", $tstfile);
98 warn "Can't remove $tstfile: $!" if -e $tstfile;