more tests
[gitmo/Moose.git] / t / attributes / accessor_override_method.t
1 #!/usr/bin/env perl
2 use strict;
3 use warnings;
4 use Test::More;
5
6 use Test::Requires {
7     'Test::Output' => '0.01', # skip all if not installed
8 };
9
10 {
11     package Foo;
12     use Moose;
13
14     sub get_a { }
15     sub set_b { }
16     sub has_c { }
17     sub clear_d { }
18     sub e { }
19 }
20
21 my $foo_meta = Foo->meta;
22 stderr_like(sub { $foo_meta->add_attribute(a => (reader => 'get_a')) },
23             qr/^You are overwriting a locally defined method \(get_a\) with an accessor/, 'reader overriding gives proper warning');
24 stderr_like(sub { $foo_meta->add_attribute(b => (writer => 'set_b')) },
25             qr/^You are overwriting a locally defined method \(set_b\) with an accessor/, 'writer overriding gives proper warning');
26 stderr_like(sub { $foo_meta->add_attribute(c => (predicate => 'has_c')) },
27             qr/^You are overwriting a locally defined method \(has_c\) with an accessor/, 'predicate overriding gives proper warning');
28 stderr_like(sub { $foo_meta->add_attribute(d => (clearer => 'clear_d')) },
29             qr/^You are overwriting a locally defined method \(clear_d\) with an accessor/, 'clearer overriding gives proper warning');
30 stderr_like(sub { $foo_meta->add_attribute(e => (is => 'rw')) },
31             qr/^You are overwriting a locally defined method \(e\) with an accessor/, 'accessor overriding gives proper warning');
32
33 stderr_like(sub { $foo_meta->add_attribute(has => (is => 'rw')) },
34             qr/^You are overwriting a locally defined function \(has\) with an accessor/, 'function overriding gives proper warning');
35
36 done_testing;