App-CSE

 view release on metacpan or  search on metacpan

t/01-help.t  view on Meta::CPAN

#! perl -T
use Test::More;

use App::CSE;

my $cse = App::CSE->new();

{
  local @ARGV = ( 'help' , '--verbose' );
  ok( $cse->version() , "Ok got a version");
  ok( $cse->command()->isa('App::CSE::Command::Help') , "Ok good command instance");
  ok( $cse->main() , "Ok can execute the magic command");
  ok( $cse->options()->{verbose} , "Ok verbose is set");
}

ok(1);
done_testing();

t/02-check.t  view on Meta::CPAN

use Test::More;

use App::CSE;


use File::Temp;

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

{
  #local @ARGV = ( 'help' );

  local @ARGV = ( 'check' , '--idx='.$dir , '--verbose' , 'blablabla' );

  my $cse = App::CSE->new();

  is_deeply( $cse->args() , [ 'blablabla' ], "Ok good args");

  ok( $cse->index_dir() , "Ok index dir");
  is( $cse->index_dir()->absolute() , $dir.'' , "Ok good option taken into account");

  ok( $cse->command()->isa('App::CSE::Command::Check') , "Ok good command instance");
  ok( $cse->main() , "Ok can execute the magic command");
  ok( $cse->options()->{verbose} , "Ok got verbose");
  ok( $cse->dirty_files() , "Ok got dirty files hash");
  # Mark the file blablabla as dirty
  $cse->dirty_files()->{blablabla} = 1;
  ok( $cse->save_dirty_files() , "Ok can save dirty files");
}

## Rebuild a brand new CSE and check the dirty files contain blablabla
{
  local @ARGV = ( 'check' , '--idx='.$dir , '--verbose' , 'blablabla' );
  my $cse = App::CSE->new();
  ok( $cse->dirty_files()->{blablabla} , "Ok blablabla is remembered as being dirty");
}

ok(1);
done_testing();

t/03-index.t  view on Meta::CPAN

# Log::Log4perl->easy_init($DEBUG);


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/';
}


{
  #local @ARGV = ( 'help' );

  my $idx_dir = File::Temp->newdir( CLEANUP => 1 );
  my $content_dir = Path::Class::Dir->new('t/toindex');

  local @ARGV = ( 'index' , '--idx='.$idx_dir , '--dir='.$content_dir.'' );

  my $cse = App::CSE->new({ cseignore => $content_dir->file('cseignore') });

  ok( $cse->cseignore(), "Ok found cse ignore file");
  ok( $cse->ignore_reassembl() , "Ok got an ignore regexp");
  ok( ! $cse->ignore_reassembl()->match('will-be-indexed') , "Ok no match");
  ok( $cse->ignore_reassembl()->match('/a/b/c-ignored') , "Ok got match");

  # is_deeply( $cse->args() , [ $content_dir ], "Ok good args");

t/04-search.t  view on Meta::CPAN

    plan skip_all => 'No mime-info database on the machine. The shared-mime-info package is available from http://freedesktop.org/';
}


my $idx_dir = File::Temp->newdir( CLEANUP => 1 );
my $content_dir = Path::Class::Dir->new('t/toindex');


# {
#   ## 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' );
  my $cse = App::CSE->new();
  ok( $cse->command()->isa('App::CSE::Command::Search') , "Ok its a search command");
  is_deeply( $cse->args() , [ 'bonjour' ] );
}

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

{
  # Explicit search for bonjour
  local @ARGV = ( 'bonjour' , '--idx=blabla' );
  my $cse = App::CSE->new();
  ok( $cse->command()->isa('App::CSE::Command::Search') , "Ok its a search command");
  is( $cse->options()->{idx} , 'blabla' );
  is_deeply( $cse->args() , [ 'bonjour' ] );
}

{
  ## Searching the content dir for bonjour.
  local @ARGV = (  '--idx='.$idx_dir, 'bonjour', '--dir='.$content_dir.'');
  my $cse = App::CSE->new();
  is( $cse->command()->execute(), 0 , "Ok execute has terminated just fine");
  ok( $cse->command()->isa('App::CSE::Command::Search') , "Ok got search");
  is( $cse->command()->query->to_string() , '(call:bonjour OR content:bonjour OR decl:bonjour OR path:bonjour)' , "Ok got good query");
  ok( $cse->command()->hits() , "Ok got hits");
  is( $cse->command()->hits()->total_hits() , 2 , "Ok got two hits");
  ok( $cse->index_mtime() , "Ok got index mtime");
}

