Add another MOOSE_TEST_MD option, MooseX
[gitmo/Moose.git] / t / attributes / accessor_override_method.t
CommitLineData
baf17065 1#!/usr/bin/env perl
2use strict;
3use warnings;
4use Test::More;
5
4d438a84 6use Test::Requires {
e0dc8e65 7 'Test::Output' => '0.01', # skip all if not installed
4d438a84 8};
baf17065 9
10{
e0dc8e65 11
baf17065 12 package Foo;
13 use Moose;
14
e0dc8e65 15 sub get_a { }
16 sub set_b { }
17 sub has_c { }
baf17065 18 sub clear_d { }
e0dc8e65 19 sub e { }
5bfb3fa4 20 sub stub;
baf17065 21}
22
23my $foo_meta = Foo->meta;
e0dc8e65 24stderr_like(
25 sub { $foo_meta->add_attribute( a => ( reader => 'get_a' ) ) },
26 qr/^You are overwriting a locally defined method \(get_a\) with an accessor/,
27 'reader overriding gives proper warning'
28);
29stderr_like(
30 sub { $foo_meta->add_attribute( b => ( writer => 'set_b' ) ) },
31 qr/^You are overwriting a locally defined method \(set_b\) with an accessor/,
32 'writer overriding gives proper warning'
33);
34stderr_like(
35 sub { $foo_meta->add_attribute( c => ( predicate => 'has_c' ) ) },
36 qr/^You are overwriting a locally defined method \(has_c\) with an accessor/,
37 'predicate overriding gives proper warning'
38);
39stderr_like(
40 sub { $foo_meta->add_attribute( d => ( clearer => 'clear_d' ) ) },
41 qr/^You are overwriting a locally defined method \(clear_d\) with an accessor/,
42 'clearer overriding gives proper warning'
43);
44stderr_like(
45 sub { $foo_meta->add_attribute( e => ( is => 'rw' ) ) },
46 qr/^You are overwriting a locally defined method \(e\) with an accessor/,
47 'accessor overriding gives proper warning'
48);
5bfb3fa4 49stderr_is(
50 sub { $foo_meta->add_attribute( stub => ( is => 'rw' ) ) },
51 q{},
52 'overriding a stub with an accessor does not warn'
53);
e0dc8e65 54stderr_like(
55 sub { $foo_meta->add_attribute( has => ( is => 'rw' ) ) },
56 qr/^You are overwriting a locally defined function \(has\) with an accessor/,
57 'function overriding gives proper warning'
58);
3968746e 59
a28e50e4 60done_testing;