[libbread-board-perl] 07/66: 100% test coverage for the Bread::Board class
Jonas Smedegaard
js at alioth.debian.org
Sun Sep 29 21:23:31 UTC 2013
This is an automated email from the git hooks/post-receive script.
js pushed a commit to branch master
in repository libbread-board-perl.
commit d814a7f15786d8cd748656fde57377abbcb7c140
Author: Jason Galea <jason at lecstor.com>
Date: Thu Dec 15 14:12:16 2011 +1000
100% test coverage for the Bread::Board class
---
lib/Bread/Board.pm | 5 ++--
t/022_sugar.t | 4 +++
t/027_sugar_w_include.t | 4 +++
t/301_lecstor.t | 63 +++++++++++++++++++++++++++++++++++++++++++++++
t/lib/false.bb | 1 +
5 files changed, 75 insertions(+), 2 deletions(-)
diff --git a/lib/Bread/Board.pm b/lib/Bread/Board.pm
index b4ca55c..1c86562 100644
--- a/lib/Bread/Board.pm
+++ b/lib/Bread/Board.pm
@@ -49,7 +49,7 @@ sub container ($;$$) {
if ( scalar @_ == 0 ) {
if ( $name_is_obj ) {
# this is basically:
- # container( A::Bread::Boad::Container->new )
+ # container( A::Bread::Board::Container->new )
# which should work
$c = $name;
}
@@ -138,7 +138,8 @@ sub service ($@) {
$s = $params{service_class}->new(name => $name, %params);
}
else {
- my $type = $params{service_type} || (exists $params{block} ? 'Block' : 'Constructor');
+ my $type = $params{service_type};
+ $type = (exists $params{block} ? 'Block' : 'Constructor') unless $type;
$s = "Bread::Board::${type}Injection"->new(name => $name, %params);
}
}
diff --git a/t/022_sugar.t b/t/022_sugar.t
index 9b22d91..66dbac2 100644
--- a/t/022_sugar.t
+++ b/t/022_sugar.t
@@ -4,6 +4,7 @@ use strict;
use warnings;
use Test::More;
+use Test::Fatal;
use Bread::Board;
@@ -34,6 +35,9 @@ my $c = container 'MyApp';
Bread::Board::set_root_container($c);
+my $exception = exception{ Bread::Board::set_root_container($c) };
+like $exception, qr/^Cannot set the root container/, 'cannot set root container twice';
+
loggers(); # reuse baby !!!
service 'application' => (
diff --git a/t/027_sugar_w_include.t b/t/027_sugar_w_include.t
index 659ceb0..b35c3f8 100644
--- a/t/027_sugar_w_include.t
+++ b/t/027_sugar_w_include.t
@@ -18,6 +18,10 @@ like(exception { include "$FindBin::Bin/lib/doesnt_exist.bb" },
qr/Couldn't open.*doesnt_exist\.bb.*for reading/,
"we get appropriate errors for files that don't exist");
+like(exception { include "$FindBin::Bin/lib/false.bb" },
+ qr/Unknown error when compiling .*/,
+ "we get appropriate errors for files that evaluate to false");
+
{
package FileLogger;
use Moose;
diff --git a/t/301_lecstor.t b/t/301_lecstor.t
new file mode 100644
index 0000000..bf0b93b
--- /dev/null
+++ b/t/301_lecstor.t
@@ -0,0 +1,63 @@
+#!/usr/bin/perl
+
+use strict;
+use warnings;
+
+use Test::More;
+use Test::Fatal;
+
+use Bread::Board;
+use Bread::Board::Container;
+
+
+my $exception = exception { container (bless {}, 'NameObject') };
+like( $exception, qr/^Attribute \(name\)/, "exception begins with: Attribute (name)" );
+
+
+ok ( (container 'MyApp' => as { service 'service_name',
+ 'service_type' => 'Block',
+ 'block' => sub{} } ), 'hmmm' );
+
+my $c = Bread::Board::Container->new(name => '/');
+isa_ok($c, 'Bread::Board::Container');
+
+
+ok ( (container $c), 'name is object' );
+
+
+$exception = exception{ container $c, 'summat', 'summat else' };
+like( $exception, qr/^container\(\$object, \.\.\.\) is not supported/, 'exception begins with: container($object, ...) is not supported' );
+
+
+$exception = exception{
+ container 'MyApp' => as { service 'service_name', 'summat', 'summat else', 'summat else again' }
+};
+like( $exception, qr/^I don't understand/, 'exception begins with: I don\'t understand' );
+
+{
+ package MyNonService;
+ use Moose;
+}
+
+$exception = exception{
+ container 'MyApp' => as {
+ service 'service_name',
+ 'service_class' => 'MyNonService',
+ }
+};
+like( $exception, qr/^The service class must do the Bread::Board::Service role/, 'exception begins with: The service class must do the Bread::Board::Service role' );
+
+
+$exception = exception{
+ typemap ('Type')
+};
+like( $exception, qr/^Too many \(or too few\)/, 'exception begins with: Too many (or too few)' );
+
+
+$exception = exception{
+ typemap ('Type', MyNonService->new)
+};
+like( $exception, qr/^No idea what to do with a/, 'exception begins with: No idea what to do with a' );
+
+
+done_testing;
diff --git a/t/lib/false.bb b/t/lib/false.bb
new file mode 100644
index 0000000..0f57817
--- /dev/null
+++ b/t/lib/false.bb
@@ -0,0 +1 @@
+0;
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-perl/packages/libbread-board-perl.git
More information about the Pkg-perl-cvs-commits
mailing list