App-CSE

 view release on metacpan or  search on metacpan

t/09-watch.t  view on Meta::CPAN

#! perl -T

use strict;

use Test::More;

use App::CSE;


use File::Slurp;
use File::Temp;
use File::Copy::Recursive;

use Path::Class::Dir;

use Log::Log4perl qw/:easy/;
# Log::Log4perl->easy_init($INFO);


use File::BaseDir qw//;
unless( File::BaseDir::data_files('mime/globs') ){
  plan skip_all => 'No mime-info database on the machine. The shared-mime-info package is available from http://freedesktop.org/';
}

unless( $ENV{TEST_SLOW} ){
  plan skip_all => 'Do not run this test. unless TEST_SLOW=1';
}


my $idx_dir = File::Temp->newdir( CLEANUP => 1 );
my $content_dir = File::Temp->newdir( CLEANUP => 1 );

my $original_content_dir = Path::Class::Dir->new('t/toindex');
File::Copy::Recursive::dircopy($original_content_dir , $content_dir);

# {
#   ## Indexing the content dir
#   local @ARGV = ( 'index' , '--idx='.$idx_dir , $content_dir.'' );
#   my $cse = App::CSE->new();
#   is( $cse->main() , 0 ,  "Ok can execute the magic command just fine");
# }

{
  ## Searching just for bonjour
  local @ARGV = ( 'bonjour' ,  '--idx='.$idx_dir  , '--dir='.$content_dir );
  my $cse = App::CSE->new();
  ok( $cse->command()->isa('App::CSE::Command::Search') , "Ok its a search command");
  is_deeply( $cse->args() , [ 'bonjour' ] );
}

my $watcher_pid;

{
  # Watch for changes.
  local @ARGV = ( 'watch' , '--idx='.$idx_dir  , '--dir='.$content_dir );
  my $cse = App::CSE->new();
  ok( $cse->command()->isa('App::CSE::Command::Watch') , "Ok we have a watch command");
  is( $cse->command()->execute() , 0 , "Ok can execute that");
}


{
  ## Get the watcher_pid
  local @ARGV = ( 'check' , '--idx='.$idx_dir );

  my $cse = App::CSE->new();
  ok( $watcher_pid = $cse->index_meta->{'watcher.pid'} , "Ok got a watcher PID");
  ( $watcher_pid ) = ( $watcher_pid =~ /(\d+)/ );
}

# Create a new pm file and check we can search for it.
  my $code = q|package My::Shiny::Package

sub abcdefg123{
   ...
}

|;
  my $filename =
    Path::Class::Dir->new( $content_dir )->file('package.pm')->absolute->stringify();
  File::Slurp::write_file($filename , $code );



( run in 1.010 second using v1.01-cache-2.11-cpan-5a3173703d6 )