line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Test::NaiveStubs; |
2
|
|
|
|
|
|
|
our $AUTHORITY = 'cpan:GENE'; |
3
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
# ABSTRACT: Generate test stubs for methods and functions |
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
our $VERSION = '0.0703'; |
7
|
|
|
|
|
|
|
|
8
|
1
|
|
|
1
|
|
941
|
use strictures 2; |
|
1
|
|
|
|
|
1382
|
|
|
1
|
|
|
|
|
32
|
|
9
|
1
|
|
|
1
|
|
577
|
use Moo; |
|
1
|
|
|
|
|
9415
|
|
|
1
|
|
|
|
|
4
|
|
10
|
1
|
|
|
1
|
|
1623
|
use Package::Stash (); |
|
1
|
|
|
|
|
4103
|
|
|
1
|
|
|
|
|
24
|
|
11
|
1
|
|
|
1
|
|
358
|
use Sub::Identify 'stash_name'; |
|
1
|
|
|
|
|
821
|
|
|
1
|
|
|
|
|
50
|
|
12
|
1
|
|
|
1
|
|
377
|
use namespace::clean; |
|
1
|
|
|
|
|
4841
|
|
|
1
|
|
|
|
|
5
|
|
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
has module => ( |
16
|
|
|
|
|
|
|
is => 'ro', |
17
|
|
|
|
|
|
|
required => 1, |
18
|
|
|
|
|
|
|
); |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
has name => ( |
22
|
|
|
|
|
|
|
is => 'ro', |
23
|
|
|
|
|
|
|
builder => 1, |
24
|
|
|
|
|
|
|
); |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
sub _build_name { |
27
|
1
|
|
|
1
|
|
7
|
my ($self) = @_; |
28
|
1
|
|
|
|
|
6
|
( my $name = $self->module ) =~ s/::/-/g; |
29
|
1
|
|
|
|
|
2
|
$name = lc $name; |
30
|
1
|
|
|
|
|
5
|
return "$name.t"; |
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
has subs => ( |
35
|
|
|
|
|
|
|
is => 'rw', |
36
|
|
|
|
|
|
|
init_arg => undef, |
37
|
|
|
|
|
|
|
); |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
has is_oo => ( |
41
|
|
|
|
|
|
|
is => 'rw', |
42
|
|
|
|
|
|
|
init_arg => undef, |
43
|
|
|
|
|
|
|
default => sub { 0 }, |
44
|
|
|
|
|
|
|
); |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
sub gather_subs { |
48
|
2
|
|
|
2
|
1
|
841
|
my ($self) = @_; |
49
|
|
|
|
|
|
|
|
50
|
2
|
|
|
|
|
44
|
my $subs = Package::Stash->new($self->module)->get_all_symbols('CODE'); |
51
|
|
|
|
|
|
|
|
52
|
2
|
|
|
|
|
6
|
my @subs; |
53
|
2
|
|
|
|
|
7
|
for my $sub ( keys %$subs ) { |
54
|
18
|
|
|
|
|
35
|
my $packagename = stash_name($subs->{$sub}); |
55
|
18
|
50
|
|
|
|
79
|
push @subs, $sub if $packagename eq $self->module; |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
|
58
|
2
|
|
|
|
|
3
|
my %subs; |
59
|
2
|
|
|
|
|
8
|
@subs{@subs} = undef; |
60
|
|
|
|
|
|
|
|
61
|
2
|
|
|
|
|
18
|
$self->subs( \%subs ); |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
sub unit_test { |
66
|
11
|
|
|
11
|
1
|
1460
|
my ($self, $subroutine) = @_; |
67
|
|
|
|
|
|
|
|
68
|
11
|
|
|
|
|
27
|
my $test = ''; |
69
|
|
|
|
|
|
|
|
70
|
11
|
100
|
|
|
|
27
|
if ( $subroutine eq 'new' ) { |
|
|
100
|
|
|
|
|
|
71
|
2
|
|
|
|
|
13
|
$test = 'use_ok "' . $self->module . '";' |
72
|
|
|
|
|
|
|
. "\n\n" |
73
|
|
|
|
|
|
|
. 'my $obj = ' . $self->module . '->new;' |
74
|
|
|
|
|
|
|
. "\n" |
75
|
|
|
|
|
|
|
. 'isa_ok $obj, "' . $self->module . '";'; |
76
|
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
elsif ( $self->is_oo ) { |
78
|
7
|
|
|
|
|
12
|
$test = 'ok $obj->can("' . $subroutine . '"), "' . $subroutine . '";'; |
79
|
|
|
|
|
|
|
} |
80
|
|
|
|
|
|
|
else { |
81
|
2
|
|
|
|
|
7
|
$test = "ok $subroutine(), " . '"' . $subroutine . '";'; |
82
|
|
|
|
|
|
|
} |
83
|
|
|
|
|
|
|
|
84
|
11
|
|
|
|
|
21
|
return $test; |
85
|
|
|
|
|
|
|
} |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
sub create_test { |
89
|
1
|
|
|
1
|
1
|
447
|
my ($self) = @_; |
90
|
|
|
|
|
|
|
|
91
|
1
|
50
|
|
|
|
86
|
open my $fh, '>', $self->name or die "Can't write " . $self->name . ": $!"; |
92
|
|
|
|
|
|
|
|
93
|
1
|
|
|
|
|
5
|
my $text =<<'END'; |
94
|
|
|
|
|
|
|
use strict; |
95
|
|
|
|
|
|
|
use warnings; |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
use Test::More; |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
END |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
# Set the subs attribute |
102
|
1
|
|
|
|
|
4
|
$self->gather_subs; |
103
|
|
|
|
|
|
|
|
104
|
1
|
50
|
|
|
|
5
|
if ( exists $self->subs->{new} ) { |
105
|
1
|
|
|
|
|
3
|
$self->is_oo(1); |
106
|
|
|
|
|
|
|
|
107
|
1
|
|
|
|
|
2
|
my $test = $self->unit_test('new'); |
108
|
|
|
|
|
|
|
|
109
|
1
|
|
|
|
|
3
|
$text .= "$test\n\n"; |
110
|
|
|
|
|
|
|
} |
111
|
|
|
|
|
|
|
|
112
|
1
|
|
|
|
|
1
|
for my $sub ( sort keys %{ $self->subs } ) { |
|
1
|
|
|
|
|
7
|
|
113
|
9
|
100
|
|
|
|
17
|
next if $sub =~ /^_/; |
114
|
8
|
100
|
|
|
|
13
|
next if $sub eq 'new'; |
115
|
|
|
|
|
|
|
|
116
|
7
|
|
|
|
|
11
|
my $test = $self->unit_test($sub); |
117
|
|
|
|
|
|
|
|
118
|
7
|
|
|
|
|
12
|
$text .= "$test\n\n"; |
119
|
|
|
|
|
|
|
} |
120
|
|
|
|
|
|
|
|
121
|
1
|
|
|
|
|
2
|
$text .= 'done_testing(); |
122
|
|
|
|
|
|
|
'; |
123
|
|
|
|
|
|
|
|
124
|
1
|
|
|
|
|
73
|
print $fh $text; |
125
|
|
|
|
|
|
|
} |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
1; |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
__END__ |