make hints test immune to perl -M options
[p5sagit/Eval-WithLexicals.git] / t / hints.t
CommitLineData
2b376bd0 1use strictures ();
8d732f30 2use Test::More;
3use Eval::WithLexicals;
9661a07c 4use lib 't/lib';
8d732f30 5
14786ff8 6use strictures 1;
c97f6397 7use get_strictures_hints qw($strictures_hints $strictures_warn);
14786ff8 8
8d732f30 9my $eval = Eval::WithLexicals->with_plugins("HintPersistence")->new(prelude => '');
10
11is_deeply(
12 [ $eval->eval('$x = 1') ],
13 [ 1 ],
14 'Basic non-strict eval ok'
15);
16
17is_deeply(
18 $eval->lexicals, { },
19 'Lexical not stored'
20);
21
22$eval->eval('use strictures 1');
23
24{
25 local $SIG{__WARN__} = sub { };
26
27 ok !eval { $eval->eval('$x') }, 'Unable to use undeclared variable';
28 like $@, qr/requires explicit package/, 'Correct message in $@';
29}
30
14786ff8 31is(
32 ${$eval->hints->{q{$^H}}}, $strictures_hints,
8d732f30 33 'Hints are set per strictures'
34);
35
14786ff8 36is(
37 (unpack "H*", ${$eval->hints->{q{${^WARNING_BITS}}}}),
38 (unpack "H*", $strictures_warn),
39 'Warning bits are set per strictures'
40);
41
8d732f30 42is_deeply(
43 $eval->lexicals, { },
44 'Lexical not stored'
45);
46
47# Assumption about perl internals: sort pragma will set a key in %^H.
9661a07c 48$eval->eval(q{ { use hint_hash_pragma 'param' } }),
49ok !exists $eval->hints->{q{%^H}}->{hint_hash_pragma},
8d732f30 50 "Lexical pragma used below main scope not captured";
51
9661a07c 52$eval->eval(q{ use hint_hash_pragma 'param' }),
53is $eval->hints->{q{%^H}}->{hint_hash_pragma}, 'param',
8d732f30 54 "Lexical pragma captured";
55
56done_testing;