]> git.vpit.fr Git - perl/modules/autovivification.git/blob - t/40-scope.t
Rename tests
[perl/modules/autovivification.git] / t / 40-scope.t
1 #!perl -T
2
3 use strict;
4 use warnings;
5
6 use Test::More tests => 8;
7
8 use lib 't/lib';
9
10 {
11  my @w;
12  my $x;
13  my $res = eval {
14   local $SIG{__WARN__} = sub { push @w, join '', 'warn:', @_ };
15   no autovivification qw/warn fetch/;
16   $x->{a};
17  };
18  is   @w,    1,     'warned only once';
19  like $w[0], qr/^warn:Reference was vivified at \Q$0\E line ${\(__LINE__-3)}/,
20                         'warning looks correct';
21  is_deeply $x,   undef, 'didn\'t vivified';
22  is        $res, undef, 'returned undef';
23 }
24
25 our $blurp;
26
27 {
28  local $blurp;
29  eval 'no autovivification; use autovivification::TestRequired1; $blurp->{x}';
30  is        $@,     '',          'first require test doesn\'t croak prematurely';
31  is_deeply $blurp, { r1_main => { }, r1_eval => { } },
32                                 'first require vivified correctly';
33 }
34
35 {
36  local $blurp;
37  eval 'no autovivification; use autovivification::TestRequired2; $blurp->{a}'; 
38  is        $@,     '',      'second require test doesn\'t croak prematurely';
39  my $expect;
40  $expect = { r1_main => { }, r1_eval => { } };
41  $expect->{r2_eval} = { } if $] <  5.009005;
42  is_deeply $blurp, $expect, 'second require test didn\'t vivify';
43 }