File: 04-ffr.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 (50 lines) | stat: -rw-r--r-- 1,497 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
#! perl
use Test::More;

BEGIN {
  eval { require File::Find::Rule };
  plan 'skip_all' => 'No File::Find::Rule installed' if $@;
}

plan 'no_plan';

BEGIN { use_ok('File::Finder') }
isa_ok(my $f = File::Finder->new, 'File::Finder');
isa_ok(my $ffr = File::Find::Rule->new, 'File::Find::Rule');
isa_ok(my $combined = $f->ffr($ffr), 'File::Finder');

{
  my $r;
  isa_ok(my $ffr = File::Find::Rule->exec(sub { $r = 1 }), "File::Find::Rule");
  isa_ok(my $combined = $f->ffr($ffr), "File::Finder");
  ## have to simulate being called in File::Find::find;
  local $File::Find::name = "/DUM/MY";
  local $_ = "MY";
  local $File::Find::dir = "/DUM";
  $combined->as_wanted->();
  is($r, 1, "simple ffr rule ran");
}

{
  my $r;
  isa_ok(my $ffr = File::Find::Rule->exec(sub { 1 }), "File::Find::Rule");
  isa_ok(my $combined = $f->ffr($ffr), "File::Finder");
  ## have to simulate being called in File::Find::find;
  local $File::Find::name = "/DUM/MY";
  local $_ = "MY";
  local $File::Find::dir = "/DUM";
  $combined->eval(sub { $r = 1 })->as_wanted->();
  is($r, 1, "simple ffr rule returned true");
}

{
  my $r;
  isa_ok(my $ffr = File::Find::Rule->exec(sub { 0 }), "File::Find::Rule");
  isa_ok(my $combined = $f->ffr($ffr), "File::Finder");
  ## have to simulate being called in File::Find::find;
  local $File::Find::name = "/DUM/MY";
  local $_ = "MY";
  local $File::Find::dir = "/DUM";
  $combined->eval(sub { $r = 1 })->as_wanted->();
  is($r, undef, "simple ffr rule returned false");
}