pod cleanups
[p5sagit/Eval-WithLexicals.git] / t / hints.t
1 use strictures 1;
2 # Find the hint value that 'use strictures 1' sets on this perl.
3 my $strictures_hints;
4 BEGIN { $strictures_hints = $^H }
5
6 use Test::More;
7 use Eval::WithLexicals;
8
9 my $eval = Eval::WithLexicals->with_plugins("HintPersistence")->new(prelude => '');
10
11 is_deeply(
12   [ $eval->eval('$x = 1') ],
13   [ 1 ],
14   'Basic non-strict eval ok'
15 );
16
17 is_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
31 is_deeply(
32   $eval->hints->{q{$^H}}, \$strictures_hints,
33  'Hints are set per strictures'
34 );
35
36 is_deeply(
37   $eval->lexicals, { },
38   'Lexical not stored'
39 );
40
41 # Assumption about perl internals: sort pragma will set a key in %^H.
42
43 $eval->eval(q{ { use sort 'stable' } }),
44 ok !exists $eval->hints->{q{%^H}}->{sort},
45   "Lexical pragma used below main scope not captured";
46
47 $eval->eval(q{ use sort 'stable' }),
48 ok exists $eval->hints->{q{%^H}}->{sort},
49   "Lexical pragma captured";
50
51 done_testing;