Convert all tests to done_testing.
[gitmo/Moose.git] / t / 020_attributes / 008_attribute_type_unions.t
1 #!/usr/bin/perl
2
3 use strict;
4 use warnings;
5
6 use Test::More;
7 use Test::Exception;
8
9
10 {
11     package Foo;
12     use Moose;
13
14     has 'bar' => (is => 'rw', isa => 'ArrayRef | HashRef');
15 }
16
17 my $foo = Foo->new;
18 isa_ok($foo, 'Foo');
19
20 lives_ok {
21     $foo->bar([])
22 } '... set bar successfully with an ARRAY ref';
23
24 lives_ok {
25     $foo->bar({})
26 } '... set bar successfully with a HASH ref';
27
28 dies_ok {
29     $foo->bar(100)
30 } '... couldnt set bar successfully with a number';
31
32 dies_ok {
33     $foo->bar(sub {})
34 } '... couldnt set bar successfully with a CODE ref';
35
36 # check the constructor
37
38 lives_ok {
39     Foo->new(bar => [])
40 } '... created new Foo with bar successfully set with an ARRAY ref';
41
42 lives_ok {
43     Foo->new(bar => {})
44 } '... created new Foo with bar successfully set with a HASH ref';
45
46 dies_ok {
47     Foo->new(bar => 50)
48 } '... didnt create a new Foo with bar as a number';
49
50 dies_ok {
51     Foo->new(bar => sub {})
52 } '... didnt create a new Foo with bar as a CODE ref';
53
54 {
55     package Bar;
56     use Moose;
57
58     has 'baz' => (is => 'rw', isa => 'Str | CodeRef');
59 }
60
61 my $bar = Bar->new;
62 isa_ok($bar, 'Bar');
63
64 lives_ok {
65     $bar->baz('a string')
66 } '... set baz successfully with a string';
67
68 lives_ok {
69     $bar->baz(sub { 'a sub' })
70 } '... set baz successfully with a CODE ref';
71
72 dies_ok {
73     $bar->baz(\(my $var1))
74 } '... couldnt set baz successfully with a SCALAR ref';
75
76 dies_ok {
77     $bar->baz({})
78 } '... couldnt set bar successfully with a HASH ref';
79
80 # check the constructor
81
82 lives_ok {
83     Bar->new(baz => 'a string')
84 } '... created new Bar with baz successfully set with a string';
85
86 lives_ok {
87     Bar->new(baz => sub { 'a sub' })
88 } '... created new Bar with baz successfully set with a CODE ref';
89
90 dies_ok {
91     Bar->new(baz => \(my $var2))
92 } '... didnt create a new Bar with baz as a number';
93
94 dies_ok {
95     Bar->new(baz => {})
96 } '... didnt create a new Bar with baz as a HASH ref';
97
98 done_testing;