chdir 't' if -d 't';
@INC = '../lib';
require './test.pl';
- plan( tests => 65 );
+ 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
+{
+ 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);
+ 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}, "\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x05", 'default bits on via "use warnings"' ); }
+ BEGIN { testwarn("\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x05", 'all'); }
# run-time :
# the warning mask has been extended by warnings::register
- testwarn("UUUUUUUUUUUU");
+ testwarn("\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x15", '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}, "\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x15", 'warning bits on via "use warnings::register"' ) }
+ testwarn("\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x15", 'following w::r');
}
print "# caller can now return the compile time state of %^H\n";
-sub get_hash {
- my $level = shift;
- my @results = caller($level||0);
- $results[10];
-}
-
-sub get_dooot {
+sub hint_exists {
+ my $key = shift;
my $level = shift;
my @results = caller($level||0);
- $results[10]->{dooot};
+ exists $results[10]->{$key};
}
-sub get_thikoosh {
+sub hint_fetch {
+ my $key = shift;
my $level = shift;
my @results = caller($level||0);
- $results[10]->{thikoosh};
+ $results[10]->{$key};
}
-sub dooot {
- is(get_dooot(), undef);
- is(get_thikoosh(), undef);
- my $hash = get_hash();
- ok(!exists $hash->{dooot});
- ok(!exists $hash->{thikoosh});
- is(get_dooot(1), 54);
- BEGIN {
- $^H{dooot} = 42;
- }
- is(get_dooot(), 6 * 7);
- is(get_dooot(1), 54);
+$::testing_caller = 1;
- 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);
- is(get_thikoosh(), undef);
- BEGIN {
- $^H{dooot} = 1;
- $^H{thikoosh} = "SKREECH";
- }
- is(get_dooot(), 1);
- is(get_thikoosh(), "SKREECH");
-
- BEGIN {
- $^H{dooot} = 42;
- }
- {
- {
- BEGIN {
- $^H{dooot} = 6 * 9;
- }
- is(get_dooot(), 54);
- is(get_thikoosh(), "SKREECH");
- {
- BEGIN {
- delete $^H{dooot};
- }
- is(get_dooot(), undef);
- my $hash = get_hash();
- ok(!exists $hash->{dooot});
- is(get_thikoosh(), "SKREECH");
- }
- dooot();
- }
- is(get_dooot(), 6 * 7);
- is(get_thikoosh(), "SKREECH");
- }
- is(get_dooot(), 6 * 7);
- is(get_thikoosh(), "SKREECH");
-}
-
-print "# which now works inside evals\n";
-
-{
- BEGIN {
- $^H{dooot} = 42;
- }
- is(get_dooot(), 6 * 7);
-
- eval "is(get_dooot(), 6 * 7); 1" or die $@;
-
- eval <<'EOE' or die $@;
- is(get_dooot(), 6 * 7);
- eval "is(get_dooot(), 6 * 7); 1" or die $@;
- BEGIN {
- $^H{dooot} = 54;
- }
- is(get_dooot(), 54);
- eval "is(get_dooot(), 54); 1" or die $@;
- eval 'BEGIN { $^H{dooot} = -1; }; 1' or die $@;
- is(get_dooot(), 54);
- eval "is(get_dooot(), 54); 1" or die $@;
-EOE
-}
-
-{
- BEGIN {
- $^H{dooot} = "FIP\0FOP\0FIDDIT\0FAP";
- }
- is(get_dooot(), "FIP\0FOP\0FIDDIT\0FAP", "Can do embedded 0 bytes");
-}
+do './op/caller.pl' or die $@;