]> git.vpit.fr Git - perl/modules/autovivification.git/blob - t/40-scope.t
Remove trailing whitespace
[perl/modules/autovivification.git] / t / 40-scope.t
1 #!perl
2
3 use strict;
4 use warnings;
5
6 use Test::More tests => 12;
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 }
44
45 # This test may not fail for the old version when ran in taint mode
46 {
47  my $err = eval <<' SNIP';
48   use autovivification::TestRequired4::a0;
49   autovivification::TestRequired4::a0::error();
50  SNIP
51  is $err, '', 'RT #50570';
52 }
53
54 # This test must be in the topmost scope
55 BEGIN { eval 'use autovivification::TestRequired5::a0' }
56 my $err = autovivification::TestRequired5::a0::error();
57 is $err, '', 'identifying requires by their eval context pointer is not enough';
58
59 {
60  local $blurp;
61
62  no autovivification;
63  use autovivification::TestRequired6;
64
65  autovivification::TestRequired6::bar();
66  is_deeply $blurp, { }, 'vivified without eval';
67
68  $blurp = undef;
69  autovivification::TestRequired6::baz();
70  is_deeply $blurp, { }, 'vivified with eval';
71 }