-
Notifications
You must be signed in to change notification settings - Fork 6
/
proto.t
44 lines (33 loc) · 1.03 KB
/
proto.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
use strict;
use warnings;
use Test::More tests => 8;
use vars qw/@warnings/;
BEGIN { $SIG{__WARN__} = sub { push @warnings, @_ } }
BEGIN { is(@warnings, 0, 'no warnings yet') }
use signatures;
sub with_proto ($x, $y, $z) : proto($$$) {
return $x + $y + $z;
}
{
my $foo;
sub with_lvalue () : lvalue proto() { $foo }
}
is(prototype('with_proto'), '$$$', ':proto attribute');
is(prototype('with_lvalue'), '', ':proto with other attributes');
with_lvalue = 1;
is(with_lvalue, 1, 'other attributes still there');
BEGIN { is(@warnings, 0, 'no warnings with correct :proto declarations') }
sub invalid_proto ($x) : proto(invalid) { $x }
BEGIN {
TODO: {
local $TODO = ':proto checks not yet implemented';
is(@warnings, 1, 'warning with illegal :proto');
like(
$warnings[0],
qr/Illegal character in prototype for main::invalid_proto : invalid at /,
'warning looks sane',
);
}
}
eval 'sub foo ($bar) : proto { $bar }';
like($@, qr/proto attribute requires argument/);