6 use Test::More tests => 12;
14 local $SIG{__WARN__} = sub { push @w, join '', 'warn:', @_ };
15 no autovivification qw/warn fetch/;
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';
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';
37 eval 'no autovivification; use autovivification::TestRequired2; $blurp->{a}';
38 is $@, '', 'second require test doesn\'t croak prematurely';
40 $expect = { r1_main => { }, r1_eval => { } };
41 $expect->{r2_eval} = { } if $] < 5.009005;
42 is_deeply $blurp, $expect, 'second require test didn\'t vivify';
45 # This test may not fail for the old version when ran in taint mode
47 my $err = eval <<' SNIP';
48 use autovivification::TestRequired4::a0;
49 autovivification::TestRequired4::a0::error();
51 is $err, '', 'RT #50570';
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';
63 use autovivification::TestRequired6;
65 autovivification::TestRequired6::bar();
66 is_deeply $blurp, { }, 'vivified without eval';
69 autovivification::TestRequired6::baz();
70 is_deeply $blurp, { }, 'vivified with eval';