]> Dogcows Code - chaz/p5-Return-Type-Lexical/blob - t/basic.t
initial commit
[chaz/p5-Return-Type-Lexical] / t / basic.t
1 #!/usr/bin/env perl
2
3 use warnings;
4 use strict;
5
6 use Test::Exception;
7 use Test::More;
8
9 use Types::Standard qw(Int);
10
11 {
12 use Return::Type::Lexical;
13 sub foo :ReturnType(Int) { 'not an int' }
14 no Return::Type::Lexical;
15 sub bar :ReturnType(Int) { 'not an int' }
16 use Return::Type::Lexical check => 0;
17 sub baz :ReturnType(Int) { 'not an int' }
18 }
19
20 dies_ok { my $dummy = foo() } 'return type enforced';
21 lives_and { my $dummy = bar(); is $dummy, 'not an int' } 'return type not enforced';
22 lives_and { my $dummy = baz(); is $dummy, 'not an int' } 'return type not enforced';
23 dies_ok { my $dummy = Other::qux() } 'return type enforced when using Return::Type directly';
24
25 done_testing;
26
27 {
28 package Other;
29
30 use Types::Standard qw(Int);
31 use Return::Type;
32
33 sub qux :ReturnType(Int) { 'not an int' }
34 }
This page took 0.036484 seconds and 4 git commands to generate.