/
51-add_func_preproc.t
54 lines (42 loc) · 1.11 KB
/
51-add_func_preproc.t
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
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");