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