{
  ## Searching the content dir for exported_method.
  local @ARGV = (  '--idx='.$idx_dir, 'call:exported_method', '--dir='.$content_dir.'');
  my $cse = App::CSE->new();
  is( $cse->command()->execute(), 0 , "Ok execute has terminated just fine");
  ok( $cse->command()->isa('App::CSE::Command::Search') , "Ok got search");
  is( $cse->command()->query->to_string() , 'call:exported_method');
  ok( $cse->command()->hits() , "Ok got hits");
  is( $cse->command()->hits()->total_hits() , 1 , "Ok got one hit");
}

{
    # Indexing with .cseignore
    local @ARGV = ( 'index' , '--idx='.$idx_dir , '--dir='.$content_dir.'' );
    my $cse = App::CSE->new({ cseignore => $content_dir->file('cseignore') });
    is( $cse->command()->execute(), 0 , "Ok execute has terminated just fine");
}

{
  ## Searching the content dir for ignored
  local @ARGV = (  '--idx='.$idx_dir, 'ignored', '--dir='.$content_dir.'');
  my $cse = App::CSE->new();
  is( $cse->command()->execute(), 0 , "Ok execute has terminated just fine");
  ok( $cse->command()->hits() , "Ok got hits");
  is( $cse->command()->hits()->total_hits() , 0 , "Ok go zero hit");
}

{
  ## Searching the content_dir/text_files/ for bonjour. Shouldnt not find anything.
  local @ARGV = (  '--idx='.$idx_dir, 'bonjour', $content_dir.'/text_files');
  my $cse = App::CSE->new();
  is( $cse->command()->execute(), 0 , "Ok execute has terminated just fine");
  is( $cse->command()->hits()->total_hits() , 0 , "No hits there.");
}

{
  ## Searhing for bon*. Will find stuff with bonjour, bonnaventure and bonsoir
  local @ARGV = (  '--idx='.$idx_dir, 'bon*', '--dir='.$content_dir.'');
  my $cse = App::CSE->new();
  # diag($cse->command->query()->to_string());
  is( $cse->command()->execute(), 0 , "Ok execute has terminated just fine");
  is( $cse->command()->hits()->total_hits() , 3 , "Ok got 3 hits");
}

## Check various queries

{
  # Plain simple term
  local @ARGV = (  '--idx='.$idx_dir, 'hello', '--dir='.$content_dir.'');
  my $cse = App::CSE->new();
  use Data::Dumper;
  is($cse->command->query()->to_string() , '(call:hello OR content:hello OR decl:hello OR path:hello)');
}

{
  # Plain field term
  local @ARGV = (  '--idx='.$idx_dir, 'content:hello', '--dir='.$content_dir.'');
  my $cse = App::CSE->new();
  use Data::Dumper;
  is($cse->command->query()->to_string(), 'content:hello');
}

{
  # Single prefix query
  local @ARGV = (  '--idx='.$idx_dir, 'hell*', '--dir='.$content_dir.'');
  my $cse = App::CSE->new();
  use Data::Dumper;
  is($cse->command->query()->to_string(), 'content:hell*');
}

{
  # Qualified prefix query
  local @ARGV = (  '--idx='.$idx_dir, 'path:hell*', '--dir='.$content_dir.'');
  my $cse = App::CSE->new();
  use Data::Dumper;
  is($cse->command->query()->to_string(), 'path:hell*');
}

{
  # Qualified composed queries
  local @ARGV = (  '--idx='.$idx_dir, 'path:hell* AND NOT content:helo*', '--dir='.$content_dir.'');
  my $cse = App::CSE->new();
  use Data::Dumper;
  is($cse->command->query()->to_string(), '(path:hell* AND -content:helo*)');
}

{
  # Qualified composed queries, multi args
  local @ARGV = (  '--idx='.$idx_dir, 'path:hell*', 'AND', 'NOT' , 'content:helo*', '--dir='.$content_dir.'');
  my $cse = App::CSE->new();
  use Data::Dumper;
  is($cse->command->query()->to_string(), '(path:hell* AND -content:helo*)');
}

{
  # Same in another way
  local @ARGV = (  '--idx='.$idx_dir, 'path:hell*', '-content:helo*', '--dir='.$content_dir.'');
  my $cse = App::CSE->new();
  use Data::Dumper;
  is($cse->command->query()->to_string(), '(path:hell* AND -content:helo*)');
}

