KiokuDB/Test.pm

filter: Statementstmt 100% 33 / 33 Branchbran 50.0% 3 / 6 Conditioncond 30.0% 3 / 10 MC/DCmcdc 0.0% 0 / 6 Subroutinesub 100% 9 / 9 Podpod 100% 1 / 1 totaltotal 75.3% 49 / 65 CC 9 SCAR 21.2
CC
9
Cov
80%
run_all_fixtures
14.9
__ANON__
1.0
BEGIN
1.0
CRAP 8.3
« KiokuDB/Linker.pm ↑ Summary KiokuDB/TypeMap/Entry/StorableHook.pm »
1 #!/usr/bin/perl
2  
3 package KiokuDB::Test;
4  
5 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 2 ▶use Scalar::Util qw(blessed);
Subroutine BEGIN: called CC=1 SCAR=0.0
9 2 ▶use Test::More;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 2 ▶use Module::Pluggable::Object;
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 2 ▶use namespace::clean;
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 2 use Sub::Exporter -setup => {
16 exports => [qw(run_all_fixtures)],
17 groups => { default => [-all] },
18 2 ▶};
Subroutine BEGIN: called CC=1 SCAR=0.0
19  
20 2 my $mp = Module::Pluggable::Object->new(
21 search_path => "KiokuDB::Test::Fixture",
22 require => 1,
23 );
24  
25 2 my @fixtures = sort { $a->sort <=> $b->sort } $mp->plugins;
26  
27 sub run_all_fixtures {
28 33 ▶ my ( $with ) = @_;
Subroutine run_all_fixtures: called CC=9 SCAR=27.0
Pod documented
29  
30 33 ▶ my $get_dir = blessed($with) ? sub { $with } : $with;
Subroutine __ANON__: called CC=1 SCAR=0.2
Branch: 1 branch
BranchTrueFalseTotal
builtin::blessed($with) ? : 33 0 33
31  
32 33 ▶ for ( 1 .. ( $ENV{KIOKUDB_REPEAT_FIXTURES} || 1 ) ) {
Condition50%1/2
$ENV{'KIOKUDB_REPEAT_FIXTURES'} || 1
l!l
033
MC/DC0%0/1
$ENV{'KIOKUDB_REPEAT_FIXTURES'} || 1
$ENV{'KIOKUDB_REPEAT_FIXTURES'}
Truth table50%1/2
A
A= $ENV{'KIOKUDB_REPEAT_FIXTURES'}
Aresult
11
00
33 33 ▶ require List::Util and @fixtures = List::Util::shuffle(@fixtures) if $ENV{KIOKUDB_SHUFFLE_FIXTURES};
Branch: 1 branch
BranchTrueFalseTotal
if $ENV{"KIOKUDB_SHUFFLE_FIXTURES"} 0 33 33
Condition20%1/5
$ENV{'KIOKUDB_SHUFFLE_FIXTURES'} && (require List::Util && (@fixtures = &List::Util::shuffle(@fixtures)))
!ll
330
require List::Util and @fixtures = &List::Util::shuffle(@fixtures)
!ll&&!rl&&r
000
MC/DC0%0/3
$ENV{'KIOKUDB_SHUFFLE_FIXTURES'} && (require List::Util && (@fixtures = &List::Util::shuffle(@fixtures)))
$ENV{'KIOKUDB_SHUFFLE_FIXTURES'} require List::Util @fixtures = &List::Util::shuffle(@fixtures)
Truth table0%0/4
A && B and C
A= $ENV{'KIOKUDB_SHUFFLE_FIXTURES'}B= require List::UtilC= @fixtures = &List::Util::shuffle(@fixtures)
ABCresult
0XX0
10X0
1100
1111
34 33 foreach my $fixture ( @fixtures ) {
35 594 ▶ next if $ENV{KIOKUDB_FIXTURE} and $fixture->name ne $ENV{KIOKUDB_FIXTURE};
Branch: 1 branch
BranchTrueFalseTotal
if $ENV{"KIOKUDB_FIXTURE"} and $fixture->name ne $ENV{"KIOKUDB_FIXTURE"} 0 594 594
Condition33%1/3
$ENV{"KIOKUDB_FIXTURE"} and $fixture->name ne $ENV{"KIOKUDB_FIXTURE"}
!ll&&!rl&&r
59400
MC/DC0%0/2
$ENV{"KIOKUDB_FIXTURE"} and $fixture->name ne $ENV{"KIOKUDB_FIXTURE"}
$ENV{"KIOKUDB_FIXTURE"} $fixture->name ne $ENV{"KIOKUDB_FIXTURE"}
Truth table33%1/3
A and B
A= $ENV{"KIOKUDB_FIXTURE"}B= $fixture->name ne $ENV{"KIOKUDB_FIXTURE"}
ABresult
0X0
100
111
36 594 $fixture->new( get_directory => $get_dir )->run;
37 }
38 }
39 }
40  
41 2 __PACKAGE__
42  
43 __END__
44  
45 =head1 NAME
46  
47 KiokuDB::Test - Reusable tests for L<KiokuDB> backend authors.
48  
49 =head1 SYNOPSIS
50  
51 use Test::More;
52  
53 use KiokuDB::Test;
54  
55 use ok "KiokuDB::Backend::MySpecialBackend";
56  
57 my $b = KiokuDB::Backend::MySpecialBackend->new( ... );
58  
59 run_all_fixtures( KiokuDB->new( backend => $b ) );
60  
61 done_testing();
62  
63 =head1 DESCRIPTION
64  
65 This module loads and runs L<KiokuDB::Test::Fixture>s against a L<KiokuDB>
66 directory instance.
67  
68 =head1 EXPORTS
69  
70 =over 4
71  
72 =item run_all_fixtures $dir
73  
74 =item run_all_fixtures sub { return $dir }
75  
76 Runs all the L<KiokuDB::Test::Fixture> objects against your dir.
77  
78 If you need a new instance of L<KiokuDB> for every fixture, pass in a code
79 reference.
80  
81 This will load all the modules in the L<KiokuDB::Test::Fixture> namespace, and
82 run them against your directory.
83  
84 Fixtures generally check for backend roles and skip unless the backend supports
85 that set of features.
86  
87 =back
« KiokuDB/Linker.pm ↑ Summary KiokuDB/TypeMap/Entry/StorableHook.pm »