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