Reorganize t/020_attributes/
[gitmo/Mouse.git] / t / 020_attributes / 006_attribute_required.t
CommitLineData
4060c871 1#!/usr/bin/perl
1f5ce14a 2# This is automatically generated by author/import-moose-test.pl.
3# DO NOT EDIT THIS FILE. ANY CHANGES WILL BE LOST!!!
4use t::lib::MooseCompat;
4060c871 5
6use strict;
7use warnings;
8
1f5ce14a 9use Test::More;
4060c871 10use Test::Exception;
11
12
4060c871 13{
14 package Foo;
15 use Mouse;
16
17 has 'bar' => (is => 'ro', required => 1);
18 has 'baz' => (is => 'rw', default => 100, required => 1);
19 has 'boo' => (is => 'rw', lazy => 1, default => 50, required => 1);
20}
21
22{
23 my $foo = Foo->new(bar => 10, baz => 20, boo => 100);
24 isa_ok($foo, 'Foo');
25
26 is($foo->bar, 10, '... got the right bar');
27 is($foo->baz, 20, '... got the right baz');
28 is($foo->boo, 100, '... got the right boo');
29}
30
31{
32 my $foo = Foo->new(bar => 10, boo => 5);
33 isa_ok($foo, 'Foo');
34
35 is($foo->bar, 10, '... got the right bar');
36 is($foo->baz, 100, '... got the right baz');
37 is($foo->boo, 5, '... got the right boo');
38}
39
40{
41 my $foo = Foo->new(bar => 10);
42 isa_ok($foo, 'Foo');
43
44 is($foo->bar, 10, '... got the right bar');
45 is($foo->baz, 100, '... got the right baz');
46 is($foo->boo, 50, '... got the right boo');
47}
48
49#Yeah.. this doesn't work like this anymore, see below. (groditi)
50#throws_ok {
51# Foo->new(bar => 10, baz => undef);
52#} qr/^Attribute \(baz\) is required and cannot be undef/, '... must supply all the required attribute';
53
54#throws_ok {
55# Foo->new(bar => 10, boo => undef);
56#} qr/^Attribute \(boo\) is required and cannot be undef/, '... must supply all the required attribute';
57
58lives_ok {
59 Foo->new(bar => 10, baz => undef);
60} '... undef is a valid attribute value';
61
62lives_ok {
63 Foo->new(bar => 10, boo => undef);
64} '... undef is a valid attribute value';
65
66
67throws_ok {
68 Foo->new;
69} qr/^Attribute \(bar\) is required/, '... must supply all the required attribute';
70
1f5ce14a 71done_testing;