Skip to content

Commit

Permalink
added tests for post_proc multi and _engine()
Browse files Browse the repository at this point in the history
  • Loading branch information
stevieb9 committed Jan 12, 2016
1 parent 6424bfa commit 11aeed6
Show file tree
Hide file tree
Showing 5 changed files with 113 additions and 7 deletions.
6 changes: 3 additions & 3 deletions t/02-file_extentions.t
Expand Up @@ -25,15 +25,15 @@ use_ok( 'File::Edit::Portable' ) || print "Bail out!\n";
maxdepth => 1,
);

ok (@files >= 50 && @files <= 60, "things appear reasonable with maxdepth param set");
ok (@files >= 60 && @files <= 70, "things appear reasonable with maxdepth param set");

@files = $rw->dir(
dir => $dir,
list => 1,
types => [qw(*.t)],
);

is (@files, 57, "using *.t extension works properly");
is (@files, 59, "using *.t extension works properly");

@files = $rw->dir(
dir => $dir,
Expand All @@ -49,7 +49,7 @@ use_ok( 'File::Edit::Portable' ) || print "Bail out!\n";
types => [qw(*.data *.t)],
);

is (@files, 64, "using *.data and *.t extensions works properly");
is (@files, 66, "using *.data and *.t extensions works properly");

}

15 changes: 14 additions & 1 deletion t/11-Engine.t
Expand Up @@ -2,7 +2,7 @@
use warnings;
use strict;

use Test::More tests => 9;
use Test::More tests => 11;

use Data::Dumper;

Expand Down Expand Up @@ -52,7 +52,20 @@ my $engine = $compiler->{engines}{_test}->();

like ( $@, qr/'asdfasdf'/, "engine module croaks if an invalid internal engine is called" );
}
{
my $des = Devel::Examine::Subs->new;

my $cref = sub { return 55; };
my $p = {
engine => $cref,
};

my $ret = $des->_engine($p, {a => 1});

is (ref $ret, 'CODE', "_engine() returns a cref properly");
is ($ret->(), 55, "...and the cref does the right thing");

}
sub _engine {
my $p = shift;
return \&{$compiler->{engines}{$p}};
Expand Down
5 changes: 2 additions & 3 deletions t/45-inject.t
Expand Up @@ -62,18 +62,17 @@ my $rw = File::Edit::Portable->new;
copy => $copy,
);

my @code = ('hello();', "\n", 'there();');

$des->inject(inject_after_sub_def => \@code);

my @c = $rw->read($copy);

is ($c[4], ' hello();', "inject() inserts use statement properly after multi-line sub def");
is ($c[4], ' one', "inject() inserts use statement properly after multi-line sub def");

eval { unlink $copy; };
is ($@, '', "unlinked copy file $copy ok");
}
__DATA__
one
two
three
46 changes: 46 additions & 0 deletions t/53-add_func_bad_code.t
@@ -0,0 +1,46 @@
#!/usr/bin/perl
use warnings;
use strict;

use Data::Dumper;
use Devel::Examine::Subs;
use File::Copy;
use Test::More tests => 2;

my $file = 't/sample.data';
my $copy = 't/add_func_engine.data';

my %params = (
file => $file,
copy => $copy,
post_proc => [ 'file_lines_contain' ],
engine => testing(),
);

#<des>
sub
testing {

return sub {

my $p = shift;
my $struct = shift;

return $struct;
};
}
#</des>

my $install = 1; # set this to true to install

if ($install) {
my $des = Devel::Examine::Subs->new(copy => $copy);
eval { $des->add_functionality(add_functionality => 'engine'); };
like ($@,
qr/couldn't extract the sub name/,
"with a malformed sub def line, we croak"
);
}

eval { unlink $copy or die $!; };
is ($@, '', "temp file removed ok");
48 changes: 48 additions & 0 deletions t/54-post_proc_dump_multi.t
@@ -0,0 +1,48 @@
#!perl
use warnings;
use strict;

use Test::More tests => 8;
use Test::Trap;

BEGIN {#1
use_ok( 'Devel::Examine::Subs' ) || print "Bail out!\n";
}

my $des = Devel::Examine::Subs->new(
file => 't/sample.data',
engine => 'all',
post_proc => ['file_lines_contain', 'subs', 'objects'],
);

{#2 - post_proc dump

my $file = 't/post_proc_dump.debug';

do {

eval { open STDOUT, '>', $file or die $!; };
ok (! $@, "STDOUT redirected for post_proc dump");

my @exit = trap { $des->run({post_proc_dump => 2}); };

eval { print STDOUT $trap->stdout; };
is (! $trap->stdout, '', "output to stdout" );
ok (! $@, "post_proc dump gave no errors" );

};

eval { open my $fh, '<', $file or die $!; };
ok (! $@, "post_proc dump output file exists and can be read" );
open my $fh, '<', $file or die $!;

my @lines = <$fh>;
is (@lines, 138, "Based on test data, post_proc dump dumps the correct info" );

eval { close $fh; };
ok (! $@, "post_proc dump output file closed successfully" );

eval { unlink $file; };
ok (! $@, "post_proc dump temp file deleted successfully" );
}

0 comments on commit 11aeed6

Please sign in to comment.