File: accessor_overwrite_warning.t

package info (click to toggle)
libmoose-perl 2.4000-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 7,408 kB
  • sloc: perl: 21,275; ansic: 291; makefile: 10
file content (75 lines) | stat: -rw-r--r-- 1,703 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
use strict;
use warnings;

use Test::Needs 'Test::Output';
use Test::More;
use Test::Output;

my $file = __FILE__;

{
    package Bar;
    use Moose;

    has has_attr => (
        is => 'ro',
    );

    ::stderr_like(
        sub {
            has attr => (
                is        => 'ro',
                predicate => 'has_attr',
            );
        },
        qr/
           \QYou are overwriting a reader (has_attr) for the has_attr attribute\E
           \Q (defined at $file line \E\d+\)
           \Q with a new predicate method for the attr attribute\E
           \Q (defined at $file line \E\d+\)
          /x,
        'overwriting an accessor for another attribute causes a warning'
    );
}

{
    package Foo;
    use Moose;

    ::stderr_like(
        sub {
            has buz => (
                reader => 'my_buz',
                writer => 'my_buz',
            );
        },
        qr/
           \QYou are overwriting a reader (my_buz) for the buz attribute\E
           \Q (defined at $file line \E\d+\)
           \Q with a new writer method for the buz attribute\E
           \Q (defined at $file line \E\d+\)
          /x,
        'overwriting an accessor for the same attribute causes a warning'
    );
}

{
    package Baz;
    use Moose;

    # This tests where Moose would also make a reader named buz for this
    # attribute, leading to an overwrite warning.
    ::stderr_is(
        sub {
            has buz => (
                is       => 'rw',
                accessor => 'buz',
                writer   => '_set_buz',
            );
        },
        q{},
        'no warning with rw attribute that has both an accessor and a writer'
    );
}

done_testing;