File: 05-steps.t

package info (click to toggle)
libfile-finder-perl 0.53-4
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 148 kB
  • sloc: perl: 985; sh: 3; makefile: 2
file content (118 lines) | stat: -rw-r--r-- 3,267 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
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
#! perl
use Test::More 'no_plan';

require_ok('File::Finder');

isa_ok(my $f = File::Finder->new, "File::Finder");

use File::Find;
sub fin {
  my $wanted = shift;

  my @results;
  find(sub {$wanted->() and push @results, $File::Find::name}, @_);
  @results;
}

is_deeply([File::Finder->in(qw(.))],
	  [fin(sub { 1 }, '.')],
	  'all names');

is_deeply([File::Finder->name(qr/\.t$/)->in(qw(.))],
	  [fin(sub { /\.t$/ }, '.')],
	  'all files named *.t via regex');

is_deeply([File::Finder->name('*.t')->in(qw(.))],
	  [fin(sub { /\.t$/ }, '.')],
	  'all files named *.t via glob');

is_deeply([File::Finder->perm('+0444')->in(qw(.))],
	  [fin(sub { (stat($_))[2] & 0444 }, '.')],
	  'readable by someone');

is_deeply([File::Finder->perm('-0444')->in(qw(.))],
	  [fin(sub { ((stat($_))[2] & 0444) == 0444 }, '.')],
	  'readable by everyone');

is_deeply([File::Finder->perm('+0222')->in(qw(.))],
	  [fin(sub { (stat($_))[2] & 0222 }, '.')],
	  'writeable by someone');

is_deeply([File::Finder->perm('+0111')->in(qw(.))],
	  [fin(sub { (stat($_))[2] & 0111 }, '.')],
	  'executable by someone');

is_deeply([File::Finder->perm('0644')->in(qw(.))],
	  [fin(sub { ((stat($_))[2] & 0777) == 0644 }, '.')],
	  'mode 0644');

is_deeply([File::Finder->perm('0755')->in(qw(.))],
	  [fin(sub { ((stat($_))[2] & 0777) == 0755 }, '.')],
	  'mode 755');

{
  my $dirperm = (stat ".")[2] & 07777;
  is_deeply([File::Finder->perm($dirperm)->in(qw(.))],
	    [fin(sub { ((stat($_))[2] & 07777) == $dirperm }, '.')],
	    'mode same as current directory');
}

is_deeply([File::Finder->type('f')->in(qw(.))],
	  [fin(sub { -f }, '.')],
	  'all files');

is_deeply([File::Finder->eval(sub { stat('/') })->type('f')->in(qw(.))],
	  [fin(sub { -f }, '.')],
	  'all files even after messing with _ pseudo handle');

is_deeply([File::Finder->user($<)->in(qw(.))],
	  [fin(sub { -o }, '.')],
	  'owned');

is_deeply([File::Finder->not->user($<)->in(qw(.))],
	  [fin(sub { not -o }, '.')],
	  'not owned');

is_deeply([File::Finder->group(0+$()->in(qw(.))],
	  [fin(sub { $( == (stat)[5] }, '.')],
	  'group');

is_deeply([File::Finder->not->group(0+$()->in(qw(.))],
	  [fin(sub { $( != (stat)[5] }, '.')],
	  'not group');

is_deeply([File::Finder->nouser->in(qw(.))],
	  [fin(sub { not defined getpwuid((stat)[4]) }, '.')],
	  'nouser');

is_deeply([File::Finder->not->nouser->in(qw(.))],
	  [fin(sub { defined getpwuid((stat)[4]) }, '.')],
	  'not nouser');

is_deeply([File::Finder->nogroup->in(qw(.))],
	  [fin(sub { not defined getgrgid((stat)[5]) }, '.')],
	  'nogroup');

is_deeply([File::Finder->not->nogroup->in(qw(.))],
	  [fin(sub { defined getgrgid((stat)[5]) }, '.')],
	  'not nogroup');

is_deeply([File::Finder->links('-2')->in(qw(.))],
	  [fin(sub { (stat)[3] < 2 }, '.')],
	  'less than 2 links');

is_deeply([File::Finder->links('+1')->in(qw(.))],
	  [fin(sub { (stat)[3] > 1 }, '.')],
	  'more than 1 link');

is_deeply([File::Finder->size('-10c')->in(qw(.))],
	  [fin(sub { -s $_ < 10 }, '.')],
	  'less than 10 bytes');

is_deeply([File::Finder->size('+10c')->in(qw(.))],
	  [fin(sub { -s $_ > 10 }, '.')],
	  'more than 10 bytes');

is_deeply([File::Finder->contains('AvErYuNlIkElYsTrInG')->in(qw(.))],
	  ["./" . __FILE__],
	  'files with a very unlikely string');