line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Test::Run::CmdLine::Iface; |
2
|
|
|
|
|
|
|
|
3
|
4
|
|
|
4
|
|
159854
|
use warnings; |
|
4
|
|
|
|
|
11
|
|
|
4
|
|
|
|
|
162
|
|
4
|
4
|
|
|
4
|
|
22
|
use strict; |
|
4
|
|
|
|
|
8
|
|
|
4
|
|
|
|
|
199
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
extends ('Test::Run::Base'); |
7
|
|
|
|
|
|
|
|
8
|
4
|
|
|
4
|
|
5307
|
use UNIVERSAL::require; |
|
4
|
|
|
|
|
8547
|
|
|
4
|
|
|
|
|
38
|
|
9
|
|
|
|
|
|
|
|
10
|
4
|
|
|
4
|
|
3329
|
use Test::Run::CmdLine; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
use Moose; |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
=head1 NAME |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
Test::Run::CmdLine::Iface - Analyze tests from the command line using Test::Run |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
=head1 SYNOPSIS |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
use Test::Run::CmdLine::Iface; |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
my $tester = Test::Run::CmdLine::Iface->new( |
23
|
|
|
|
|
|
|
{ |
24
|
|
|
|
|
|
|
'test_files' => ["t/one.t", "t/two.t"], |
25
|
|
|
|
|
|
|
} |
26
|
|
|
|
|
|
|
); |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
$tester->run(); |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
=cut |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
has 'driver_class' => (is => "rw", isa => "Str", init_arg => undef,); |
33
|
|
|
|
|
|
|
has 'driver_plugins' => (is => "rw", isa => "ArrayRef", |
34
|
|
|
|
|
|
|
default => sub { [] }, init_arg => undef,); |
35
|
|
|
|
|
|
|
has '_driver_class_arg' => (is => "ro", isa => "Str", init_arg => "driver_class"); |
36
|
|
|
|
|
|
|
has '_driver_plugins_arg' => (is => "ro", isa => "Maybe[ArrayRef]", init_arg => "driver_plugins"); |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
has 'test_files' => (is => "rw", isa => "ArrayRef", default => sub { [] },); |
39
|
|
|
|
|
|
|
has 'backend_params' => (is => "rw", isa => "HashRef", predicate => "has_backend_params"); |
40
|
|
|
|
|
|
|
has '_is_driver_class_prepared' => (is => "rw", isa => "Bool", default => 0); |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
sub BUILD |
43
|
|
|
|
|
|
|
{ |
44
|
|
|
|
|
|
|
my ($self) = @_; |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
my $driver_class = $self->_driver_class_arg() ; |
47
|
|
|
|
|
|
|
my $plugins = $self->_driver_plugins_arg(); |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
if ($driver_class || $plugins) |
50
|
|
|
|
|
|
|
{ |
51
|
|
|
|
|
|
|
$self->_set_driver( |
52
|
|
|
|
|
|
|
{ |
53
|
|
|
|
|
|
|
'class' => ($driver_class || |
54
|
|
|
|
|
|
|
"Test::Run::CmdLine::Drivers::Default"), |
55
|
|
|
|
|
|
|
'plugins' => ($plugins || []), |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
); |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
elsif ($ENV{'HARNESS_DRIVER'} || $ENV{'HARNESS_PLUGINS'}) |
60
|
|
|
|
|
|
|
{ |
61
|
|
|
|
|
|
|
$self->_set_driver( |
62
|
|
|
|
|
|
|
{ |
63
|
|
|
|
|
|
|
'class' => ($ENV{'HARNESS_DRIVER'} || |
64
|
|
|
|
|
|
|
"Test::Run::CmdLine::Drivers::Default"), |
65
|
|
|
|
|
|
|
'plugins' => [split(/\s+/, $ENV{'HARNESS_PLUGINS'} || "")] |
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
); |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
else |
70
|
|
|
|
|
|
|
{ |
71
|
|
|
|
|
|
|
$self->_set_driver( |
72
|
|
|
|
|
|
|
{ |
73
|
|
|
|
|
|
|
'class' => "Test::Run::CmdLine::Drivers::Default", |
74
|
|
|
|
|
|
|
'plugins' => [], |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
); |
77
|
|
|
|
|
|
|
} |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
return; |
80
|
|
|
|
|
|
|
} |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
=head1 Interface Functions |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
=head2 $tester = Test::Run::CmdLine::Iface->new({'test_files' => \@test_files, ....}); |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
Initializes a new testing front end. C<test_files> is a named argument that |
87
|
|
|
|
|
|
|
contains the files to test. |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
Other named arguments are: |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
=over 4 |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
=item backend_params |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
This is a hash of named parameters to be passed to the backend class (derived |
96
|
|
|
|
|
|
|
from L<Test::Run::Obj>.) |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
=item driver_class |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
This is the backend class that will be instantiated and used to perform |
101
|
|
|
|
|
|
|
the processing. Defaults to L<Test::Run::CmdLine::Drivers::Default>. |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
=item driver_plugins |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
This is a list of plugin classes to be used by the driver class. Each plugin |
106
|
|
|
|
|
|
|
is a module and a corresponding class, that is prefixed by |
107
|
|
|
|
|
|
|
C<Test::Run::CmdLine::Plugin::> - a prefix which should not be included in |
108
|
|
|
|
|
|
|
them. |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
=back |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
=head2 $tester->run() |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
Actually runs the tests on the command line. |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
=head2 BUILD |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
For Moose. |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
TODO : Write more. |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
=cut |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
sub _real_prepare_driver_class |
125
|
|
|
|
|
|
|
{ |
126
|
|
|
|
|
|
|
my $self = shift; |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
my $driver_class = $self->driver_class(); |
129
|
|
|
|
|
|
|
$driver_class->require(); |
130
|
|
|
|
|
|
|
if ($@) |
131
|
|
|
|
|
|
|
{ |
132
|
|
|
|
|
|
|
die $@; |
133
|
|
|
|
|
|
|
} |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
foreach my $plugin (@{$self->_calc_plugins_for_ISA()}) |
136
|
|
|
|
|
|
|
{ |
137
|
|
|
|
|
|
|
$plugin->require(); |
138
|
|
|
|
|
|
|
if ($@) |
139
|
|
|
|
|
|
|
{ |
140
|
|
|
|
|
|
|
die $@; |
141
|
|
|
|
|
|
|
} |
142
|
|
|
|
|
|
|
{ |
143
|
|
|
|
|
|
|
no strict 'refs'; |
144
|
|
|
|
|
|
|
push @{"${driver_class}::ISA"}, $plugin; |
145
|
|
|
|
|
|
|
} |
146
|
|
|
|
|
|
|
} |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
# Finally - put Test::Run::CmdLine there. |
149
|
|
|
|
|
|
|
{ |
150
|
|
|
|
|
|
|
no strict 'refs'; |
151
|
|
|
|
|
|
|
push @{"${driver_class}::ISA"}, "Test::Run::CmdLine"; |
152
|
|
|
|
|
|
|
} |
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
} |
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
# Does _real_prepare_driver_class with memoization. |
158
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
sub _prepare_driver_class |
160
|
|
|
|
|
|
|
{ |
161
|
|
|
|
|
|
|
my $self = shift; |
162
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
if (! $self->_is_driver_class_prepared()) |
164
|
|
|
|
|
|
|
{ |
165
|
|
|
|
|
|
|
$self->_real_prepare_driver_class(); |
166
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
$self->_is_driver_class_prepared(1); |
168
|
|
|
|
|
|
|
} |
169
|
|
|
|
|
|
|
return; |
170
|
|
|
|
|
|
|
} |
171
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
sub _calc_driver |
173
|
|
|
|
|
|
|
{ |
174
|
|
|
|
|
|
|
my $self = shift; |
175
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
$self->_prepare_driver_class(); |
177
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
my $driver = $self->driver_class()->new( |
179
|
|
|
|
|
|
|
{ |
180
|
|
|
|
|
|
|
'test_files' => $self->test_files(), |
181
|
|
|
|
|
|
|
($self->has_backend_params() |
182
|
|
|
|
|
|
|
? ('backend_params' => $self->backend_params()) |
183
|
|
|
|
|
|
|
: () |
184
|
|
|
|
|
|
|
), |
185
|
|
|
|
|
|
|
} |
186
|
|
|
|
|
|
|
); |
187
|
|
|
|
|
|
|
|
188
|
|
|
|
|
|
|
} |
189
|
|
|
|
|
|
|
sub run |
190
|
|
|
|
|
|
|
{ |
191
|
|
|
|
|
|
|
my $self = shift; |
192
|
|
|
|
|
|
|
|
193
|
|
|
|
|
|
|
return $self->_calc_driver()->run(); |
194
|
|
|
|
|
|
|
} |
195
|
|
|
|
|
|
|
|
196
|
|
|
|
|
|
|
sub _check_driver_class |
197
|
|
|
|
|
|
|
{ |
198
|
|
|
|
|
|
|
my $self = shift; |
199
|
|
|
|
|
|
|
return $self->_is_class_name(@_); |
200
|
|
|
|
|
|
|
} |
201
|
|
|
|
|
|
|
|
202
|
|
|
|
|
|
|
sub _check_plugins |
203
|
|
|
|
|
|
|
{ |
204
|
|
|
|
|
|
|
my $self = shift; |
205
|
|
|
|
|
|
|
my $plugins = shift; |
206
|
|
|
|
|
|
|
foreach my $p (@$plugins) |
207
|
|
|
|
|
|
|
{ |
208
|
|
|
|
|
|
|
if (! $self->_is_class_name($p)) |
209
|
|
|
|
|
|
|
{ |
210
|
|
|
|
|
|
|
return 0; |
211
|
|
|
|
|
|
|
} |
212
|
|
|
|
|
|
|
} |
213
|
|
|
|
|
|
|
return 1; |
214
|
|
|
|
|
|
|
} |
215
|
|
|
|
|
|
|
|
216
|
|
|
|
|
|
|
sub _is_class_name |
217
|
|
|
|
|
|
|
{ |
218
|
|
|
|
|
|
|
my $self = shift; |
219
|
|
|
|
|
|
|
my $class = shift; |
220
|
|
|
|
|
|
|
return ($class =~ /^\w+(?:::\w+)*$/); |
221
|
|
|
|
|
|
|
} |
222
|
|
|
|
|
|
|
|
223
|
|
|
|
|
|
|
sub _set_driver |
224
|
|
|
|
|
|
|
{ |
225
|
|
|
|
|
|
|
my ($self, $args) = @_; |
226
|
|
|
|
|
|
|
|
227
|
|
|
|
|
|
|
my $class = $args->{'class'}; |
228
|
|
|
|
|
|
|
if (! $self->_check_driver_class($class)) |
229
|
|
|
|
|
|
|
{ |
230
|
|
|
|
|
|
|
die "Invalid Driver Class \"$class\"!"; |
231
|
|
|
|
|
|
|
} |
232
|
|
|
|
|
|
|
$self->driver_class($class); |
233
|
|
|
|
|
|
|
|
234
|
|
|
|
|
|
|
my $plugins = $args->{'plugins'}; |
235
|
|
|
|
|
|
|
if (! $self->_check_plugins($plugins)) |
236
|
|
|
|
|
|
|
{ |
237
|
|
|
|
|
|
|
die "Invalid Plugins for Test::Run::CmdLine::Iface!"; |
238
|
|
|
|
|
|
|
} |
239
|
|
|
|
|
|
|
$self->driver_plugins($plugins); |
240
|
|
|
|
|
|
|
|
241
|
|
|
|
|
|
|
return 0; |
242
|
|
|
|
|
|
|
} |
243
|
|
|
|
|
|
|
|
244
|
|
|
|
|
|
|
sub _calc_plugins_for_ISA |
245
|
|
|
|
|
|
|
{ |
246
|
|
|
|
|
|
|
my $self = shift; |
247
|
|
|
|
|
|
|
return |
248
|
|
|
|
|
|
|
[ |
249
|
|
|
|
|
|
|
map { $self->_calc_single_plugin_for_ISA($_) } |
250
|
|
|
|
|
|
|
@{$self->driver_plugins()} |
251
|
|
|
|
|
|
|
]; |
252
|
|
|
|
|
|
|
} |
253
|
|
|
|
|
|
|
|
254
|
|
|
|
|
|
|
sub _calc_single_plugin_for_ISA |
255
|
|
|
|
|
|
|
{ |
256
|
|
|
|
|
|
|
my $self = shift; |
257
|
|
|
|
|
|
|
my $p = shift; |
258
|
|
|
|
|
|
|
|
259
|
|
|
|
|
|
|
return "Test::Run::CmdLine::Plugin::$p"; |
260
|
|
|
|
|
|
|
} |
261
|
|
|
|
|
|
|
|
262
|
|
|
|
|
|
|
=head1 AUTHOR |
263
|
|
|
|
|
|
|
|
264
|
|
|
|
|
|
|
Shlomi Fish, C<< <shlomif@iglu.org.il> >> |
265
|
|
|
|
|
|
|
|
266
|
|
|
|
|
|
|
=head1 BUGS |
267
|
|
|
|
|
|
|
|
268
|
|
|
|
|
|
|
Please report any bugs or feature requests to |
269
|
|
|
|
|
|
|
C<bug-test-run-cmdline@rt.cpan.org>, or through the web interface at |
270
|
|
|
|
|
|
|
L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Test-Run-CmdLine>. |
271
|
|
|
|
|
|
|
I will be notified, and then you'll automatically be notified of progress on |
272
|
|
|
|
|
|
|
your bug as I make changes. |
273
|
|
|
|
|
|
|
|
274
|
|
|
|
|
|
|
=head1 ACKNOWLEDGEMENTS |
275
|
|
|
|
|
|
|
|
276
|
|
|
|
|
|
|
=head1 COPYRIGHT & LICENSE |
277
|
|
|
|
|
|
|
|
278
|
|
|
|
|
|
|
Copyright 2005 Shlomi Fish, all rights reserved. |
279
|
|
|
|
|
|
|
|
280
|
|
|
|
|
|
|
This program is released under the MIT X11 License. |
281
|
|
|
|
|
|
|
|
282
|
|
|
|
|
|
|
=cut |
283
|
|
|
|
|
|
|
|
284
|
|
|
|
|
|
|
1; # End of Test::Run::CmdLine |