Skip some distros with known test issues
[gitmo/Moose.git] / t / immutable / immutable_moose.t
CommitLineData
03aac1fa 1#!/usr/bin/perl
2
3use strict;
4use warnings;
5
a28e50e4 6use Test::More;
b10dde3a 7use Test::Fatal;
39b3bc94 8
7ff56534 9use Moose::Meta::Role;
10
ac2dc464 11
12{
fa2985bc 13 package FooRole;
14 our $VERSION = '0.01';
15 sub foo {'FooRole::foo'}
a8878950 16}
ac2dc464 17
18{
fa2985bc 19 package Foo;
20 use Moose;
21
22 #two checks because the inlined methods are different when
23 #there is a TC present.
24 has 'foos' => ( is => 'ro', lazy_build => 1 );
25 has 'bars' => ( isa => 'Str', is => 'ro', lazy_build => 1 );
26 has 'bazes' => ( isa => 'Str', is => 'ro', builder => '_build_bazes' );
27 sub _build_foos {"many foos"}
28 sub _build_bars {"many bars"}
29 sub _build_bazes {"many bazes"}
ac2dc464 30}
31
32{
fa2985bc 33 my $foo_role = Moose::Meta::Role->initialize('FooRole');
34 my $meta = Foo->meta;
35
b10dde3a 36 is( exception { Foo->new }, undef, "lazy_build works" );
fa2985bc 37 is( Foo->new->foos, 'many foos',
38 "correct value for 'foos' before inlining constructor" );
39 is( Foo->new->bars, 'many bars',
40 "correct value for 'bars' before inlining constructor" );
41 is( Foo->new->bazes, 'many bazes',
42 "correct value for 'bazes' before inlining constructor" );
b10dde3a 43 is( exception { $meta->make_immutable }, undef, "Foo is imutable" );
44 is( exception { $meta->identifier }, undef, "->identifier on metaclass lives" );
45 isnt( exception { $meta->add_role($foo_role) }, undef, "Add Role is locked" );
46 is( exception { Foo->new }, undef, "Inlined constructor works with lazy_build" );
fa2985bc 47 is( Foo->new->foos, 'many foos',
48 "correct value for 'foos' after inlining constructor" );
49 is( Foo->new->bars, 'many bars',
50 "correct value for 'bars' after inlining constructor" );
51 is( Foo->new->bazes, 'many bazes',
52 "correct value for 'bazes' after inlining constructor" );
b10dde3a 53 is( exception { $meta->make_mutable }, undef, "Foo is mutable" );
54 is( exception { $meta->add_role($foo_role) }, undef, "Add Role is unlocked" );
7a5b07b3 55
39b3bc94 56}
946289d1 57
73b84d2e 58{
59 package Bar;
60
61 use Moose;
62
63 sub BUILD { 'bar' }
64}
65
66{
67 package Baz;
68
69 use Moose;
70
71 extends 'Bar';
72
73 sub BUILD { 'baz' }
74}
75
b10dde3a 76is( exception { Bar->meta->make_immutable }, undef, 'Immutable meta with single BUILD' );
73b84d2e 77
b10dde3a 78is( exception { Baz->meta->make_immutable }, undef, 'Immutable meta with multiple BUILDs' );
73b84d2e 79
946289d1 80=pod
81
82Nothing here yet, but soon :)
83
84=cut
a28e50e4 85
86done_testing;