summaryrefslogtreecommitdiff
path: root/t
diff options
context:
space:
mode:
Diffstat (limited to 't')
-rw-r--r--t/00_load.t12
-rw-r--r--t/01_factory.t35
-rw-r--r--t/02_factory_validate.t51
-rw-r--r--t/03_check_implementation_class.t51
-rw-r--r--t/04_override_get_implementation.t32
-rw-r--r--t/05_override_validate_implementation.t47
-rw-r--r--t/97_pod.t4
-rw-r--r--t/98_pod_coverage.t12
-rw-r--r--t/99_perl_critic.t21
-rw-r--r--t/perlcriticrc5
10 files changed, 270 insertions, 0 deletions
diff --git a/t/00_load.t b/t/00_load.t
new file mode 100644
index 0000000..b5eeaa6
--- /dev/null
+++ b/t/00_load.t
@@ -0,0 +1,12 @@
+#!/usr/bin/perl
+
+use strict;
+use warnings;
+
+use Test::More tests => 3;
+
+package NotMain; # so Moose::Exporter doesn't complain
+
+::use_ok('MooseX::AbstractFactory');
+::use_ok('MooseX::AbstractFactory::Role');
+::use_ok('MooseX::AbstractFactory::Meta::Class'); \ No newline at end of file
diff --git a/t/01_factory.t b/t/01_factory.t
new file mode 100644
index 0000000..7c49cb4
--- /dev/null
+++ b/t/01_factory.t
@@ -0,0 +1,35 @@
+use Test::More tests => 6;
+use Test::Moose;
+use Test::Exception;
+
+BEGIN {
+ package My::Factory::Implementation;
+ use Moose;
+
+ has connection => (is => 'ro', isa => 'Str');
+
+ sub tweak { 1; };
+
+ package My::Factory;
+ use MooseX::AbstractFactory;
+ use Moose;
+}
+
+my $imp;
+
+lives_ok {
+ $imp = My::Factory->create(
+ 'Implementation',
+ { connection => 'Type1' }
+ );
+} "Factory->new() doesn't die";
+
+isa_ok($imp, "My::Factory::Implementation");
+
+can_ok($imp, qw/tweak/);
+is($imp->tweak(),1,"tweak returns 1");
+is($imp->connection(), 'Type1', 'connection attr set by constructor');
+
+dies_ok {
+ $imp->fudge();
+} "fudge dies, not implemented on implementor"; \ No newline at end of file
diff --git a/t/02_factory_validate.t b/t/02_factory_validate.t
new file mode 100644
index 0000000..ccd1389
--- /dev/null
+++ b/t/02_factory_validate.t
@@ -0,0 +1,51 @@
+use Test::More tests => 2;
+use Test::Exception;
+
+BEGIN {
+ #----------------------------------------------------
+ # ImplementationA has a tweak() method
+ package My::Factory::ImplementationA;
+ use Moose;
+
+ has connection => (is => 'ro', isa => 'Str');
+
+ sub tweak { 1; }
+
+ #----------------------------------------------------
+ # ImplementationB doesn't have a tweak() method
+
+ package My::Factory::ImplementationB;
+ use Moose;
+
+ sub no_tweak { 1; }
+
+ #----------------------------------------------------
+ # Factory class, has _roles() method that defines
+ # the role(s) (My::Role) all implementations should satisfy
+ package My::Factory;
+ use MooseX::AbstractFactory;
+
+ implementation_does qw/My::Role/;
+
+ #----------------------------------------------------
+ # My::Role requires tweak()
+ package My::Role;
+ use Moose::Role;
+ requires 'tweak';
+}
+
+my $imp;
+
+lives_ok {
+ $imp = My::Factory->create('ImplementationA',
+ {connection => 'Type1'});
+}
+"Factory->new() doesn't die with ImplementationA";
+
+dies_ok {
+ $imp = My::Factory->create(
+ 'ImplementationB',
+ {},
+ );
+}
+"Factory->new() dies with implementationB";
diff --git a/t/03_check_implementation_class.t b/t/03_check_implementation_class.t
new file mode 100644
index 0000000..ccd1389
--- /dev/null
+++ b/t/03_check_implementation_class.t
@@ -0,0 +1,51 @@
+use Test::More tests => 2;
+use Test::Exception;
+
+BEGIN {
+ #----------------------------------------------------
+ # ImplementationA has a tweak() method
+ package My::Factory::ImplementationA;
+ use Moose;
+
+ has connection => (is => 'ro', isa => 'Str');
+
+ sub tweak { 1; }
+
+ #----------------------------------------------------
+ # ImplementationB doesn't have a tweak() method
+
+ package My::Factory::ImplementationB;
+ use Moose;
+
+ sub no_tweak { 1; }
+
+ #----------------------------------------------------
+ # Factory class, has _roles() method that defines
+ # the role(s) (My::Role) all implementations should satisfy
+ package My::Factory;
+ use MooseX::AbstractFactory;
+
+ implementation_does qw/My::Role/;
+
+ #----------------------------------------------------
+ # My::Role requires tweak()
+ package My::Role;
+ use Moose::Role;
+ requires 'tweak';
+}
+
+my $imp;
+
+lives_ok {
+ $imp = My::Factory->create('ImplementationA',
+ {connection => 'Type1'});
+}
+"Factory->new() doesn't die with ImplementationA";
+
+dies_ok {
+ $imp = My::Factory->create(
+ 'ImplementationB',
+ {},
+ );
+}
+"Factory->new() dies with implementationB";
diff --git a/t/04_override_get_implementation.t b/t/04_override_get_implementation.t
new file mode 100644
index 0000000..d53cbf9
--- /dev/null
+++ b/t/04_override_get_implementation.t
@@ -0,0 +1,32 @@
+use Test::More tests => 2;
+use Test::Moose;
+use Test::Exception;
+
+BEGIN {
+ package Bar::Implementation;
+ use Moose;
+
+ has connection => (is => 'ro', isa => 'Str');
+
+ sub tweak { 1; };
+
+ package My::Factory;
+ use MooseX::AbstractFactory;
+
+ sub _get_implementation_class {
+ my ($self, $impl) = @_;
+
+ return "Bar::" . $impl;
+ }
+}
+
+my $imp;
+
+lives_ok {
+ $imp = My::Factory->create(
+ 'Implementation',
+ { connection => 'Type1' }
+ );
+} "Factory->new() doesn't die";
+
+isa_ok($imp, "Bar::Implementation"); \ No newline at end of file
diff --git a/t/05_override_validate_implementation.t b/t/05_override_validate_implementation.t
new file mode 100644
index 0000000..652f063
--- /dev/null
+++ b/t/05_override_validate_implementation.t
@@ -0,0 +1,47 @@
+use Test::More tests => 2;
+use Test::Exception;
+
+BEGIN {
+ #----------------------------------------------------
+ package My::Implementation;
+ use Moose;
+
+ #----------------------------------------------------
+ # Factory class, all implementations valid
+ package My::FactoryA;
+ use MooseX::AbstractFactory;
+
+ implementation_class_via sub { "My::Implementation" };
+
+ sub _validate_implementation_class {
+ return;
+ }
+
+ #----------------------------------------------------
+ # Factory class, all implementations invalid
+ package My::FactoryB;
+ use MooseX::AbstractFactory;
+
+ implementation_class_via sub { "My::Implementation" };
+
+ sub _validate_implementation_class {
+ confess "invalid implementation";
+ }
+
+}
+
+my $imp;
+
+lives_ok {
+ $imp = My::FactoryA->create('Implementation',
+ {});
+}
+"FactoryA->new() doesn't die with Implementation";
+
+dies_ok {
+ $imp = My::FactoryB->create(
+ 'Implementation',
+ {},
+ );
+}
+"FactoryB->new() dies with implementation"; \ No newline at end of file
diff --git a/t/97_pod.t b/t/97_pod.t
new file mode 100644
index 0000000..0abe73a
--- /dev/null
+++ b/t/97_pod.t
@@ -0,0 +1,4 @@
+use Test::More;
+eval "use Test::Pod 1.14";
+plan skip_all => "Test::Pod 1.14 required for testing POD" if $@;
+all_pod_files_ok(); \ No newline at end of file
diff --git a/t/98_pod_coverage.t b/t/98_pod_coverage.t
new file mode 100644
index 0000000..975b60d
--- /dev/null
+++ b/t/98_pod_coverage.t
@@ -0,0 +1,12 @@
+use Test::More;
+
+eval "use Test::Pod::Coverage 1.00";
+plan skip_all => "Test::Pod::Coverage 1.00 required for testing POD coverage" if $@;
+eval "use Pod::Coverage::Moose";
+plan skip_all => "Pod::Coverage::Moose required for testing POD coverage" if $@;
+
+all_pod_coverage_ok(
+ { trustme => [qr/^(new|.*meta)$/],
+ coverage_class => 'Pod::Coverage::Moose',
+ }
+); \ No newline at end of file
diff --git a/t/99_perl_critic.t b/t/99_perl_critic.t
new file mode 100644
index 0000000..c7b6b61
--- /dev/null
+++ b/t/99_perl_critic.t
@@ -0,0 +1,21 @@
+use strict;
+use warnings;
+use File::Spec;
+use Test::More;
+use English qw(-no_match_vars);
+
+if ( not $ENV{TEST_AUTHOR} ) {
+ my $msg = 'Author test. Set $ENV{TEST_AUTHOR} to a true value to run.';
+ plan( skip_all => $msg );
+}
+
+eval { require Test::Perl::Critic; };
+
+if ( $EVAL_ERROR ) {
+ my $msg = 'Test::Perl::Critic required to criticise code';
+ plan( skip_all => $msg );
+}
+
+my $rcfile = File::Spec->catfile( 't', 'perlcriticrc' );
+Test::Perl::Critic->import( -profile => $rcfile );
+all_critic_ok(); \ No newline at end of file
diff --git a/t/perlcriticrc b/t/perlcriticrc
new file mode 100644
index 0000000..ec6f6dc
--- /dev/null
+++ b/t/perlcriticrc
@@ -0,0 +1,5 @@
+severity = 2
+exclude = BuiltinFunctions::ProhibitStringyEval Variables::ProhibitPunctuationVars TestingAndDebugging::RequireUseStrict TestingAndDebugging::RequireUseWarnings ErrorHandling::RequireCheckingReturnValueOfEval Miscellanea::RequireRcsKeywords
+
+[Documentation::RequirePodSections]
+lib_sections = NAME | SYNOPSIS | DESCRIPTION | SUBROUTINES/METHODS | BUGS AND LIMITATIONS | AUTHOR