Too many my $fh:s.
[p5sagit/p5-mst-13.2.git] / lib / filetest.t
index 096031c..32f286a 100644 (file)
@@ -5,7 +5,7 @@ BEGIN {
        @INC = '../lib';
 }
 
-use Test::More tests => 11;
+use Test::More tests => 15;
 
 # these two should be kept in sync with the pragma itself
 # if hint bits are changed there, other things *will* break
@@ -49,3 +49,42 @@ like( $@, qr/^$error/, 'filetest dies with missing subpragma on use' );
 
 eval "no filetest";
 like( $@, qr/^$error/, 'filetest dies with missing subpragma on unuse' );
+
+SKIP: {
+    # A real test for filetest.
+    # This works for systems with /usr/bin/chflags (i.e. BSD4.4 systems).
+    my $chflags = "/usr/bin/chflags";
+    my $tstfile = "filetest.tst";
+    skip("No $chflags available", 4) if !-x $chflags;
+
+    skip("Test does not work on OpenBSD and BSD/OS", 4)
+       if $^O =~ /^(?:openbsd|bsdos)$/;
+
+  SKIP: {
+       eval {
+           if (!-e $tstfile) {
+               open(T, ">$tstfile") or die "Can't create $tstfile: $!";
+               close T;
+           }
+           system($chflags, "uchg", $tstfile);
+           die "Can't exec $chflags uchg" if $? != 0;
+       };
+       skip("Errors in test using chflags: $@", 4) if $@;
+
+       {
+           use filetest 'access';
+           is(-w $tstfile, undef, "$tstfile should not be recognized as writable");
+           is(-W $tstfile, undef, "$tstfile should not be recognized as writable");
+       }
+       {
+           no filetest 'access';
+           is(-w $tstfile, 1, "$tstfile should be recognized as writable");
+           is(-W $tstfile, 1, "$tstfile should be recognized as writable");
+       }
+    }
+
+    # cleanup
+    system($chflags, "nouchg", $tstfile);
+    unlink $tstfile;
+    warn "Can't remove $tstfile: $!" if -e $tstfile;
+}