Skip to content

Commit

Permalink
use File::ChangeNotify to watch changed files
Browse files Browse the repository at this point in the history
because it is much faster than linux.
  • Loading branch information
dann committed Jul 5, 2009
1 parent e333339 commit 9b61fe4
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 21 deletions.
1 change: 1 addition & 0 deletions Makefile.PL
Expand Up @@ -20,6 +20,7 @@ requires(
"Module::ExtractUse" => 0.23,
"TAP::Harness" => 3.16,
"self" => 0.32,
"File::ChangeNotify" => 0.07,
);

features(
Expand Down
33 changes: 12 additions & 21 deletions lib/Test/Continuous.pm
Expand Up @@ -10,11 +10,11 @@ our $VERSION = '0.66';
use Exporter::Lite;
use App::Prove;
use File::Find;
use File::Modified;
use Cwd;
use Module::ExtractUse;
use List::MoreUtils qw(uniq);
use Test::Continuous::Formatter;
use File::ChangeNotify;

our @EXPORT = qw(&runtests);
{
Expand All @@ -27,19 +27,6 @@ my @tests;
my @changes;
my @files;

sub _files {
return @files if @files;
my $cwd = getcwd;
find sub {
my $filename = $File::Find::name;
return if ! -f $filename;
return unless $filename =~ /\.(p[lm]|t)$/;

push @files, $filename;
}, $cwd;
return @files;
}

sub _tests_to_run {
my %dep;

Expand All @@ -64,6 +51,8 @@ sub _tests_to_run {
my $changed = $_;
map { @{$dep{$_}} } grep { index($changed, $_) >= 0 } keys %dep;
}
} map {
$_->path;
} @changes;

return @tests if @tests_to_run == 0;
Expand Down Expand Up @@ -106,13 +95,15 @@ sub runtests {
}

print "[MSG] Will run continuously test $_\n" for @tests;
my $d = File::Modified->new( files => [ _files ] );
while(1) {
if ( @changes = $d->changed ) {
print "[MSG]: $_ was changed.\n" for @changes;
$d->update();
_run_once;
}

my $watcher = File::ChangeNotify->instantiate_watcher(
directories => [ getcwd ],
filter => qr/\.(p[lm]|t)$/,
);

while ( my @changes = $watcher->wait_for_events() ) {
print "[MSG]:" . $_->path . " was changed.\n" for @changes;
_run_once;
sleep 3;
}
}
Expand Down

0 comments on commit 9b61fe4

Please sign in to comment.