Skip to content

Commit

Permalink
Added tests for add_functionality()
Browse files Browse the repository at this point in the history
  • Loading branch information
stevieb9 committed Jan 12, 2016
1 parent 6f3681b commit 0ab586e
Show file tree
Hide file tree
Showing 6 changed files with 174 additions and 4 deletions.
7 changes: 6 additions & 1 deletion lib/Devel/Examine/Subs.pm
Expand Up @@ -240,7 +240,6 @@ sub add_functionality {
$self->_config($p);

my $to_add = $self->{params}{add_functionality};

my $in_prod = $self->{params}{add_functionality_prod};

my @allowed = qw(
Expand Down Expand Up @@ -304,6 +303,12 @@ sub add_functionality {
}

my $file = $dt{$to_add}->();
my $copy = $self->{params}{copy};

if ($copy) {
copy $file, $copy or die $!;
$file = $copy;
}

my $des = Devel::Examine::Subs->new(
file => $file,
Expand Down
4 changes: 2 additions & 2 deletions t/02-file_extentions.t
Expand Up @@ -33,7 +33,7 @@ use_ok( 'File::Edit::Portable' ) || print "Bail out!\n";
types => [qw(*.t)],
);

is (@files, 54, "using *.t extension works properly");
is (@files, 57, "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, 61, "using *.data and *.t extensions works properly");
is (@files, 64, "using *.data and *.t extensions works properly");

}

54 changes: 54 additions & 0 deletions t/50-add_func_engine.t
@@ -0,0 +1,54 @@
#!/usr/bin/perl
use warnings;
use strict;

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

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);
my $ret = $des->add_functionality(add_functionality => 'engine');
is ($ret, 1, "add_functionality engine succeeded");
}
else {
my $des = Devel::Examine::Subs->new(%params);
my $struct = $des->run(\%params);
print Dumper $struct;
}

open my $fh, '<', $copy or die $!;
my @file = <$fh>;
close $fh;

is ((grep { $_ =~ /testing =>/ } @file), 1, "dt updated ok");
is ((grep { $_ =~ /sub testing \{/ } @file), 1, "sub added ok");

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

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

my $file = 't/sample.data';
my $copy = 't/add_func_preproc.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);
my $ret = $des->add_functionality(add_functionality => 'pre_proc');
is ($ret, 1, "add_functionality pre_proc succeeded");
}
else {
my $des = Devel::Examine::Subs->new(%params);
my $struct = $des->run(\%params);
print Dumper $struct;
}

open my $fh, '<', $copy or die $!;
my @file = <$fh>;
close $fh;

is ((grep { $_ =~ /testing =>/ } @file), 1, "dt updated ok");
is ((grep { $_ =~ /sub testing \{/ } @file), 1, "sub added correctly");

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

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

my $file = 't/sample.data';
my $copy = 't/add_func_postproc.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);
my $ret = $des->add_functionality(add_functionality => 'post_proc');
is ($ret, 1, "add_functionality post_proc succeeded");
}
else {
my $des = Devel::Examine::Subs->new(%params);
my $struct = $des->run(\%params);
print Dumper $struct;
}

open my $fh, '<', $copy or die $!;
my @file = <$fh>;
close $fh;

is ((grep { $_ =~ /testing =>/ } @file), 1, "dt updated ok");
is ((grep { $_ =~ /sub testing \{/ } @file), 1, "sub added correctly");

eval { unlink $copy or die $!; };
is ($@, '', "temp file removed ok");
5 changes: 4 additions & 1 deletion t/__clean.t
Expand Up @@ -2,7 +2,7 @@
use warnings;
use strict;

use Test::More tests => 30;
use Test::More tests => 36;
use File::Copy qw(copy);

BEGIN {#1
Expand Down Expand Up @@ -36,6 +36,9 @@ my @files_to_delete = qw(
t/post_proc_dump.debug
t/pre_proc_dump.debug
t/remove.data
t/add_func_engine.data
t/add_func_postproc.data
t/add_func_preproc.data
);
my @bak_glob = <*.bak>;

Expand Down

0 comments on commit 0ab586e

Please sign in to comment.