blob: 00efb25dbd157d9b64094edd3d41854641aba502 (
plain)
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
|
use strict;
use warnings;
use Test::More;
use Test::Fatal;
use Moose();
{
package Bar;
use Moose;
has 'foo' => (
is => 'rw',
isa => 'ArrayRef[Int]',
traits => ['Array'],
handles => { push => 'push'}
);
}
my $bar_obj = Bar->new;
{
my $exception = exception {
$bar_obj->push(1.2);
};
like(
$exception,
qr/A new member value for foo does not pass its type constraint because: Validation failed for 'Int' with value 1.2/,
"trying to push a Float(1.2) to ArrayRef[Int]");
isa_ok(
$exception,
'Moose::Exception::ValidationFailedForInlineTypeConstraint',
"trying to push a Float(1.2) to ArrayRef[Int]");
is(
$exception->attribute_name,
"foo",
"trying to push a Float(1.2) to ArrayRef[Int]");
is(
$exception->class_name,
"Bar",
"trying to push a Float(1.2) to ArrayRef[Int]");
is(
$exception->value,
1.2,
"trying to push a Float(1.2) to ArrayRef[Int]");
}
done_testing;
|