File Coverage

blib/lib/KiokuDB/Test.pm
Criterion Covered Total %
statement 14 16 87.5
branch n/a
condition n/a
subroutine 6 6 100.0
pod n/a
total 20 22 90.9


line stmt bran cond sub pod time code
1             package KiokuDB::Test;
2             BEGIN {
3 1     1   50997 $KiokuDB::Test::AUTHORITY = 'cpan:NUFFIN';
4             }
5             $KiokuDB::Test::VERSION = '0.57';
6 1     1   10 use strict;
  1         1  
  1         31  
7 1     1   4 use warnings;
  1         2  
  1         26  
8             # ABSTRACT: Reusable tests for KiokuDB backend authors.
9              
10 1     1   5 use Scalar::Util qw(blessed);
  1         1  
  1         123  
11 1     1   4 use Test::More;
  1         2  
  1         5  
12              
13 1     1   1977 use Module::Pluggable::Object;
  0            
  0            
14              
15             use namespace::clean;
16              
17             use Sub::Exporter -setup => {
18             exports => [qw(run_all_fixtures)],
19             groups => { default => [-all] },
20             };
21              
22             my $mp = Module::Pluggable::Object->new(
23             search_path => "KiokuDB::Test::Fixture",
24             require => 1,
25             );
26              
27             my @fixtures = sort { $a->sort <=> $b->sort } $mp->plugins;
28              
29             sub run_all_fixtures {
30             my ( $with ) = @_;
31              
32             my $get_dir = blessed($with) ? sub { $with } : $with;
33              
34             for ( 1 .. ( $ENV{KIOKUDB_REPEAT_FIXTURES} || 1 ) ) {
35             require List::Util and @fixtures = List::Util::shuffle(@fixtures) if $ENV{KIOKUDB_SHUFFLE_FIXTURES};
36             foreach my $fixture ( @fixtures ) {
37             next if $ENV{KIOKUDB_FIXTURE} and $fixture->name ne $ENV{KIOKUDB_FIXTURE};
38             $fixture->new( get_directory => $get_dir )->run;
39             }
40             }
41             }
42              
43             __PACKAGE__
44              
45             __END__
46              
47             =pod
48              
49             =encoding UTF-8
50              
51             =head1 NAME
52              
53             KiokuDB::Test - Reusable tests for KiokuDB backend authors.
54              
55             =head1 VERSION
56              
57             version 0.57
58              
59             =head1 SYNOPSIS
60              
61             use Test::More;
62              
63             use KiokuDB::Test;
64              
65             use KiokuDB::Backend::MySpecialBackend;
66              
67             my $b = KiokuDB::Backend::MySpecialBackend->new( ... );
68              
69             run_all_fixtures( KiokuDB->new( backend => $b ) );
70              
71             done_testing();
72              
73             =head1 DESCRIPTION
74              
75             This module loads and runs L<KiokuDB::Test::Fixture>s against a L<KiokuDB>
76             directory instance.
77              
78             =head1 EXPORTS
79              
80             =over 4
81              
82             =item run_all_fixtures $dir
83              
84             =item run_all_fixtures sub { return $dir }
85              
86             Runs all the L<KiokuDB::Test::Fixture> objects against your dir.
87              
88             If you need a new instance of L<KiokuDB> for every fixture, pass in a code
89             reference.
90              
91             This will load all the modules in the L<KiokuDB::Test::Fixture> namespace, and
92             run them against your directory.
93              
94             Fixtures generally check for backend roles and skip unless the backend supports
95             that set of features.
96              
97             =back
98              
99             =head1 AUTHOR
100              
101             Yuval Kogman <nothingmuch@woobling.org>
102              
103             =head1 COPYRIGHT AND LICENSE
104              
105             This software is copyright (c) 2014 by Yuval Kogman, Infinity Interactive.
106              
107             This is free software; you can redistribute it and/or modify it under
108             the same terms as the Perl 5 programming language system itself.
109              
110             =cut