ok(1);
done_testing();

t/05-more-search.t  view on Meta::CPAN



my $idx_dir = File::Temp->newdir( CLEANUP => 1 );
my $content_dir = Path::Class::Dir->new('t/toindex');

# We are trying to cover as many languages from http://langpop.corger.nl/
# as possible.

{
  ## Searching for some javascript.
  local @ARGV = (  '--idx='.$idx_dir, 'javascriptIsGreat', '--dir='.$content_dir.'');
  my $cse = App::CSE->new();
  is( $cse->command()->execute(), 0 , "Ok execute has terminated just fine");
  ok( $cse->command()->hits() , "Ok got hits");
  is( $cse->command()->hits()->total_hits() , 1 , "Ok got one hit");
}

{
  ## Searching for 'isgreat' in javascript
  local @ARGV = (  '--idx='.$idx_dir, 'isgreat', '--dir='.$content_dir.'');
  my $cse = App::CSE->new();
  is( $cse->command()->execute(), 0 , "Ok execute has terminated just fine");
  ok( $cse->command()->hits() , "Ok got hits");
  is( $cse->command()->hits()->total_hits() , 1 , "Ok got one hit");
}


{
  ## Searching for some ruby
  local @ARGV = (  '--idx='.$idx_dir, 'ruby');
  my $cse = App::CSE->new();
  is( $cse->command()->execute(), 0 , "Ok execute has terminated just fine");
  ok( $cse->command()->hits() , "Ok got hits");
  is( $cse->command()->hits()->total_hits() , 3 , "Ok got two hits (one is a directory)");
}

{
  ## Searching for some text file
  local @ARGV = (  '--idx='.$idx_dir, 'search_for_text');
  my $cse = App::CSE->new();
  is( $cse->command()->execute(), 0 , "Ok execute has terminated just fine");
  ok( $cse->command()->hits() , "Ok got hits");
  is( $cse->command()->hits()->total_hits() , 1 , "Ok got one hit");
}

{
  ## Searching a file that is really too big
  local @ARGV = (  '--idx='.$idx_dir, 'really_big');
  my $cse = App::CSE->new();
  is( $cse->command()->execute(), 0 , "Ok execute has terminated just fine");
  ok( $cse->command()->hits() , "Ok got hits");
  is( $cse->command()->hits()->total_hits() , 0, "Ok got zero hit");
}

{
  ## Searching in ini file
  local @ARGV = (  '--idx='.$idx_dir, 'ini_file_section' );
  my $cse = App::CSE->new();
  is( $cse->command()->execute(), 0 , "Ok execute has terminated just fine");
  ok( $cse->command()->hits() , "Ok got hits");
  is( $cse->command()->hits()->total_hits() , 1, "Ok got zero hit");
}

{
  ## Searching a template toolkit file
  local @ARGV = (  '--idx='.$idx_dir, 'template_toolkit mime:application/x-templatetoolkit');
  my $cse = App::CSE->new();
  is( $cse->command()->execute(), 0 , "Ok execute has terminated just fine");
  ok( $cse->command()->hits() , "Ok got hits");
  is( $cse->command()->hits()->total_hits() , 1, "Ok got one hit");
}

{
  ## Searching a java file
  local @ARGV = (  '--idx='.$idx_dir, 'Java mime:text/x-java');
  my $cse = App::CSE->new();
  is( $cse->command()->execute(), 0 , "Ok execute has terminated just fine");
  ok( $cse->command()->hits() , "Ok got hits");
  is( $cse->command()->hits()->total_hits() , 1, "Ok got one hit");
}

{
  ## Searching a scala file
  local @ARGV = (  '--idx='.$idx_dir, 'scala mime:text/x-scala');
  my $cse = App::CSE->new();
  is( $cse->command()->execute(), 0 , "Ok execute has terminated just fine");
  ok( $cse->command()->hits() , "Ok got hits");
  is( $cse->command()->hits()->total_hits() , 1, "Ok got one hit");
}

{
  ## Searching a scala file excluding declaration
  local @ARGV = (  '--idx='.$idx_dir, 'scala -decl:FooClass mime:text/x-scala');
  my $cse = App::CSE->new();
  is( $cse->command()->execute(), 0 , "Ok execute has terminated just fine");
  ok( $cse->command()->hits() , "Ok got hits");
  is( $cse->command()->hits()->total_hits() , 0, "Ok no hit because FooClass is in declarations");
}

