chdir 't' if -d 't';
@INC = '../lib';
require './test.pl';
- plan( tests => 48 );
+ plan( tests => 78 );
}
my @c;
# See if caller() returns the correct warning mask
+sub show_bits
+{
+ my $in = shift;
+ my $out = '';
+ foreach (unpack('W*', $in)) {
+ $out .= sprintf('\x%02x', $_);
+ }
+ return $out;
+}
+
+sub check_bits
+{
+ local $Level = $Level + 2;
+ my ($got, $exp, $desc) = @_;
+ if (! ok($got eq $exp, $desc)) {
+ diag(' got: ' . show_bits($got));
+ diag('expected: ' . show_bits($exp));
+ }
+}
+
sub testwarn {
my $w = shift;
- is( (caller(0))[9], $w, "warnings match caller");
+ my $id = shift;
+ check_bits( (caller(0))[9], $w, "warnings match caller ($id)");
}
-# NB : extend the warning mask values below when new warnings are added
{
no warnings;
- BEGIN { is( ${^WARNING_BITS}, "\0" x 12, 'all bits off via "no warnings"' ) }
- testwarn("\0" x 12);
+ # Build the warnings mask dynamically
+ my ($default, $registered);
+ BEGIN {
+ for my $i (0..$warnings::LAST_BIT/2 - 1) {
+ vec($default, $i, 2) = 1;
+ }
+ $registered = $default;
+ vec($registered, $warnings::LAST_BIT/2, 2) = 1;
+ }
+ BEGIN { check_bits( ${^WARNING_BITS}, "\0" x 12, 'all bits off via "no warnings"' ) }
+ testwarn("\0" x 12, 'no bits');
use warnings;
- BEGIN { is( ${^WARNING_BITS}, "UUUUUUUUUUU\025", 'default bits on via "use warnings"' ); }
- BEGIN { testwarn("UUUUUUUUUUU\025", "#1"); }
+ BEGIN { check_bits( ${^WARNING_BITS}, $default,
+ 'default bits on via "use warnings"' ); }
+ BEGIN { testwarn($default, 'all'); }
# run-time :
# the warning mask has been extended by warnings::register
- testwarn("UUUUUUUUUUUU");
+ testwarn($registered, 'ahead of w::r');
use warnings::register;
- BEGIN { is( ${^WARNING_BITS}, "UUUUUUUUUUUU", 'warning bits on via "use warnings::register"' ) }
- testwarn("UUUUUUUUUUUU","#3");
+ BEGIN { check_bits( ${^WARNING_BITS}, $registered,
+ 'warning bits on via "use warnings::register"' ) }
+ testwarn($registered, 'following w::r');
}
is( $i, 11, 'do not skip over eval even if $^P had been on at some point' );
is( eval 'pb()', 'main::pb', 'actually return the right function name even if $^P had been on at some point' );
-# caller can now return the compile time state of %^H
-sub get_dooot {
+print "# caller can now return the compile time state of %^H\n";
+
+sub hint_exists {
+ my $key = shift;
my $level = shift;
my @results = caller($level||0);
- $results[10]->{dooot};
+ exists $results[10]->{$key};
}
-sub get_hash {
+
+sub hint_fetch {
+ my $key = shift;
my $level = shift;
my @results = caller($level||0);
- $results[10];
+ $results[10]->{$key};
}
-sub dooot {
- is(get_dooot(), undef);
- my $hash = get_hash();
- ok(!exists $hash->{dooot});
- is(get_dooot(1), 54);
- BEGIN {
- $^H{dooot} = 42;
- }
- is(get_dooot(), 6 * 7);
- is(get_dooot(1), 54);
- BEGIN {
- $^H{dooot} = undef;
- }
- is(get_dooot(), undef);
- $hash = get_hash();
- ok(exists $hash->{dooot});
-
- BEGIN {
- delete $^H{dooot};
- }
- is(get_dooot(), undef);
- $hash = get_hash();
- ok(!exists $hash->{dooot});
- is(get_dooot(1), 54);
-}
-{
- is(get_dooot(), undef);
- BEGIN {
- $^H{dooot} = 1;
- }
- is(get_dooot(), 1);
+$::testing_caller = 1;
- BEGIN {
- $^H{dooot} = 42;
- }
- {
- {
- BEGIN {
- $^H{dooot} = 6 * 9;
- }
- is(get_dooot(), 54);
- {
- BEGIN {
- delete $^H{dooot};
- }
- is(get_dooot(), undef);
- my $hash = get_hash();
- ok(!exists $hash->{dooot});
- }
- dooot();
- }
- is(get_dooot(), 6 * 7);
- }
- is(get_dooot(), 6 * 7);
-}
+do './op/caller.pl' or die $@;