blib/lib/Fennec/Lite.pm

filter: Statementstmt 97.4% 193 / 198 Branchbran 73.2% 41 / 56 Conditioncond 42.3% 11 / 26 MC/DCmcdc 6.2% 1 / 16 Subroutinesub 100% 43 / 43 Podpod 80.0% 12 / 15 totaltotal 85.0% 301 / 354 CC 43 SCAR 16.6
CC
43
Cov
88%
run_tests
14.3
_import_loads
7.8
_add_tests
7.3
CRAP 5.3
↑ Summary
1 package Fennec::Lite;
2 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 3 ▶use Carp qw/ croak /;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 3 ▶use List::Util qw/ shuffle /;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 3 ▶use B;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 3 our $VERSION = '0.004';
10  
11 our %MODULE_LOADERS = (
12 2 ▶ 'Test::More' => sub {
Subroutine __ANON__: called CC=5 SCAR=19.4
13 2 my ( $self ) = @_;
14 2 my $into = $self->test_class;
15 2 require Test::More;
16  
17 2 ▶ my $plan = $self->plan || (Test::More->can('done_testing') ? '' : 'no_plan');
Branch: 1 branch
BranchTrueFalseTotal
'Test::More'->can('done_testing') ? : 0 0 0
Condition33%1/3
$self->plan || ('Test::More'->can('done_testing') ? '' : 'no_plan')
l!l&&r!l&&!r
200
MC/DC0%0/2
$self->plan || ('Test::More'->can('done_testing') ? '' : 'no_plan')
$self->plan ('Test::More'->can('done_testing') ? '' : 'no_plan')
Truth table33%1/3
A || B
A= $self->planB= ('Test::More'->can('done_testing') ? '' : 'no_plan')
ABresult
1X1
011
000
18 2 ▶ eval "package $into; Test::More->import(" . ($plan ? 'tests => $plan' : '') . "); 1"
Branch: 2 branches
BranchTrueFalseTotal
eval "package $into; Test::More->import(" . ($plan ? "tests => \$plan" : "") . '); 1' or die $@ 2 0 2
$plan ? : 2 0 2
19 || die $@;
20 },
21 3 );
22  
23 2 ▶sub import_hook {}
Subroutine import_hook: called CC=1 SCAR=0.0
Pod documented
24 4 ▶sub module_loaders { \%MODULE_LOADERS }
Subroutine module_loaders: called CC=1 SCAR=0.0
Pod documented
25 2 ▶sub must_load {qw/ Test::More /}
Subroutine must_load: called CC=1 SCAR=0.0
Pod documented
26 2 ▶sub may_load {qw/
Subroutine may_load: called CC=1 SCAR=0.0
Pod documented
27 Test::Warn
28 Test::Exception
29 /};
30  
31 3 fennec_accessors(qw/
32 tests
33 test_class
34 seed
35 random
36 testing
37 alias
38 alias_to
39 plan
40 TB
41 /);
42  
43 2 ▶sub import {
Subroutine import: called CC=2 SCAR=6.9
44 2 my $class = shift;
45 2 my %specs = @_;
46 2 my $caller = caller;
47  
48 2 ▶ $specs{random} = 1 unless defined $specs{random};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $specs{"random"} 2 0 2
49  
50 2 my $instance = $class->new( %specs, test_class => $caller );
51  
52 2 $instance->_import_must_loads();
53 2 $instance->_import_way_loads();
54 2 $instance->_export_shortcuts();
55 2 $instance->_export_aliases();
56 2 $instance->_export_functions();
57 2 $instance->import_hook();
58  
59 2 1;
60 }
61  
62 4 ▶sub new {
Subroutine new: called CC=2 SCAR=7.2
Pod undocumented
63 4 my $class = shift;
64 4 my @ltime = localtime(time);
65 my $self = bless ({
66 tests => [],
67 4 ▶ seed => $ENV{FENNEC_SEED} || join( '', @ltime[5,4,3] ),
Condition33%1/3
$ENV{'FENNEC_SEED'} || join('', @ltime[5, 4, 3])
l!l&&r!l&&!r
040
MC/DC0%0/2
$ENV{'FENNEC_SEED'} || join('', @ltime[5, 4, 3])
$ENV{'FENNEC_SEED'} join('', @ltime[5, 4, 3])
Truth table33%1/3
A || B
A= $ENV{'FENNEC_SEED'}B= join('', @ltime[5, 4, 3])
ABresult
1X1
011
000
68 @_,
69 }, $class );
70 4 $self->init();
71 4 return $self;
72 }
73  
74 4 ▶sub init {
Subroutine init: called CC=1 SCAR=0.0
Pod documented
75 4 my $self = shift;
76 4 require Test::Builder;
77 4 $self->TB( Test::Builder->new());
78 }
79  
80 4 ▶sub _import_loads {
Subroutine _import_loads: called CC=6 SCAR=20.5
81 4 my $self = shift;
82 4 my ( $no_die_on_fail, @load ) = @_;
83 4 my $handlers = $self->module_loaders;
84  
85 4 for my $package ( @load ) {
86 6 ▶ if ($handlers->{$package}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($handlers->{$package}) 2 4 6
87 2 $handlers->{$package}->( $self );
88 2 next;
89 }
90 4 my ($ret, $error) = load_package_into( $package, $self->test_class );
91 4 ▶ next if $ret;
Branch: 1 branch
BranchTrueFalseTotal
if $ret 4 0 4
92 0 ▶ die $error unless $no_die_on_fail && $error =~ m/Can't locate [\w\d_\/\.]+\.pm in \@INC/;
Branch: 1 branch
BranchTrueFalseTotal
unless $no_die_on_fail and $error =~ m[Can't locate [\w\d_/\.]+\.pm in \@INC] 0 0 0
Condition0%0/3
$no_die_on_fail and $error =~ m[Can't locate [\w\d_/\.]+\.pm in \@INC]
!ll&&!rl&&r
000
MC/DC0%0/2
$no_die_on_fail and $error =~ m[Can't locate [\w\d_/\.]+\.pm in \@INC]
$no_die_on_fail $error =~ m[Can't locate [\w\d_/\.]+\.pm in \@INC]
Truth table0%0/3
A and B
A= $no_die_on_failB= $error =~ m[Can't locate [\w\d_/\.]+\.pm in \@INC]
ABresult
0X0
100
111
93 }
94 }
95  
96 4 ▶sub load_package_into {
Subroutine load_package_into: called CC=2 SCAR=6.9
Pod undocumented
97 4 my ( $load, $into ) = @_;
98 4 local $@;
99 2 ▶ my $ret = eval "package $into; use $load; 1;";
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
100 4 ▶ return $ret ? ( $ret ) : ( $ret, $@ );
Branch: 1 branch
BranchTrueFalseTotal
$ret ? : 4 0 4
101 }
102  
103 2 ▶sub _import_must_loads {
Subroutine _import_must_loads: called CC=1 SCAR=0.0
104 2 my $self = shift;
105 2 $self->_import_loads( 0, $self->must_load );
106 }
107  
108 2 ▶sub _import_way_loads {
Subroutine _import_way_loads: called CC=1 SCAR=0.0
109 2 my $self = shift;
110 2 $self->_import_loads( 1, $self->may_load );
111 }
112  
113 2 ▶sub _export_shortcuts {
Subroutine _export_shortcuts: called CC=2 SCAR=6.9
114 2 my $self = shift;
115 2 ▶ my $package = $self->testing || return;
Condition100%2/2
$self->testing || (return)
l!l
11
MC/DC100%1/1
$self->testing || (return)
$self->testing
Truth table100%2/2
A
A= $self->testing
Aresult
11
00
116 1 my $into = $self->test_class;
117  
118 3 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
119 1 ▶ *{"$into\::CLASS"} = sub { $package };
Subroutine __ANON__: called CC=1 SCAR=0.0
120 1 *{"$into\::CLASS"} = \$package;
121 }
122  
123 2 ▶sub _export_aliases {
Subroutine _export_aliases: called CC=7 SCAR=19.5
124 2 my $self = shift;
125 2 my $caller = $self->test_class;
126  
127 2 ▶ if ( my $aliases = $self->alias ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $aliases = $self->alias) 1 1 2
128 1 ▶ $aliases = [ $aliases ] unless ref $aliases;
Branch: 1 branch
BranchTrueFalseTotal
unless ref $aliases 0 1 1
129 1 for my $class ( @$aliases ) {
130 1 ▶ eval "require $class; 1" || die $@;
Branch: 1 branch
BranchTrueFalseTotal
eval "require $class; 1" or die $@ 1 0 1
131 3 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
132 1 my $name = $class;
133 1 $name =~ s/^.*:([^:]+)$/$1/;
134 1 ▶ *{"$caller\::$name"} = sub { $class };
Subroutine __ANON__: called CC=1 SCAR=0.0
135 }
136 }
137  
138 2 ▶ if ( my $alias_map = $self->alias_to ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $alias_map = $self->alias_to) 1 1 2
139 1 for my $name ( keys %$alias_map ) {
140 1 my $class = $alias_map->{ $name };
141 3 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
142 1 ▶ *{"$caller\::$name"} = sub { $class };
Subroutine __ANON__: called CC=1 SCAR=0.0
143 }
144 }
145 }
146  
147 2 ▶sub _export_functions {
Subroutine _export_functions: called CC=1 SCAR=0.0
148 2 my $self = shift;
149 2 my $into = $self->test_class;
150  
151 3 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
152 2 ▶ *{"$into\::tests"} = sub { $self->_add_tests( @_ ) };
Subroutine __ANON__: called CC=1 SCAR=0.0
153 2 ▶ *{"$into\::run_tests"} = sub { $self->run_tests( @_ ) };
Subroutine __ANON__: called CC=1 SCAR=0.0
154 2 ▶ *{"$into\::fennec"} = sub { return $self };
Subroutine __ANON__: called CC=1 SCAR=0.0
155  
156 2 *{"$into\::fennec_accessors"} = \&fennec_accessors;
157 }
158  
159 13 ▶sub add_tests {
Subroutine add_tests: called CC=1 SCAR=0.0
Pod documented
160 13 my $self = shift;
161 13 $self->_add_tests( @_ );
162 }
163  
164 27 ▶sub _add_tests {
Subroutine _add_tests: called CC=7 SCAR=19.9
165 27 my $self = shift;
166 27 ( undef, undef, my $end_line ) = caller(1);
167 27 my $name = shift;
168 27 ▶ my %proto = ( @_ == 1 )
Branch: 1 branch
BranchTrueFalseTotal
@_ == 1 ? : 21 6 27
169 ? ( method => $_[0] )
170 : @_;
171  
172 27 ▶ $proto{ name } = $name if $name;
Branch: 1 branch
BranchTrueFalseTotal
if $name 27 0 27
173 27 ▶ $proto{ method } ||= $proto{ code } || $proto{ sub };
Condition66%4/6
$proto{"method"} ||= $proto{"code"} || $proto{"sub"}
l!l&&r!l&&!r
2340
$proto{'code'} || $proto{'sub'}
l!l&&r!l&&!r
220
MC/DC0%0/3
$proto{"method"} ||= $proto{"code"} || $proto{"sub"}
$proto{"method"} $proto{'code'} $proto{'sub'}
Truth table0%0/4
A ||= B || C
A= $proto{"method"}B= $proto{'code'}C= $proto{'sub'}
ABCresult
1XX1
01X1
0011
0000
174 27 $proto{ end_line } = $end_line;
175 27 $proto{ start_line } = B::svref_2object( $proto{ method })->START->line;
176  
177 croak "You must name your test group"
178 27 ▶ unless $proto{name};
Branch: 1 branch
BranchTrueFalseTotal
unless $proto{"name"} 0 27 27
179  
180 croak "You must provide a coderef as one of the following params 'method', 'code', or 'sub'."
181 27 ▶ unless $proto{method};
Branch: 1 branch
BranchTrueFalseTotal
unless $proto{"method"} 0 27 27
182  
183 27 push @{$self->tests} => \%proto;
184 }
185  
186 8 ▶sub run_tests {
Subroutine run_tests: called CC=14 SCAR=26.6
Pod documented
187 8 my $self = shift;
188 8 my %params = @_;
189 8 my $tests = $self->tests;
190 8 my $pass = 1;
191 8 my $item = $ENV{FENNEC_ITEM};
192  
193 8 my $invocant_class = $self->test_class;
194 8 ▶ my $invocant = $invocant_class->can( 'new' )
Branch: 1 branch
BranchTrueFalseTotal
$invocant_class->can('new') ? : 4 4 8
195 ? $invocant_class->new( %params )
196 : bless( \%params, $invocant_class );
197  
198 # Seed before randomizing tests, for reproducibility
199 8 srand( $self->seed );
200 8 ▶ $tests = [ shuffle @$tests ]
Branch: 1 branch
BranchTrueFalseTotal
if $self->random 4 4 8
201 if $self->random;
202  
203 8 for my $test ( @$tests ) {
204 27 my $method = $test->{method};
205 27 my $name = $test->{name};
206  
207 27 ▶ if ( $item ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($item) 12 15 27
208 12 ▶ if ( $item =~ m/^\d+$/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($item =~ /^\d+$/) { } 6 6 12
209 6 ▶ next unless $test->{start_line} <= ($item + 1);
Branch: 1 branch
BranchTrueFalseTotal
unless $test->{"start_line"} <= $item + 1 2 4 6
210 4 ▶ next unless $test->{end_line} >= $item;
Branch: 1 branch
BranchTrueFalseTotal
unless $test->{"end_line"} >= $item 2 2 4
211 }
212 else {
213 6 ▶ next unless $name eq $item;
Branch: 1 branch
BranchTrueFalseTotal
unless $name eq $item 4 2 6
214 }
215 }
216  
217 19 ▶ if ( $test->{ skip }) {
Branch: 2 branches
BranchTrueFalseTotal
if ($test->{'skip'}) { } 2 17 19
elsif ($test->{'todo'}) { } 2 15 17
218 2 ▶ $pass &&= $self->run_skip_group( $invocant, $test );
Condition33%1/3
$pass &&= $self->run_skip_group($invocant, $test)
!ll&&!rl&&r
002
MC/DC0%0/2
$pass &&= $self->run_skip_group($invocant, $test)
$pass $self->run_skip_group($invocant, $test)
Truth table33%1/3
A &&= B
A= $passB= $self->run_skip_group($invocant, $test)
ABresult
0X0
100
111
219 }
220 elsif( $test->{ todo }) {
221 2 ▶ $pass &&= $self->run_todo_group( $invocant, $test );
Condition33%1/3
$pass &&= $self->run_todo_group($invocant, $test)
!ll&&!rl&&r
002
MC/DC0%0/2
$pass &&= $self->run_todo_group($invocant, $test)
$pass $self->run_todo_group($invocant, $test)
Truth table33%1/3
A &&= B
A= $passB= $self->run_todo_group($invocant, $test)
ABresult
0X0
100
111
222 }
223 else {
224 15 ▶ $pass &&= $self->run_test_group( $invocant, $test );
Condition33%1/3
$pass &&= $self->run_test_group($invocant, $test)
!ll&&!rl&&r
0015
MC/DC0%0/2
$pass &&= $self->run_test_group($invocant, $test)
$pass $self->run_test_group($invocant, $test)
Truth table33%1/3
A &&= B
A= $passB= $self->run_test_group($invocant, $test)
ABresult
0X0
100
111
225 }
226 }
227  
228 8 $self->tests([]);
229 8 return $pass;
230 }
231  
232 2 ▶sub run_skip_group {
Subroutine run_skip_group: called CC=1 SCAR=0.0
Pod undocumented
233 2 my $self = shift;
234 2 my ( $invocant, $test ) = @_;
235 2 my $name = $test->{ name };
236 2 $self->TB->note( "Skipping: $name" );
237 2 $self->TB->skip( $test->{skip} );
238 2 1;
239 }
240  
241 2 ▶sub run_todo_group {
Subroutine run_todo_group: called CC=1 SCAR=0.0
Pod documented
242 2 my $self = shift;
243 2 my ( $invocant, $test ) = @_;
244 2 $self->TB->todo_start( $test->{todo} );
245 2 my $out = $self->run_test_eval( $invocant, $test );
246 2 $self->TB->todo_end();
247 2 return $out;
248 }
249  
250 15 ▶sub run_test_group {
Subroutine run_test_group: called CC=1 SCAR=0.0
Pod documented
251 15 my $self = shift;
252 15 my ( $invocant, $test ) = @_;
253 15 $self->run_test_eval( $invocant, $test );
254 }
255  
256 17 ▶sub run_test_eval {
Subroutine run_test_eval: called CC=2 SCAR=6.9
Pod documented
257 17 my $self = shift;
258 17 my ( $invocant, $test ) = @_;
259  
260 # Seed again before running test, for reproducibility
261 17 srand( $self->seed );
262 17 my $ret = eval { $test->{method}->( $invocant ); 1 };
263 17 ▶ return $ret ? $ret : $self->test_eval_error( $ret, $@, $test );
Branch: 1 branch
BranchTrueFalseTotal
$ret ? : 15 2 17
264 }
265  
266 2 ▶sub test_eval_error {
Subroutine test_eval_error: called CC=2 SCAR=9.9
Pod documented
267 2 my $self = shift;
268 2 my ( $ret, $error, $test ) = @_;
269  
270 2 ▶ return !$ret if $test->{ should_fail };
Branch: 1 branch
BranchTrueFalseTotal
if $test->{"should_fail"} 2 0 2
271  
272 0 my $name = $test->{name};
273 0 $self->TB->ok( $ret, "Test Group '$name' died (it should not)" );
274 0 $self->TB->diag( $error );
275  
276 0 return $ret;
277 }
278  
279 5 ▶sub fennec_accessors {
Subroutine fennec_accessors: called CC=2 SCAR=6.9
Pod documented
280 5 my $caller = caller;
281 5 for my $name ( @_ ) {
282 119 ▶ my $sub = sub {
Subroutine __ANON__: called CC=2 SCAR=6.9
283 119 my $self = shift;
284 119 ▶ ( $self->{ $name }) = @_ if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 12 107 119
285 119 return $self->{ $name };
286 31 };
287 3 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
288 31 *{"$caller\::$name"} = $sub;
289 }
290 }
291  
292 3 1;
293  
294 =head1 NAME
295  
296 Fennec::Lite - Minimalist Fennec, the commonly used bits.
297  
298 =head1 DESCRIPTION
299  
300 L<Fennec> does a ton, but it may be hard to adopt it all at once. It also is a
301 large project, and has not yet been fully split into component projects.
302 Fennec::Lite takes a minimalist approach to do for Fennec what Mouse does for
303 Moose.
304  
305 Fennec::Lite is a single module file with no non-core dependencies. It can
306 easily be used by any project, either directly, or by copying it into your
307 project. The file itself is less than 300 lines of code at the time of this
308 writing, that includes whitespace.
309  
310 This module does not cover any of the more advanced features such as result
311 capturing or SPEC workflows. This module only covers test grouping and group
312 randomization. You can also use the FENNEC_ITEM variable with a group name or
313 line number to run a specific test group only. Test::Builder is used under the
314 hood for TAP output.
315  
316 =head1 SYNOPSIS
317  
318 =head2 SIMPLE
319  
320 #!/usr/bin/perl
321 use strict;
322 use warnings;
323  
324 # Brings in Test::More for us.
325 use Fennec::Lite;
326  
327 tests good => sub {
328 ok( 1, "A good test" );
329 };
330  
331 # You most call run_tests() after declaring your tests.
332 run_tests();
333 done_testing();
334  
335 =head2 ADVANCED
336  
337 #!/usr/bin/perl
338 use strict;
339 use warnings;
340  
341 use Fennec::Lite
342 plan => 8,
343 random => 1,
344 testing => 'My::Class',
345 alias => [
346 'My::Class::ThingA'
347 ],
348 alias_to => {
349 TB => 'My::Class::ThingB',
350 };
351  
352 # Quickly create get/set accessors
353 fennec_accessors qw/ construction_string /;
354  
355 # Create a constructor for our test class.
356 sub new {
357 my $class = shift;
358 my $string = @_;
359 return bless({ construction_string => $string }, $class );
360 }
361  
362 tests good => sub {
363 # Get $self. Created with new()
364 my $self = shift;
365 $self->isa_ok( __PACKAGE__ );
366 is(
367 $self->construction_string,
368 "This is the construction string",
369 "Constructed properly"
370 );
371 ok( 1, "A good test" );
372 };
373  
374 tests "todo group" => (
375 todo => "This will fail",
376 code => sub { ok( 0, "false value" )},
377 );
378  
379 tests "skip group" => (
380 skip => "This will fail badly",
381 sub => sub { die "oops" },
382 );
383  
384 run_tests( "This is the construction string" );
385  
386 =head2 Pure OO Interface
387  
388 #!/usr/bin/perl
389 use strict;
390 use warnings;
391  
392 use Fennec::Lite ();
393 use Test::More;
394  
395 my $fennec = Fennec::Lite->new( test_class => __PACKAGE__ );
396  
397 $fennec->add_tests( "test name" => sub {
398 ok( ... );
399 });
400  
401 $fennec->run_tests;
402  
403 done_testing();
404  
405 =head1 IMPORTED FOR YOU
406  
407 When you use Fennec::Lite, L<Test::More> is automatically imported for you. In
408 addition L<Test::Warn> and L<Test::Exception> will also be loaded, but only if
409 they are installed.
410  
411 =head1 IMPORT ARGUMENTS
412  
413 use Fennec::Lite %ARGS
414  
415 =over 4
416  
417 =item plan => 'no_plan' || $count
418  
419 Plan to pass into Test::More.
420  
421 =item random => $bool
422  
423 True by default. When true test groups will be run in random order.
424  
425 =item testing => $CLASS_NAME
426  
427 Declare what class you ore testing. Provides $CLASS and CLASS(), both of which
428 are simply the name of the class being tested.
429  
430 =item alias => @PACKAGES
431  
432 Create alias functions your the given package. An alias is a function that
433 returns the package name. The aliases will be named after the last part of the
434 package name.
435  
436 =item alias_to => { $ALIAS => $PACKAGE, ... }
437  
438 Define aliases, keys are alias names, values are tho package names they should
439 return.
440  
441 =back
442  
443 =head1 RUNNING IN RANDOM ORDER
444  
445 By default test groups will be run in a random order. The random seed is the
446 current date (YYYYMMDD). This is used so that the order does not change on the
447 day you are editing your code. However the ardor will change daily allowing for
448 automated testing to find order dependent failures.
449  
450 You can manually set the random seed to reproduce a failure. The FENNEC_SEED
451 environment variable will be used as the seed when it is present.
452  
453 $ FENNEC_SEED="20100915" prove -I lib -v t/*.t
454  
455 =head1 RUNNING SPECIFIC GROUPS
456  
457 You can use the FENNEC_ITEM variable with a group name or line number to run a
458 specific test group only.
459  
460 $ FENNEC_ITEM="22" prove -I lib -v t/MyTest.t
461 $ FENNEC_ITEM="Test Group A" prove -I lib -v t/MyTest.t
462  
463 This can easily be integrated into an editor such as vim or emacs.
464  
465 =head1 EXPORTED FUNCTIONS
466  
467 =over 4
468  
469 =item tests $name => $coderef,
470  
471 =item tests $name => ( code => $coderef, todo => $reason )
472  
473 =item tests $name => ( code => $coderef, skip => $reason )
474  
475 =item tests $name => ( sub => $coderef )
476  
477 =item tests $name => ( method => $coderef )
478  
479 Declare a test group. The first argument must always be the test group name. In
480 the 2 part form the second argument must be a coderef. In the multi-part form
481 you may optionally declare the group as todo, or as a skip. A coderef must
482 always be provided, in multi-part form you may use the code, method, or sub
483 params for this purpose, they are all the same.
484  
485 =item run_tests( %params )
486  
487 Instantiate an instance of the test class, passing %params to the constructor.
488 If no constructor is present a default is used. All tests that have been added
489 will be run. All tests will be cleared, you may continue to declare tests and
490 call run_tests again to run the new tests.
491  
492 =item fennec()
493  
494 Returns the instance of Fennec::Lite created when you imported it. This is the
495 instance that tests() and run_tests() act upon.
496  
497 =item fennec_accessors( @NAMES )
498  
499 Quickly generate get/set accessors for your test class. You could alternatively
500 do it manually or use L<Moose>.
501  
502 =back
503  
504 =head1 PURE OO INTERFACE METHODS
505  
506 =over 4
507  
508 =item $tests_ref = $fennec->tests()
509  
510 Get a reference to the array of tests that have been added since the last run.
511  
512 =item $classname = $fennec->test_class( $classname )
513  
514 Get/Set the class name that will be used to create test objects that will act
515 as the invocant on all test methods.
516  
517 =item $seed = $fennec->seed( $newseed )
518  
519 Get/Set the random seed that will be used to re-seed srand() before randomizing
520 tests, as well as before each test.
521  
522 =item $bool = $fennec->random( $bool )
523  
524 Turn random on/off.
525  
526 =item $fennec->add_tests( $name => sub { ... })
527  
528 =item $fennec->add_tests( $name, %args, method => sub { ... })
529  
530 Add a test group.
531  
532 =item $fennec->run_tests( %test_class_construction_args )
533  
534 Run the test groups
535  
536 =item $bool = $fennec->run_skip_test( \%test )
537  
538 Run a skip test (really just returns true)
539  
540 =item $bool = $fennec->run_todo_group( \%test )
541  
542 Run a group as TODO
543  
544 =item $bool = $fennec->run_test_group( \%test )
545  
546 Run a test group.
547  
548 =item ( $bool, $error ) = $fennec->run_test_eval( \%test )
549  
550 Does the actual test running in an eval to capture errors.
551  
552 =item $fennec->test_eval_error( $bool, $error, \%test )
553  
554 Handle a test eval error.
555  
556 =back
557  
558 =head1 Extending Fennec::Lite
559  
560 In the tradition of the Fennec project, Fennec::Lite is designed to be
561 extensible. You can even easily subclass/edit Fennec::Lite to work with
562 alternatives to Test::Builder.
563  
564 =head2 METHODS TO OVERRIDE
565  
566 =over 4
567  
568 =item $fennec->init()
569  
570 Called by new prior to returning the newly constructed object. In Fennec::Lite
571 this loads L<Test::Builder> and puts a reference to it in the TB() accessor. If
572 you do want to replace L<Test::Builder> in your subclass you may do so by
573 overriding init().
574  
575 =item $fennec->run_skip_test( \%test )
576  
577 Calls Test::Builder->skip( $reason ), then returns true. Override this if you
578 replace Test::Builder in your subclass.
579  
580 =item $fennec->run_todo_group( \%test )
581  
582 Calls run_test_eval() in a TODO environment. Currently uses L<Test::Builder> to
583 start/stop TODO mode around the test. Override this if you wish to replace
584 Test::Builder.
585  
586 =item $fennec->test_eval_error( $bool, $error, \%test )
587  
588 Handle an exception thrown in a test group method. Currently calls
589 Test::Bulder->ok( 0, GROUP_NAME ).
590  
591 =item @list = must_load()
592  
593 Returns a list of modules that MUST be loaded into tho calling class (unless
594 used in OO form). This is currently only L<Test::More>.
595  
596 =item @list = may_load()
597  
598 Returns a list of modules that should be loaded only if they are installed.
599  
600 =item $name_to_code_ref = module_loaders()
601  
602 Returns a hashref containing package => sub { ... }. Use this if you need to
603 load modules in a custom way, currently Test::More has a special loader in here
604 to account for plans.
605  
606 =item $fennec->import_hook()
607  
608 Called on the instance that was created by import(), runs at the very end of
609 the import process. Currently does nothing.
610  
611 =back
612  
613 =head1 FENNEC PROJECT
614  
615 This module is part of the Fennec project. See L<Fennec> for more details.
616 Fennec is a project to develop an extensible and powerful testing framework.
617 Together the tools that make up the Fennec framework provide a potent testing
618 environment.
619  
620 The tools provided by Fennec are also useful on their own. Sometimes a tool
621 created for Fennec is useful outside the greater framework. Such tools are
622 turned into their own projects. This is one such project.
623  
624 =over 2
625  
626 =item L<Fennec> - The core framework
627  
628 The primary Fennec project that ties them all together.
629  
630 =back
631  
632 =head1 AUTHORS
633  
634 Chad Granum L<exodist7@gmail.com>
635  
636 =head1 COPYRIGHT
637  
638 Copyright (C) 2010 Chad Granum
639  
640 Fennec-Lite is free software; Standard perl license.
641  
642 Fennec-Lite is distributed in the hope that it will be useful, but WITHOUT ANY
643 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
644 FOR A PARTICULAR PURPOSE. See the license for more details.
↑ Summary