{
  ## Searching for CSharp
  local @ARGV = (  '--idx='.$idx_dir, 'CSHarp mime:text/x-csharp');
  my $cse = App::CSE->new();
  is( $cse->command()->execute(), 0 , "Ok execute has terminated just fine");
  ok( $cse->command()->hits() , "Ok got hits");
  is( $cse->command()->hits()->total_hits() , 1, "Ok got one hit");
}

{
  ## Searching for php_test
  local @ARGV = (  '--idx='.$idx_dir, 'php_test');
  my $cse = App::CSE->new();
  is( $cse->command()->execute(), 0 , "Ok execute has terminated just fine");
  ok( $cse->command()->hits() , "Ok got hits");
  is( $cse->command()->hits()->total_hits() , 1, "Ok got one hit");
}

{
  ## Searching for pythonesque
  local @ARGV = (  '--idx='.$idx_dir, 'pythonesque');
  my $cse = App::CSE->new();
  is( $cse->command()->execute(), 0 , "Ok execute has terminated just fine");
  ok( $cse->command()->hits() , "Ok got hits");
  is( $cse->command()->hits()->total_hits() , 1, "Ok got one hit");
}

{
  ## Searching for hypertext (from the XHTML file).
  local @ARGV = (  '--idx='.$idx_dir, 'HyperText');
  my $cse = App::CSE->new();
  is( $cse->command()->execute(), 0 , "Ok execute has terminated just fine");
  ok( $cse->command()->hits() , "Ok got hits");
  is( $cse->command()->hits()->total_hits() , 1, "Ok got one hit");
}

{
  ## Searching for this_is_an_html_file (from the HTML file).
  local @ARGV = (  '--idx='.$idx_dir, 'This_is_an_html_file');
  my $cse = App::CSE->new();
  is( $cse->command()->execute(), 0 , "Ok execute has terminated just fine");
  ok( $cse->command()->hits() , "Ok got hits");
  is( $cse->command()->hits()->total_hits() , 1, "Ok got one hit");
}

{
  ## Searching for c_plus_plus (from the .cc and .cpp file).
  local @ARGV = (  '--idx='.$idx_dir, 'c_plus_plus');
  my $cse = App::CSE->new();
  is( $cse->command()->execute(), 0 , "Ok execute has terminated just fine");
  ok( $cse->command()->hits() , "Ok got hits");
  is( $cse->command()->hits()->total_hits() , 2, "Ok got two hits. One from the .cc and one from the .cpp");
}

{
  ## Searching for head_h (from the .h file).
  local @ARGV = (  '--idx='.$idx_dir, 'head_h');
  my $cse = App::CSE->new();
  is( $cse->command()->execute(), 0 , "Ok execute has terminated just fine");
  ok( $cse->command()->hits() , "Ok got hits");
  is( $cse->command()->hits()->total_hits() , 1, "Ok got one hit");
}

ok(1);
done_testing();

t/06-update.t  view on Meta::CPAN

my $c_dir = File::Temp->newdir( CLEANUP => 1 );
my $content_dir = Path::Class::Dir->new( $c_dir );

my $bonjour_file = $content_dir->file('bonjour_file.txt');
File::Slurp::write_file($bonjour_file.'', 'bonjour' );
my $soon_gone = $content_dir->file('soon_gone.txt');
File::Slurp::write_file($soon_gone.'', 'soonGone');

{
  ## Index and search the content dir
  local @ARGV = (  '--idx='.$idx_dir, 'bonjour', '--dir='.$content_dir.'');
  my $cse = App::CSE->new();
  is( $cse->command()->execute(), 0 , "Ok execute has terminated just fine");
  is( $cse->command()->hits()->total_hits() , 1 , "Ok got one hits");
}

{
  # Touch the file (write it again) and check it is now dirty
  sleep(1); # Let one second go.
  File::Slurp::write_file($bonjour_file.'', 'bonsoir' );
  local @ARGV = (  '--idx='.$idx_dir, 'bonjour', '--dir='.$content_dir.'');
  my $cse = App::CSE->new();
  is( $cse->command()->execute(), 0 , "Ok execute has terminated just fine");
  is( $cse->command()->hits->total_hits() , 1 , "Ok got one hit for bonjour, even if the file now says bonsoir");
  ok( $cse->dirty_files()->{$bonjour_file.''} , "Ok this file is now dirty");
}

