Redid conversion to Test::Fatal
[gitmo/Moose.git] / t / 020_attributes / 029_accessor_context.t
CommitLineData
f9cf947d 1#!/usr/bin/perl
2
3use strict;
4use warnings;
a28e50e4 5use Test::More;
b10dde3a 6use Test::Fatal;
f9cf947d 7
b10dde3a 8is( exception {
f9cf947d 9 package My::Class;
10 use Moose;
11
12 has s_rw => (
13 is => 'rw',
14 );
15
16 has s_ro => (
17 is => 'ro',
18 );
19
20 has a_rw => (
21 is => 'rw',
22 isa => 'ArrayRef',
23
24 auto_deref => 1,
25 );
26
27 has a_ro => (
28 is => 'ro',
29 isa => 'ArrayRef',
30
31 auto_deref => 1,
32 );
33
34 has h_rw => (
35 is => 'rw',
36 isa => 'HashRef',
37
38 auto_deref => 1,
39 );
40
41 has h_ro => (
42 is => 'ro',
43 isa => 'HashRef',
44
45 auto_deref => 1,
46 );
b10dde3a 47}, undef, 'class definition' );
f9cf947d 48
b10dde3a 49is( exception {
f9cf947d 50 my $o = My::Class->new();
51
52 is_deeply [scalar $o->s_rw], [undef], 'uninitialized scalar attribute/rw in scalar context';
53 is_deeply [$o->s_rw], [undef], 'uninitialized scalar attribute/rw in list context';
54 is_deeply [scalar $o->s_ro], [undef], 'uninitialized scalar attribute/ro in scalar context';
55 is_deeply [$o->s_ro], [undef], 'uninitialized scalar attribute/ro in list context';
56
57
58 is_deeply [scalar $o->a_rw], [undef], 'uninitialized ArrayRef attribute/rw in scalar context';
59 is_deeply [$o->a_rw], [], 'uninitialized ArrayRef attribute/rw in list context';
60 is_deeply [scalar $o->a_ro], [undef], 'uninitialized ArrayRef attribute/ro in scalar context';
61 is_deeply [$o->a_ro], [], 'uninitialized ArrayRef attribute/ro in list context';
62
63 is_deeply [scalar $o->h_rw], [undef], 'uninitialized HashRef attribute/rw in scalar context';
64 is_deeply [$o->h_rw], [], 'uninitialized HashRef attribute/rw in list context';
65 is_deeply [scalar $o->h_ro], [undef], 'uninitialized HashRef attribute/ro in scalar context';
66 is_deeply [$o->h_ro], [], 'uninitialized HashRef attribute/ro in list context';
67
b10dde3a 68}, undef, 'testing' );
a28e50e4 69
70done_testing;