Commit | Line | Data |
700071de |
1 | #!perl |
2 | |
3 | use strict; |
4 | use warnings FATAL => 'all'; |
5 | use Dir::Self; |
6 | use lib __DIR__ . '/lib'; |
7 | |
1a52f2db |
8 | use Test::More; |
9 | use Test::Fatal; |
700071de |
10 | |
11 | |
1a52f2db |
12 | SKIP: |
13 | { |
14 | eval { require Moose } or skip "Moose required for testing Moose types", 1; |
700071de |
15 | |
1a52f2db |
16 | require MooseLoadTest; |
700071de |
17 | |
1a52f2db |
18 | my $foobar = Foo::Bar->new; |
700071de |
19 | |
1a52f2db |
20 | # can't check for type module not being loaded here, because Moose will drag it in |
700071de |
21 | |
700071de |
22 | |
1a52f2db |
23 | $foobar->check_int(42); |
700071de |
24 | |
1a52f2db |
25 | # now we should have loaded Moose to do our type checking |
26 | |
27 | like $INC{'Moose/Util/TypeConstraints.pm'}, qr{Moose/Util/TypeConstraints\.pm$}, 'loaded Moose'; |
28 | |
29 | |
30 | # tests for ScalarRef[X] have to live here, because they only work with Moose |
31 | |
32 | my $method = 'check_paramized_sref'; |
33 | my $bad_ref = \'thing'; |
34 | is exception { $foobar->$method(\42) }, undef, 'call with good value for paramized_sref passes'; |
35 | like exception { $foobar->$method($bad_ref) }, |
36 | qr/\bcheck_paramized_sref\b.+\$bar\b.+ScalarRef\[Num\]/, |
37 | 'call with bad value for paramized_sref dies'; |
38 | } |
39 | |
40 | |
41 | done_testing; |