X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=p5sagit%2FEval-WithLexicals.git;a=blobdiff_plain;f=t%2Fhints.t;h=8d30d786893a81a4acf2f177583a4d6bf6b6091d;hp=88bbec36f6719486a119091c4b334a525f7b695b;hb=52ec47288bfbf9d8f6d9798d13b023af3fe7cdc0;hpb=c97f63974c1d1d0b422306ab24391fd256cbeceb diff --git a/t/hints.t b/t/hints.t index 88bbec3..8d30d78 100644 --- a/t/hints.t +++ b/t/hints.t @@ -24,8 +24,9 @@ $eval->eval('use strictures 1'); { local $SIG{__WARN__} = sub { }; - ok !eval { $eval->eval('$x') }, 'Unable to use undeclared variable'; - like $@, qr/requires explicit package/, 'Correct message in $@'; + ok !eval { $eval->eval('${"x"}') }, 'Unable to use undeclared variable'; + like $@, qr/Can't use string .* as a SCALAR ref/, + 'Correct message in $@'; } is( @@ -34,10 +35,45 @@ is( ); is( - (unpack "H*", ${$eval->hints->{q{${^WARNING_BITS}}}}), + (unpack "H*", ${ $eval->hints->{'${^WARNING_BITS}'} }), (unpack "H*", $strictures_warn), 'Warning bits are set per strictures' -); +) or do { + my @cats = + map { + [ $_ => $warnings::Bits{$_} ], + [ "fatal $_" => $warnings::DeadBits{$_} ], + } + grep $_ ne 'all', + keys %warnings::Bits; + + my %info; + for my $check ( + [ missing => $strictures_warn ], + [ extra => ${ $eval->hints->{'${^WARNING_BITS}'} } ], + ) { + my $bits = $check->[1]; + $info{$check->[0]} = { + map { ($bits & $_->[1]) =~ /[^\0]/ ? ( $_->[0] => 1 ) : () } + @cats + }; + } + + { + my @extra = keys %{$info{extra}}; + my @missing = keys %{$info{missing}}; + delete @{$info{missing}}{ @extra }; + delete @{$info{extra}}{ @missing }; + } + + for my $type (qw(missing extra)) { + my @found = grep $info{$type}{$_}, map $_->[0], @cats; + diag "$type:" + if @found; + diag " $_" + for @found; + } +}; is_deeply( $eval->lexicals, { }, @@ -53,4 +89,10 @@ $eval->eval(q{ use hint_hash_pragma 'param' }), is $eval->hints->{q{%^H}}->{hint_hash_pragma}, 'param', "Lexical pragma captured"; +$eval->eval('my $x = 1'); +is_deeply( + $eval->lexicals->{'$x'}, \1, + 'Lexical captured when preserving hints', +); + done_testing;