use our own pragma for hints hash test
[p5sagit/Eval-WithLexicals.git] / t / hints.t
CommitLineData
2b376bd0 1use strictures ();
8d732f30 2my $strictures_hints;
2b376bd0 3BEGIN {
4 local $ENV{PERL_STRICTURES_EXTRA} = 0;
5 strictures->VERSION(1); strictures->import();
6 # Find the hint value that 'use strictures 1' sets on this perl.
7 $strictures_hints = $^H;
8}
9use strictures 1;
8d732f30 10
11use Test::More;
12use Eval::WithLexicals;
9661a07c 13use lib 't/lib';
8d732f30 14
15my $eval = Eval::WithLexicals->with_plugins("HintPersistence")->new(prelude => '');
16
17is_deeply(
18 [ $eval->eval('$x = 1') ],
19 [ 1 ],
20 'Basic non-strict eval ok'
21);
22
23is_deeply(
24 $eval->lexicals, { },
25 'Lexical not stored'
26);
27
28$eval->eval('use strictures 1');
29
30{
31 local $SIG{__WARN__} = sub { };
32
33 ok !eval { $eval->eval('$x') }, 'Unable to use undeclared variable';
34 like $@, qr/requires explicit package/, 'Correct message in $@';
35}
36
37is_deeply(
38 $eval->hints->{q{$^H}}, \$strictures_hints,
39 'Hints are set per strictures'
40);
41
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;