forked from moose/Moose
-
Notifications
You must be signed in to change notification settings - Fork 0
/
exception-lazyattributeneedsadefault.t
67 lines (52 loc) · 1.51 KB
/
exception-lazyattributeneedsadefault.t
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
use strict;
use warnings;
use Test::More;
use Test::Fatal;
use Moose::Util 'throw_exception';
{
package Foo;
use Moose;
has 'foo' => (
is => 'ro'
);
has 'bar' => (
is => 'ro'
);
}
{
my $exception = exception {
throw_exception( LazyAttributeNeedsADefault => attribute_name => "foo",
attribute => Foo->meta->get_attribute("bar")
);
};
like(
$exception,
qr/\Qattribute_name (foo) does not match attribute->name (bar)/,
"you have given attribute_name as 'foo' and attribute->name as 'bar'");
isa_ok(
$exception,
"Moose::Exception::AttributeNamesDoNotMatch",
"you have given attribute_name as 'foo' and attribute->name as 'bar'");
is(
$exception->attribute_name,
"foo",
"you have given attribute_name as 'foo' and attribute->name as 'bar'");
is(
$exception->attribute->name,
"bar",
"you have given attribute_name as 'foo' and attribute->name as 'bar'");
}
{
my $exception = exception {
throw_exception("LazyAttributeNeedsADefault");
};
like(
$exception,
qr/\QYou need to give attribute or attribute_name or both/,
"please give either attribute or attribute_name");
isa_ok(
$exception,
"Moose::Exception::NeitherAttributeNorAttributeNameIsGiven",
"please give either attribute or attribute_name");
}
done_testing;