From: Nicholas Clark Date: Thu, 17 Jan 2008 11:31:38 +0000 (+0000) Subject: Generate the warnings masks programatically. X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=ac27d13b824657b726428f3a6a1d5b3a01df569e;p=p5sagit%2Fp5-mst-13.2.git Generate the warnings masks programatically. Get the correct line number when reporting errors from &check_bits. p4raw-id: //depot/perl@32988 --- diff --git a/t/op/caller.t b/t/op/caller.t index fe2c53b..67992f1 100644 --- a/t/op/caller.t +++ b/t/op/caller.t @@ -77,6 +77,7 @@ sub show_bits sub check_bits { + local $Level = $Level + 2; my ($got, $exp, $desc) = @_; if (! ok($got eq $exp, $desc)) { diag(' got: ' . show_bits($got)); @@ -90,22 +91,32 @@ sub testwarn { check_bits( (caller(0))[9], $w, "warnings match caller ($id)"); } -# NB : extend the warning mask values below when new warnings are added { no warnings; + # 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 { 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'); } + 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("\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x15", 'ahead of w::r'); + testwarn($registered, 'ahead of w::r'); use warnings::register; - 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'); + BEGIN { check_bits( ${^WARNING_BITS}, $registered, + 'warning bits on via "use warnings::register"' ) } + testwarn($registered, 'following w::r'); }