Fix tests for accessors
[gitmo/Mouse.git] / t / 201-squirrel.t
CommitLineData
692e1bcd 1#!/usr/bin/perl
2
3use strict;
4use warnings;
5
6use Test::More;
6c169c50 7use Scalar::Util 'blessed';
692e1bcd 8
b03fda9f 9# Don't spew deprecation warnings onto the user's screen
10BEGIN {
11 $SIG{__WARN__} = sub { warn $_[0] if $_[0] !~ /Squirrel is deprecated/ };
12}
13
eb061d5b 14do {
692e1bcd 15 package Foo;
16 use Squirrel;
17
18 has foo => (
19 isa => "Int",
20 is => "rw",
21 );
eb061d5b 22
23 no Squirrel;
24};
692e1bcd 25
26# note that 'Foo' is defined before this, to prevent Moose being loaded from
27# affecting its definition
28
29BEGIN {
9cc87fff 30 plan skip_all => "Moose 0.68 required for this test" unless eval { require Moose && Moose->VERSION('0.68') };
eb061d5b 31 plan tests => 12;
692e1bcd 32}
33
eb061d5b 34do {
692e1bcd 35 package Bar;
36 use Squirrel;
37
38 has foo => (
39 isa => "Int",
40 is => "rw",
41 );
692e1bcd 42
eb061d5b 43 no Squirrel;
44};
45
46my $foo = Foo->new(foo => 3);
47isa_ok($foo, "Foo");
48isa_ok($foo, "Mouse::Object");
49is($foo->foo, 3, "accessor");
50
51my $bar = Bar->new(foo => 3);
52isa_ok($bar, "Bar");
53isa_ok($bar, "Moose::Object");
54is($bar->foo, 3, "accessor");
692e1bcd 55
eb061d5b 56ok(!Foo->can('has'), "Mouse::has was unimported");
57ok(!Bar->can('has'), "Moose::has was unimported");
692e1bcd 58
eb061d5b 59eval "
60 package Foo;
61 use Squirrel;
62
63 has bar => (is => 'rw');
60e2164a 64 __PACKAGE__->meta->make_immutable;
692e1bcd 65
eb061d5b 66 package Bar;
67 use Squirrel;
692e1bcd 68
eb061d5b 69 has bar => (is => 'rw');
60e2164a 70 __PACKAGE__->meta->make_immutable;
eb061d5b 71";
60e2164a 72warn $@ if $@;
692e1bcd 73
eb061d5b 74is(blessed(Foo->meta->get_attribute('foo')), 'Mouse::Meta::Attribute');
75is(blessed(Foo->meta->get_attribute('bar')), 'Mouse::Meta::Attribute', 'Squirrel is consistent if Moose was loaded between imports');
692e1bcd 76
eb061d5b 77is(blessed(Bar->meta->get_attribute('foo')), 'Moose::Meta::Attribute');
78is(blessed(Bar->meta->get_attribute('bar')), 'Moose::Meta::Attribute');
692e1bcd 79