line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
1
|
|
|
1
|
|
774
|
use 5.010001; |
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
34
|
|
2
|
1
|
|
|
1
|
|
5
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
27
|
|
3
|
1
|
|
|
1
|
|
13
|
use warnings; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
63
|
|
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
package Dist::Inkt::Role::Test; |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
our $AUTHORITY = 'cpan:TOBYINK'; |
8
|
|
|
|
|
|
|
our $VERSION = '0.002'; |
9
|
|
|
|
|
|
|
|
10
|
1
|
|
|
1
|
|
370
|
use Moose::Role; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
use File::chdir; |
12
|
|
|
|
|
|
|
use Try::Tiny; |
13
|
|
|
|
|
|
|
use Types::Standard -types; |
14
|
|
|
|
|
|
|
use namespace::autoclean; |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
for my $category (qw( prebuild_test build_test tarball_test )) |
17
|
|
|
|
|
|
|
{ |
18
|
|
|
|
|
|
|
has "${category}s" => ( |
19
|
|
|
|
|
|
|
traits => ["Array"], |
20
|
|
|
|
|
|
|
is => "ro", |
21
|
|
|
|
|
|
|
isa => ArrayRef[CodeRef], |
22
|
|
|
|
|
|
|
default => sub { [] }, |
23
|
|
|
|
|
|
|
handles => { "setup_${category}" => "push" }, |
24
|
|
|
|
|
|
|
init_arg => undef, |
25
|
|
|
|
|
|
|
lazy => 1, |
26
|
|
|
|
|
|
|
); |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
has "skip_${category}s" => ( |
29
|
|
|
|
|
|
|
is => "ro", |
30
|
|
|
|
|
|
|
isa => Bool, |
31
|
|
|
|
|
|
|
default => 0, |
32
|
|
|
|
|
|
|
); |
33
|
|
|
|
|
|
|
} |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
has _build_tests_already_run => (is => "rw", isa => Bool, default => 0); |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
before BuildTargets => sub |
38
|
|
|
|
|
|
|
{ |
39
|
|
|
|
|
|
|
my $self = shift; |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
return unless @{$self->prebuild_tests}; |
42
|
|
|
|
|
|
|
return $self->log("Skipping pre-build tests") |
43
|
|
|
|
|
|
|
if $self->skip_prebuild_tests; |
44
|
|
|
|
|
|
|
$self->log("Running pre-build tests..."); |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
my $die = 0; |
47
|
|
|
|
|
|
|
for my $test (@{ $self->prebuild_tests }) |
48
|
|
|
|
|
|
|
{ |
49
|
|
|
|
|
|
|
try { |
50
|
|
|
|
|
|
|
$self->$test(); |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
catch { |
53
|
|
|
|
|
|
|
$self->log("ERROR: $_"); |
54
|
|
|
|
|
|
|
++$die; |
55
|
|
|
|
|
|
|
}; |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
die "Failed pre-build test; stopped" if $die; |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
$self->_build_tests_already_run(0); # reset bool |
60
|
|
|
|
|
|
|
}; |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
my $tmp = sub |
63
|
|
|
|
|
|
|
{ |
64
|
|
|
|
|
|
|
my $self = shift; |
65
|
|
|
|
|
|
|
return if $self->_build_tests_already_run; |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
return unless @{$self->build_tests}; |
68
|
|
|
|
|
|
|
return $self->log("Skipping build tests") |
69
|
|
|
|
|
|
|
if $self->skip_build_tests; |
70
|
|
|
|
|
|
|
$self->log("Running build tests..."); |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
my $die = 0; |
73
|
|
|
|
|
|
|
my $dir = $self->targetdir->absolute; |
74
|
|
|
|
|
|
|
for my $test (@{ $self->build_tests }) |
75
|
|
|
|
|
|
|
{ |
76
|
|
|
|
|
|
|
try { |
77
|
|
|
|
|
|
|
local $CWD = $dir->stringify; |
78
|
|
|
|
|
|
|
$self->$test($dir); |
79
|
|
|
|
|
|
|
} |
80
|
|
|
|
|
|
|
catch { |
81
|
|
|
|
|
|
|
$self->log("ERROR: $_"); |
82
|
|
|
|
|
|
|
++$die; |
83
|
|
|
|
|
|
|
}; |
84
|
|
|
|
|
|
|
} |
85
|
|
|
|
|
|
|
die "Failed build test; stopped" if $die; |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
$self->_build_tests_already_run(1); |
88
|
|
|
|
|
|
|
}; |
89
|
|
|
|
|
|
|
# Numerous opportunities to try to run these tests |
90
|
|
|
|
|
|
|
after [qw/BuildManifest BuildAll/] => $tmp; |
91
|
|
|
|
|
|
|
before [qw/BuildTarball/] => $tmp; |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
after BuildTarball => sub |
94
|
|
|
|
|
|
|
{ |
95
|
|
|
|
|
|
|
my $self = shift; |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
return unless @{$self->tarball_tests}; |
98
|
|
|
|
|
|
|
return $self->log("Skipping tarball tests") |
99
|
|
|
|
|
|
|
if $self->skip_tarball_tests; |
100
|
|
|
|
|
|
|
$self->log("Running tarball tests..."); |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
my $die = 0; |
103
|
|
|
|
|
|
|
my $file = Path::Tiny::path($_[0] || sprintf('%s.tar.gz', $self->targetdir)); |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
for my $test (@{ $self->tarball_tests }) |
106
|
|
|
|
|
|
|
{ |
107
|
|
|
|
|
|
|
try { |
108
|
|
|
|
|
|
|
$self->$test($file); |
109
|
|
|
|
|
|
|
} |
110
|
|
|
|
|
|
|
catch { |
111
|
|
|
|
|
|
|
$self->log("ERROR: $_"); |
112
|
|
|
|
|
|
|
++$die; |
113
|
|
|
|
|
|
|
}; |
114
|
|
|
|
|
|
|
} |
115
|
|
|
|
|
|
|
die "Failed tarball test; stopped" if $die; |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
$self->_build_tests_already_run(1); |
118
|
|
|
|
|
|
|
}; |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
1; |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
__END__ |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
=pod |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
=encoding utf-8 |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
=head1 NAME |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
Dist::Inkt::Role::Test - run various tests on a distribution at build time |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
=head1 SYNOPSIS |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
package Dist::Inkt::Profile::JOEBLOGGS; |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
use Moose; |
137
|
|
|
|
|
|
|
extends qw(Dist::Inkt); |
138
|
|
|
|
|
|
|
with ( |
139
|
|
|
|
|
|
|
..., |
140
|
|
|
|
|
|
|
"Dist::Inkt::Role::Test", |
141
|
|
|
|
|
|
|
..., |
142
|
|
|
|
|
|
|
); |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
after BUILD => sub { |
145
|
|
|
|
|
|
|
my $self = shift; |
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
# Run a test before attempting to build |
148
|
|
|
|
|
|
|
# the dist dir. |
149
|
|
|
|
|
|
|
# |
150
|
|
|
|
|
|
|
$self->setup_prebuild_test(sub { |
151
|
|
|
|
|
|
|
die "rude!" if $self->name =~ /Arse/; |
152
|
|
|
|
|
|
|
}); |
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
# Run a test after building the dist dir. |
155
|
|
|
|
|
|
|
# |
156
|
|
|
|
|
|
|
$self->setup_build_test(sub { |
157
|
|
|
|
|
|
|
die "missing change log" unless -f "Changes"; |
158
|
|
|
|
|
|
|
}); |
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
# Run a test after tarballing the dist dir. |
161
|
|
|
|
|
|
|
# |
162
|
|
|
|
|
|
|
$self->setup_tarball_test(sub { |
163
|
|
|
|
|
|
|
my $tarball = $_[1] |
164
|
|
|
|
|
|
|
die "too big" if $tarball->stat->size > 1_000_000; |
165
|
|
|
|
|
|
|
}); |
166
|
|
|
|
|
|
|
}; |
167
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
1; |
169
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
=head1 DESCRIPTION |
171
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
This role exists to provide hooks for L<Dist::Inkt> subclasses and |
173
|
|
|
|
|
|
|
other roles to run tests. |
174
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
Bundled with this role are a few other roles that consume it in |
176
|
|
|
|
|
|
|
useful ways. |
177
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
=head1 BUGS |
179
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
Please report any bugs to |
181
|
|
|
|
|
|
|
L<http://rt.cpan.org/Dist/Display.html?Queue=Dist-Inkt-Role-Test>. |
182
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
=head1 SEE ALSO |
184
|
|
|
|
|
|
|
|
185
|
|
|
|
|
|
|
L<Dist::Inkt>. |
186
|
|
|
|
|
|
|
|
187
|
|
|
|
|
|
|
=head1 AUTHOR |
188
|
|
|
|
|
|
|
|
189
|
|
|
|
|
|
|
Toby Inkster E<lt>tobyink@cpan.orgE<gt>. |
190
|
|
|
|
|
|
|
|
191
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENCE |
192
|
|
|
|
|
|
|
|
193
|
|
|
|
|
|
|
This software is copyright (c) 2014 by Toby Inkster. |
194
|
|
|
|
|
|
|
|
195
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
196
|
|
|
|
|
|
|
the same terms as the Perl 5 programming language system itself. |
197
|
|
|
|
|
|
|
|
198
|
|
|
|
|
|
|
|
199
|
|
|
|
|
|
|
=head1 DISCLAIMER OF WARRANTIES |
200
|
|
|
|
|
|
|
|
201
|
|
|
|
|
|
|
THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED |
202
|
|
|
|
|
|
|
WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF |
203
|
|
|
|
|
|
|
MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. |
204
|
|
|
|
|
|
|
|