This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Data::Dumper test compatibility fixes for older Perls
[perl5.git] / dist / Data-Dumper / t / bless.t
1 #!perl
2
3 use Test::More 0.60;
4
5 # Test::More 0.60 required because:
6 # - is_deeply(undef, $not_undef); now works. [rt.cpan.org 9441]
7
8 BEGIN { plan tests => 1+2*5; }
9
10 BEGIN { use_ok('Data::Dumper') };
11
12 # RT 39420: Data::Dumper fails to escape bless class name
13
14 run_tests_for_bless();
15 SKIP: {
16     skip "XS version was unavailable, so we already ran with pure Perl", 5
17         if $Data::Dumper::Useperl;
18     local $Data::Dumper::Useperl = 1;
19     run_tests_for_bless();
20 }
21
22 sub run_tests_for_bless {
23 note("\$Data::Dumper::Useperl = $Data::Dumper::Useperl");
24
25 {
26 my $t = bless( {}, q{a'b} );
27 my $dt = Dumper($t);
28 my $o = <<'PERL';
29 $VAR1 = bless( {}, 'a\'b' );
30 PERL
31
32 is($dt, $o, "package name in bless is escaped if needed");
33 is_deeply(scalar eval($dt), $t, "eval reverts dump");
34 }
35
36 {
37 my $t = bless( {}, q{a\\} );
38 my $dt = Dumper($t);
39 my $o = <<'PERL';
40 $VAR1 = bless( {}, 'a\\' );
41 PERL
42
43 is($dt, $o, "package name in bless is escaped if needed");
44 is_deeply(scalar eval($dt), $t, "eval reverts dump");
45 }
46 SKIP: {
47     skip(q/no 're::regexp_pattern'/, 1)
48         if ! defined(*re::regexp_pattern{CODE});
49
50 my $t = bless( qr//, 'foo');
51 my $dt = Dumper($t);
52 my $o = ($] >= 5.013006 ? <<'PERL' : <<'PERL_LEGACY');
53 $VAR1 = bless( qr/(?^:)/, 'foo' );
54 PERL
55 $VAR1 = bless( qr/(?-xism:)/, 'foo' );
56 PERL_LEGACY
57
58 is($dt, $o, "We can dump blessed qr//'s properly");
59
60 }
61
62 } # END sub run_tests_for_bless()