Move t/100_with_moose t/810_with_moose
[gitmo/Mouse.git] / t / 810_with_moose / 201-squirrel.t
diff --git a/t/810_with_moose/201-squirrel.t b/t/810_with_moose/201-squirrel.t
new file mode 100644 (file)
index 0000000..c9360f1
--- /dev/null
@@ -0,0 +1,82 @@
+#!/usr/bin/perl
+
+use strict;
+use warnings;
+
+use Test::More;
+
+use Mouse::Spec;
+
+use Scalar::Util 'blessed';
+
+# Don't spew deprecation warnings onto the user's screen
+BEGIN {
+    $SIG{__WARN__} = sub { warn $_[0] if $_[0] !~ /Squirrel is deprecated/ };
+}
+
+do {
+    package Foo;
+    use Squirrel; # load Mouse
+
+    has foo => (
+        isa => "Int",
+        is  => "rw",
+    );
+
+    no Squirrel;
+};
+
+# note that 'Foo' is defined before this, to prevent Moose being loaded from
+# affecting its definition
+BEGIN {
+    eval{ require Moose && Moose->VERSION(Mouse::Spec->MooseVersion) };
+    plan skip_all => "Moose $Mouse::Spec::MooseVersion required for this test" if $@;
+    plan tests => 12;
+}
+
+do {
+    package Bar;
+    use Squirrel; # load Moose
+
+    has foo => (
+        isa => "Int",
+        is  => "rw",
+    );
+
+    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");
+
+ok(!Foo->can('has'), "Mouse::has was unimported");
+ok(!Bar->can('has'), "Moose::has was unimported");
+
+eval q{
+    package Foo;
+    use Squirrel;
+
+    has bar => (is => 'rw');
+    __PACKAGE__->meta->make_immutable;
+
+    package Bar;
+    use Squirrel;
+
+    has bar => (is => 'rw');
+    __PACKAGE__->meta->make_immutable;
+};
+warn $@ if $@;
+
+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');
+
+is(blessed(Bar->meta->get_attribute('foo')), 'Moose::Meta::Attribute');
+is(blessed(Bar->meta->get_attribute('bar')), 'Moose::Meta::Attribute');
+