{
    # Remove the soon_gone file and search for it to check it is marked as dirty.
    unlink $soon_gone;
    local @ARGV = (  '--idx='.$idx_dir, 'soonGone', '--dir='.$content_dir.'');
    my $cse = App::CSE->new();
    is( $cse->command()->execute(), 0 , "Ok execute has terminated just fine");
    is( $cse->command()->hits->total_hits() , 1 , "Ok got one hit for bonjour, even if the file now says bonsoir");
    ok( $cse->dirty_files()->{$soon_gone.''} , "Ok this file is now dirty");
}


{
  # Update and check the dirt is gone.
  local @ARGV = ( 'update', '--idx='.$idx_dir, '--dir='.$content_dir.'');
  my $cse = App::CSE->new();
  ok( $cse->command()->isa('App::CSE::Command::Update') , "Ok good command class");
  is( $cse->command()->execute(), 0 , "Ok execute has terminated just fine");
  ok( ! $cse->dirty_files()->{$bonjour_file.''} , "Ok dirt is gone");
  ok( ! $cse->dirty_files()->{$soon_gone.''} , "Ok gone file is gone");
}

{
  ## Search for bonjour, check we cannot find anything.
  local @ARGV = (  '--idx='.$idx_dir, 'bonjour', '--dir='.$content_dir.'');
  my $cse = App::CSE->new();
  is( $cse->command()->execute(), 0 , "Ok execute has terminated just fine");
  is( $cse->command()->hits()->total_hits() , 0 , "Ok got zero hit on bonjour");
}

{
  ## Search for bonsoir
  local @ARGV = (  '--idx='.$idx_dir, 'bonsoir', '--dir='.$content_dir.'');
  my $cse = App::CSE->new();
  is( $cse->command()->execute(), 0 , "Ok execute has terminated just fine");
  is( $cse->command()->hits()->total_hits() , 1 , "Ok got one hits");
}


ok(1);
done_testing();

t/07-decl.t  view on Meta::CPAN

}



my $idx_dir = File::Temp->newdir( CLEANUP => 1 );
my $content_dir = Path::Class::Dir->new('t/toindex');

## Testing the decl field
{
  ## Searching for some_method
  local @ARGV = (  '--idx='.$idx_dir, 'some_method', '--dir='.$content_dir.'');
  my $cse = App::CSE->new();
  is( $cse->command()->execute(), 0 , "Ok execute has terminated just fine");
  ok( $cse->command()->hits() , "Ok got hits");
  is( $cse->command()->hits()->total_hits() , 2 , "Ok two hits");
}

SKIP: {
    skip "Perl too old.", 3  unless ( $] ge '5.14' );
    ## Searching for some method, but excluding the declaration
    local @ARGV = (  '--idx='.$idx_dir, 'some_method', '-decl:some_method', '--dir='.$content_dir.'');
    my $cse = App::CSE->new();
    is( $cse->command()->execute(), 0 , "Ok execute has terminated just fine");
    ok( $cse->command()->hits() , "Ok got hits");
    is( $cse->command()->hits()->total_hits() , 1 , "Ok one hit only");
};

ok(1);
done_testing();

t/08-meta.t  view on Meta::CPAN



my $idx_dir = File::Temp->newdir( CLEANUP => 1 );
my $content_dir = Path::Class::Dir->new('t/toindex');

# We are trying to cover as many languages from http://langpop.corger.nl/
# as possible.

{
  ## Searching for some javascript.
  local @ARGV = (  '--idx='.$idx_dir, 'javascriptIsGreat', '--dir='.$content_dir.'');
  my $cse = App::CSE->new();

  is( $cse->index_meta->{version} , '-unknown-' , "Ok good unknown version");

  is( $cse->command()->execute(), 0 , "Ok execute has terminated just fine");
  ok( $cse->command()->hits() , "Ok got hits");
  is( $cse->command()->hits()->total_hits() , 1 , "Ok got one hit");

  is( $cse->index_meta->{version} , $cse->version() , "Ok good version in index meta");
}

{
  ## Build the object, but not the index again.
  local @ARGV = (  '--idx='.$idx_dir, 'javascriptIsGreat', '--dir='.$content_dir.'');
  my $cse = App::CSE->new();
  is( $cse->index_meta->{version} , $cse->version() , "Ok good version in index meta");
  ok( $cse->index_meta->{index_time} , "Ok got an index time");
}




ok(1);
done_testing();

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



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{

 view all matches for this distribution
 view release on metacpan -  search on metacpan

( run in 1.900 second using v1.00-cache-2.02-grep-82fe00e-cpan-d29e8ade9f55 )