From: Shawn M Moore Date: Wed, 11 Jun 2008 05:36:12 +0000 (+0000) Subject: Improve test code coverage of Squirrel X-Git-Tag: 0.04~28 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=eb061d5b0c1eea896c00ac732f6f4096255a79e3;p=gitmo%2FMouse.git Improve test code coverage of Squirrel --- diff --git a/lib/Squirrel.pm b/lib/Squirrel.pm index de12906..5599db0 100644 --- a/lib/Squirrel.pm +++ b/lib/Squirrel.pm @@ -27,7 +27,8 @@ sub _handlers { my $caller = caller(1); - $pkgs{$caller} ||= $class->_choose_backend; + $pkgs{$caller} = $class->_choose_backend + unless $pkgs{$caller}; } sub import { diff --git a/t/201-squirrel.t b/t/201-squirrel.t index aa09a9d..198af9e 100644 --- a/t/201-squirrel.t +++ b/t/201-squirrel.t @@ -4,8 +4,9 @@ use strict; use warnings; use Test::More; +use Scalar::Util 'blessed'; -{ +do { package Foo; use Squirrel; @@ -13,17 +14,19 @@ use Test::More; isa => "Int", is => "rw", ); -} + + no Squirrel; +}; # note that 'Foo' is defined before this, to prevent Moose being loaded from # affecting its definition BEGIN { plan skip_all => "Moose required for this test" unless eval { require Moose }; - plan 'no_plan'; + plan tests => 12; } -{ +do { package Bar; use Squirrel; @@ -31,20 +34,38 @@ BEGIN { isa => "Int", is => "rw", ); -} -my $foo = Foo->new( foo => 3 ); + no Squirrel; +}; + +my $foo = Foo->new(foo => 3); +isa_ok($foo, "Foo"); +isa_ok($foo, "Mouse::Object"); +is($foo->foo, 3, "accessor"); + +my $bar = Bar->new(foo => 3); +isa_ok($bar, "Bar"); +isa_ok($bar, "Moose::Object"); +is($bar->foo, 3, "accessor"); -isa_ok( $foo, "Foo" ); +ok(!Foo->can('has'), "Mouse::has was unimported"); +ok(!Bar->can('has'), "Moose::has was unimported"); -isa_ok( $foo, "Mouse::Object" ); +eval " + package Foo; + use Squirrel; + + has bar => (is => 'rw'); -is( $foo->foo, 3, "accessor" ); + package Bar; + use Squirrel; + has bar => (is => 'rw'); +"; -my $bar = Bar->new( foo => 3 ); +is(blessed(Foo->meta->get_attribute('foo')), 'Mouse::Meta::Attribute'); +is(blessed(Foo->meta->get_attribute('bar')), 'Mouse::Meta::Attribute', 'Squirrel is consistent if Moose was loaded between imports'); -isa_ok( $bar, "Bar" ); -isa_ok( $bar, "Moose::Object" ); +is(blessed(Bar->meta->get_attribute('foo')), 'Moose::Meta::Attribute'); +is(blessed(Bar->meta->get_attribute('bar')), 'Moose::Meta::Attribute'); -is( $bar->foo, 3, "accessor" );