de-tabify
[p5sagit/Eval-WithLexicals.git] / t / hints.t
CommitLineData
8d732f30 1use strictures 1;
2# Find the hint value that 'use strictures 1' sets on this perl.
3my $strictures_hints;
4BEGIN { $strictures_hints = $^H }
5
6use Test::More;
7use Eval::WithLexicals;
8
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
31is_deeply(
32 $eval->hints->{q{$^H}}, \$strictures_hints,
33 'Hints are set per strictures'
34);
35
36is_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' } }),
44ok !exists $eval->hints->{q{%^H}}->{sort},
45 "Lexical pragma used below main scope not captured";
46
47$eval->eval(q{ use sort 'stable' }),
48ok exists $eval->hints->{q{%^H}}->{sort},
49 "Lexical pragma captured";
50
51done_testing;