Fix [perl #66970] Incorrect coderef in MODIFY_CODE_ATTRIBUTES
[p5sagit/p5-mst-13.2.git] / ext / List-Util / t / reftype.t
CommitLineData
1bfb5477 1#!./perl
2
f4a2945e 3BEGIN {
1bfb5477 4 unless (-d 'blib') {
f4a2945e 5 chdir 't' if -d 't';
6 @INC = '../lib';
6b05f64e 7 require Config; import Config;
1bfb5477 8 keys %Config; # Silence warning
6b05f64e 9 if ($Config{extensions} !~ /\bList\/Util\b/) {
10 print "1..0 # Skip: List::Util was not built\n";
11 exit 0;
12 }
1bfb5477 13 }
f4a2945e 14}
15
2ff28616 16use Test::More tests => 29;
1bfb5477 17
f4a2945e 18use Scalar::Util qw(reftype);
19use vars qw($t $y $x *F);
20use Symbol qw(gensym);
21
22# Ensure we do not trigger and tied methods
23tie *F, 'MyTie';
2ff28616 24my $RE = $] < 5.011 ? 'SCALAR' : 'REGEXP';
f4a2945e 25
26@test = (
cf083cf9 27 [ undef, 1, 'number' ],
28 [ undef, 'A', 'string' ],
29 [ HASH => {}, 'HASH ref' ],
30 [ ARRAY => [], 'ARRAY ref' ],
31 [ SCALAR => \$t, 'SCALAR ref' ],
32 [ REF => \(\$t), 'REF ref' ],
33 [ GLOB => \*F, 'tied GLOB ref' ],
34 [ GLOB => gensym, 'GLOB ref' ],
35 [ CODE => sub {}, 'CODE ref' ],
2ff28616 36 [ IO => *STDIN{IO},'IO ref' ],
37 [ $RE => qr/x/, 'REGEEXP' ],
f4a2945e 38);
39
f4a2945e 40foreach $test (@test) {
cf083cf9 41 my($type,$what, $n) = @$test;
42
43 is( reftype($what), $type, $n);
44 next unless ref($what);
45
46 bless $what, "ABC";
47 is( reftype($what), $type, $n);
48
49 bless $what, "0";
50 is( reftype($what), $type, $n);
f4a2945e 51}
52
53package MyTie;
54
55sub TIEHANDLE { bless {} }
56sub DESTROY {}
57
58sub AUTOLOAD {
59 warn "$AUTOLOAD called";
60 exit 1; # May be in an eval
61}