3 # test a few problems with the Freezer option, not a complete Freezer
7 require Config; import Config;
9 if ($Config{'extensions'} !~ /\bData\/Dumper\b/) {
10 print "1..0 # Skip: Data::Dumper was not built\n";
16 use Test::More qw(no_plan);
18 $Data::Dumper::Freezer = 'freeze';
20 # test for seg-fault bug when freeze() returns a non-ref
21 my $foo = Test1->new("foo");
22 my $dumped_foo = Dumper($foo);
24 "Use of freezer sub which returns non-ref worked.");
25 like($dumped_foo, qr/frozed/,
26 "Dumped string has the key added by Freezer.");
28 # run the same tests with useperl. this always worked
30 local $Data::Dumper::Useperl = 1;
31 my $foo = Test1->new("foo");
32 my $dumped_foo = Dumper($foo);
34 "Use of freezer sub which returns non-ref worked with useperl");
35 like($dumped_foo, qr/frozed/,
36 "Dumped string has the key added by Freezer with useperl.");
39 # test for warning when an object doesn't have a freeze()
42 local $SIG{__WARN__} = sub { $warned++ };
43 my $bar = Test2->new("bar");
44 my $dumped_bar = Dumper($bar);
45 is($warned, 0, "A missing freeze() shouldn't warn.");
49 # run the same test with useperl, which always worked
51 local $Data::Dumper::Useperl = 1;
53 local $SIG{__WARN__} = sub { $warned++ };
54 my $bar = Test2->new("bar");
55 my $dumped_bar = Dumper($bar);
56 is($warned, 0, "A missing freeze() shouldn't warn with useperl");
59 # a freeze() which die()s should still trigger the warning
62 local $SIG{__WARN__} = sub { $warned++; };
63 my $bar = Test3->new("bar");
64 my $dumped_bar = Dumper($bar);
65 is($warned, 1, "A freeze() which die()s should warn.");
68 # the same should work in useperl
70 local $Data::Dumper::Useperl = 1;
72 local $SIG{__WARN__} = sub { $warned++; };
73 my $bar = Test3->new("bar");
74 my $dumped_bar = Dumper($bar);
75 is($warned, 1, "A freeze() which die()s should warn with useperl.");
78 # a package with a freeze() which returns a non-ref
80 sub new { bless({name => $_[1]}, $_[0]) }
86 # a package without a freeze()
88 sub new { bless({name => $_[1]}, $_[0]) }
90 # a package with a freeze() which dies
92 sub new { bless({name => $_[1]}, $_[0]) }
93 sub freeze { die "freeze() is broked" }