6 use Test::More tests => 3 + 12 + (($^V ge v5.10.0) ? 2 : 0);
8 use Scalar::Util qw/set_prototype/;
9 use Sub::Prototype::Util qw/recall/;
11 eval { recall undef };
12 like($@, qr/^Wrong\s+subroutine/, 'recall undef croaks');
14 like($@, qr/^Wrong\s+subroutine/, 'recall "" croaks');
15 eval { recall 'hlagh' };
16 like($@, qr/^Undefined\s+subroutine/, 'recall <unknown> croaks');
18 sub noproto { $_[1], $_[0] }
19 sub mytrunc ($;$) { $_[1], $_[0] };
20 sub mygrep1 (&@) { grep { $_[0]->() } @_[1 .. $#_] };
21 sub mygrep2 (\&@) { grep { $_[0]->() } @_[1 .. $#_] };
22 my $t = [ 1, 2, 3, 4 ];
23 my $g = [ sub { $_ > 2 }, 1 .. 5 ];
25 [ 'main::noproto', 'no prototype', $t, $t, [ 2, 1 ] ],
26 [ 'CORE::push', 'push', [ [ 1, 2 ], 3, 5 ], [ [ 1, 2, 3, 5 ], 3, 5 ], [ 4 ] ],
27 [ 'main::mytrunc', 'truncate 1', [ 1 ], [ 1 ], [ undef, 1 ] ],
28 [ 'main::mytrunc', 'truncate 2', $t, $t, [ 2, 1 ] ],
29 [ 'main::mygrep1', 'grep1', $g, $g, [ 3 .. 5 ] ],
30 [ 'main::mygrep2', 'grep2', $g, $g, [ 3 .. 5 ] ],
32 sub myit { push @{$_->[2]}, 1; return 2 };
34 set_prototype \&myit, '_';
35 push @tests, [ 'main::myit', '_ prototype', [ ], [ 1 ], [ 2 ] ];
39 my $r = [ recall $_->[0], @{$_->[2]} ];
40 is_deeply($r, $_->[4], $_->[1] . ' return value');
41 is_deeply($_->[2], $_->[3], $_->[1] . ' arguments modification');