The debugging aid #19182 didn't.
[p5sagit/p5-mst-13.2.git] / ext / B / t / b.t
1 #!./perl
2
3 BEGIN {
4     chdir 't' if -d 't';
5     if ($^O eq 'MacOS') {
6         @INC = qw(: ::lib ::macos:lib);
7     } else {
8         @INC = '.';
9         push @INC, '../lib';
10     }
11 }
12
13 $|  = 1;
14 use warnings;
15 use strict;
16 use Test::More tests => 5;
17
18 BEGIN { use_ok( 'B' ); }
19
20
21 package Testing::Symtable;
22 use vars qw($This @That %wibble $moo %moo);
23 my $not_a_sym = 'moo';
24
25 sub moo { 42 }
26 sub car { 23 }
27
28
29 package Testing::Symtable::Foo;
30 sub yarrow { "Hock" }
31
32 package Testing::Symtable::Bar;
33 sub hock { "yarrow" }
34
35 package main;
36 use vars qw(%Subs);
37 local %Subs = ();
38 B::walksymtable(\%Testing::Symtable::, 'find_syms', sub { $_[0] =~ /Foo/ },
39                 'Testing::Symtable::');
40
41 sub B::GV::find_syms {
42     my($symbol) = @_;
43
44     $main::Subs{$symbol->STASH->NAME . '::' . $symbol->NAME}++;
45 }
46
47 my @syms = map { 'Testing::Symtable::'.$_ } qw(This That wibble moo car
48                                                BEGIN);
49 push @syms, "Testing::Symtable::Foo::yarrow";
50
51 # Make sure we hit all the expected symbols.
52 ok( join('', sort @syms) eq join('', sort keys %Subs), 'all symbols found' );
53
54 # Make sure we only hit them each once.
55 ok( (!grep $_ != 1, values %Subs), '...and found once' );
56
57 # Tests for MAGIC / MOREMAGIC
58 ok( B::svref_2object(\$.)->MAGIC->TYPE eq "\0", '$. has \0 magic' );
59 {
60     my $e = '';
61     local $SIG{__DIE__} = sub { $e = $_[0] };
62     # Used to dump core, bug #16828
63     eval { B::svref_2object(\$.)->MAGIC->MOREMAGIC->TYPE; };
64     like( $e, qr/Can't call method "TYPE" on an undefined value/, 
65         '$. has no more magic' );
66 }