File: sticky-bit.t

package info (click to toggle)
libfile-chmod-perl 0.40-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 232 kB
  • ctags: 29
  • sloc: perl: 372; makefile: 2
file content (39 lines) | stat: -rw-r--r-- 1,070 bytes parent folder | download | duplicates (3)
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
use strict;
use warnings;
use Test::More;
use English '-no_match_vars';
use File::Temp ();
use File::chmod qw( chmod getmod );
$File::chmod::UMASK = 0;

plan skip_all => "Windows perms work differently" if $OSNAME eq 'MSWin32';
plan skip_all => "old File::Temp without newdir" if !File::Temp->can('newdir');

my $tmp = File::Temp->newdir;
my $fn  = $tmp->dirname;
note sprintf "original state of %s: %o\n", $fn, getmod( $fn );


ok chmod("+t", $fn ), "chmod +t $fn";
ok -k $fn, "$fn sticky"
	or diag sprintf "state of %s: %o\n", $fn, getmod( $fn );

ok chmod("-t", $fn ), "chmod -t $fn";
ok ! -k $fn, "$fn not sticky"
	or diag sprintf "state of %s: %o\n", $fn, getmod( $fn );


ok chmod("o+t", $fn ), "chmod o+t $fn";
ok -k $fn, "$fn sticky"
	or diag sprintf "state of %s: %o\n", $fn, getmod( $fn );

ok chmod("o-t", $fn ), "chmod o-t $fn";
ok ! -k $fn, "$fn not sticky"
	or diag sprintf "state of %s: %o\n", $fn, getmod( $fn );


ok chmod("u+t", $fn ), "chmod u+t $fn";
ok ! -k $fn, "$fn sticky"
	or diag sprintf "state of %s: %o\n", $fn, getmod( $fn );

done_testing;