AnyEvent-Filesys-Notify
view release on metacpan or search on metacpan
t/30-event.t view on Meta::CPAN
use Test::More tests => 11;
use strict;
use warnings;
use File::Spec;
use lib 't/lib';
$|++;
use TestSupport qw(create_test_files delete_test_files move_test_files
modify_attrs_on_test_files $dir received_events receive_event);
use AnyEvent::Filesys::Notify;
use AnyEvent::Impl::Perl;
create_test_files(qw(one/1));
create_test_files(qw(two/1));
create_test_files(qw(one/sub/1));
## ls: one/1 one/sub/1 two/1
my $n = AnyEvent::Filesys::Notify->new(
dirs => [ map { File::Spec->catfile( $dir, $_ ) } qw(one two) ],
filter => sub { shift !~ qr/ignoreme/ },
cb => sub { receive_event(@_) },
## parse_events => 0,
);
isa_ok( $n, 'AnyEvent::Filesys::Notify' );
SKIP: {
skip "not sure which os we are on", 1
unless $^O =~ /linux|darwin|bsd/;
ok( $n->does('AnyEvent::Filesys::Notify::Role::Inotify2'),
'... with the linux role' )
if $^O eq 'linux';
ok( $n->does('AnyEvent::Filesys::Notify::Role::FSEvents'),
'... with the mac role' )
if $^O eq 'darwin';
ok( $n->does('AnyEvent::Filesys::Notify::Role::KQueue'),
'... with the bsd role' )
if $^O =~ /bsd/;
}
diag "This might take a few seconds to run...";
# ls: one/1 one/sub/1 +one/sub/2 two/1
received_events( sub { create_test_files(qw(one/sub/2)) },
'create a file', qw(created) );
# ls: one/1 +one/2 one/sub/1 one/sub/2 two/1 +two/sub/2
received_events(
sub { create_test_files(qw(one/2 two/sub/2)) },
'create file in new subdir',
qw(created created created)
);
# ls: one/1 ~one/2 one/sub/1 one/sub/2 two/1 two/sub/2
received_events( sub { create_test_files(qw(one/2)) },
'modify existing file', qw(modified) );
# ls: one/1 one/2 one/sub/1 one/sub/2 two/1 two/sub -two/sub/2
received_events( sub { delete_test_files(qw(two/sub/2)) },
'deletes a file', qw(deleted) );
# ls: one/1 one/2 +one/ignoreme +one/3 one/sub/1 one/sub/2 two/1 two/sub
received_events( sub { create_test_files(qw(one/ignoreme one/3)) },
'creates two files one should be ignored', qw(created) );
( run in 1.028 second using v1.01-cache-2.11-cpan-cdf2f3d4e48 )