KiokuDB::Test - Reusable tests for L<KiokuDB> backend authors.


KiokuDB documentation Contained in the KiokuDB distribution.

Index


Code Index:

NAME

Top

KiokuDB::Test - Reusable tests for KiokuDB backend authors.

SYNOPSIS

Top

    use Test::More;

    use KiokuDB::Test;

    use ok "KiokuDB::Backend::MySpecialBackend";

    my $b = KiokuDB::Backend::MySpecialBackend->new( ... );

    run_all_fixtures( KiokuDB->new( backend => $b ) );

    done_testing();

DESCRIPTION

Top

This module loads and runs KiokuDB::Test::Fixtures against a KiokuDB directory instance.

EXPORTS

Top

run_all_fixtures $dir
run_all_fixtures sub { return $dir }

Runs all the KiokuDB::Test::Fixture objects against your dir.

If you need a new instance of KiokuDB for every fixture, pass in a code reference.

This will load all the modules in the KiokuDB::Test::Fixture namespace, and run them against your directory.

Fixtures generally check for backend roles and skip unless the backend supports that set of features.


KiokuDB documentation Contained in the KiokuDB distribution.

#!/usr/bin/perl

package KiokuDB::Test;

use strict;
use warnings;

use Scalar::Util qw(blessed);
use Test::More;

use Module::Pluggable::Object;

use namespace::clean;

use Sub::Exporter -setup => {
    exports => [qw(run_all_fixtures)],
    groups  => { default => [-all] },
};

my $mp = Module::Pluggable::Object->new(
    search_path => "KiokuDB::Test::Fixture",
    require     => 1,
);

my @fixtures = sort { $a->sort <=> $b->sort } $mp->plugins;

sub run_all_fixtures {
    my ( $with ) = @_;

    my $get_dir = blessed($with) ? sub { $with } : $with;

    for ( 1 .. ( $ENV{KIOKUDB_REPEAT_FIXTURES} || 1 ) ) {
        require List::Util and @fixtures = List::Util::shuffle(@fixtures) if $ENV{KIOKUDB_SHUFFLE_FIXTURES};
        foreach my $fixture ( @fixtures ) {
            next if $ENV{KIOKUDB_FIXTURE} and $fixture->name ne $ENV{KIOKUDB_FIXTURE};
            $fixture->new( get_directory => $get_dir )->run;
        }
    }
}

__PACKAGE__

__END__