Fix [perl #66970] Incorrect coderef in MODIFY_CODE_ATTRIBUTES
[p5sagit/p5-mst-13.2.git] / ext / List-Util / t / proto.t
CommitLineData
97605c51 1#!./perl
2
3BEGIN {
4 unless (-d 'blib') {
5 chdir 't' if -d 't';
6 @INC = '../lib';
7 require Config; import Config;
8 keys %Config; # Silence warning
9 if ($Config{extensions} !~ /\bList\/Util\b/) {
10 print "1..0 # Skip: List::Util was not built\n";
11 exit 0;
12 }
13 }
14}
15
cf083cf9 16use Scalar::Util ();
17use Test::More (grep { /set_prototype/ } @Scalar::Util::EXPORT_FAIL)
18 ? (skip_all => 'set_prototype requires XS version')
19 : (tests => 13);
97605c51 20
cf083cf9 21Scalar::Util->import('set_prototype');
97605c51 22
23sub f { }
cf083cf9 24is( prototype('f'), undef, 'no prototype');
25
97605c51 26$r = set_prototype(\&f,'$');
cf083cf9 27is( prototype('f'), '$', 'set prototype');
28is( $r, \&f, 'return value');
29
97605c51 30set_prototype(\&f,undef);
cf083cf9 31is( prototype('f'), undef, 'remove prototype');
32
97605c51 33set_prototype(\&f,'');
cf083cf9 34is( prototype('f'), '', 'empty prototype');
97605c51 35
36sub g (@) { }
cf083cf9 37is( prototype('g'), '@', '@ prototype');
38
97605c51 39set_prototype(\&g,undef);
cf083cf9 40is( prototype('g'), undef, 'remove prototype');
97605c51 41
cf083cf9 42sub stub;
43is( prototype('stub'), undef, 'non existing sub');
97605c51 44
cf083cf9 45set_prototype(\&stub,'$$$');
46is( prototype('stub'), '$$$', 'change non existing sub');
47
48sub f_decl ($$$$);
49is( prototype('f_decl'), '$$$$', 'forward declaration');
50
51set_prototype(\&f_decl,'\%');
52is( prototype('f_decl'), '\%', 'change forward declaration');
97605c51 53
54eval { &set_prototype( 'f', '' ); };
cf083cf9 55print "not " unless
56ok($@ =~ /^set_prototype: not a reference/, 'not a reference');
57
97605c51 58eval { &set_prototype( \'f', '' ); };
cf083cf9 59ok($@ =~ /^set_prototype: not a subroutine reference/, 'not a sub reference');