#!./perl -w
#
# testsuite for Data::Dumper
#
BEGIN {
chdir 't' if -d 't';
print "1..0 # Skip: Data::Dumper was not built\n";
exit 0;
}
}
}
# Since Perl 5.8.1 because otherwise hash ordering is really random.
use Config;
my $TMAX;
my $XS;
my $TNUM = 0;
my $WANT = '';
my $string = shift;
my $name = shift;
my $t = eval $string;
++$TNUM;
$t =~ s/([A-Z]+)\(0x[0-9a-f]+\)/$1(0xdeadbeef)/g
# these data need massaging with non ascii character sets
# because of hashing order differences
$t =~ s/\,$//mg;
}
++$TNUM;
eval "$t";
$t = eval $string;
++$TNUM;
$t =~ s/([A-Z]+)\(0x[0-9a-f]+\)/$1(0xdeadbeef)/g
# here too there are hashing order differences
$t =~ s/\,$//mg;
}
}
my $reason = shift;
}
# Force Data::Dumper::Dump to use perl. We test Dumpxs explicitly by calling
# it direct. Out here it lets us knobble the next if to test that the perl
# only tests do work (and count correctly)
print "### XS extension loaded, will run XS tests\n";
}
else {
print "### XS extensions not loaded, will NOT run XS tests\n";
}
print "1..$TMAX\n";
#XXXif (0) {
#############
#############
@c = ('c');
$c = \@c;
$b = {};
$a = [1, $b, $c];
$b->{a} = $a;
$b->{b} = $a->[1];
$b->{c} = $a->[2];
############# 1
##
$WANT = <<'EOT';
#$a = [
# 1,
# {
# 'a' => $a,
# 'b' => $a->[1],
# 'c' => [
# 'c'
# ]
# },
# $a->[1]{'c'}
# ];
#$b = $a->[1];
#$c = $a->[1]{'c'};
############# 7
##
$WANT = <<'EOT';
#@a = (
# 1,
# {
# 'a' => [],
# 'b' => {},
# 'c' => [
# 'c'
# ]
# },
# []
# );
#$a[1]{'a'} = \@a;
#$a[1]{'b'} = $a[1];
#$a[2] = $a[1]{'c'};
#$b = $a[1];
############# 13
##
$WANT = <<'EOT';
#%b = (
# 'a' => [
# 1,
# {},
# [
# 'c'
# ]
# ],
# 'b' => {},
# 'c' => []
# );
#$b{'a'}[1] = \%b;
#$b{'b'} = \%b;
#$b{'c'} = $b{'a'}[2];
#$a = $b{'a'};
############# 19
##
$WANT = <<'EOT';
#$a = [
# 1,
# {
# 'a' => [],
# 'b' => {},
# 'c' => []
# },
# []
#];
#$a->[1]{'a'} = $a;
#$a->[1]{'b'} = $a->[1];
#$a->[1]{'c'} = \@c;
#$a->[2] = \@c;
#$b = $a->[1];
TEST q(
$d->Dump;
);
if ($XS) {
TEST q(
$d->Dumpxs;
);
}
############# 25
##
$WANT = <<'EOT';
#$a = [
# #0
# 1,
# #1
# {
# a => $a,
# b => $a->[1],
# c => [
# #0
# 'c'
# ]
# },
# #2
# $a->[1]{c}
# ];
#$b = $a->[1];
$d->Indent(3);
############# 31
##
$WANT = <<'EOT';
#$VAR1 = [
# 1,
# {
# 'a' => [],
# 'b' => {},
# 'c' => [
# 'c'
# ]
# },
# []
#];
#$VAR1->[1]{'a'} = $VAR1;
#$VAR1->[1]{'b'} = $VAR1->[1];
#$VAR1->[2] = $VAR1->[1]{'c'};
############# 37
##
$WANT = <<'EOT';
#[
# 1,
# {
# a => $VAR1,
# b => $VAR1->[1],
# c => [
# 'c'
# ]
# },
# $VAR1->[1]{c}
#]
{
}
############# 43
##
$WANT = <<'EOT';
#$VAR1 = {
# "abc\0'\efg" => "mno\0",
# "reftest" => \\1
#};
"reftest" => \\1,
};
{
}
$WANT = <<"EOT";
#\$VAR1 = {
# 'abc\0\\'\efg' => 'mno\0',
# 'reftest' => \\\\1
#};
{
}
#############
#############
{
$foo = 5;
############# 49
##
#$foo = \*::foo;
#*::foo = \5;
#*::foo = [
# #0
# -10,
# #1
# do{my $o},
# #2
# {
# 'a' => 1,
# 'b' => do{my $o},
# 'c' => [],
# 'd' => {}
# }
# ];
#*::foo{ARRAY}->[1] = $foo;
#*::foo{ARRAY}->[2]{'b'} = *::foo{SCALAR};
#*::foo{ARRAY}->[2]{'c'} = *::foo{ARRAY};
#*::foo{ARRAY}->[2]{'d'} = *::foo{ARRAY}->[2];
#*::foo = *::foo{ARRAY}->[2];
#@bar = @{*::foo{ARRAY}};
#%baz = %{*::foo{ARRAY}->[2]};
############# 55
##
#$foo = \*::foo;
#*::foo = \5;
#*::foo = [
# -10,
# do{my $o},
# {
# 'a' => 1,
# 'b' => do{my $o},
# 'c' => [],
# 'd' => {}
# }
#];
#*::foo{ARRAY}->[1] = $foo;
#*::foo{ARRAY}->[2]{'b'} = *::foo{SCALAR};
#*::foo{ARRAY}->[2]{'c'} = *::foo{ARRAY};
#*::foo{ARRAY}->[2]{'d'} = *::foo{ARRAY}->[2];
#*::foo = *::foo{ARRAY}->[2];
#$bar = *::foo{ARRAY};
#$baz = *::foo{ARRAY}->[2];
############# 61
##
#@bar = (
# -10,
# \*::foo,
# {}
#);
#*::foo = \5;
#*::foo = \@bar;
#*::foo = {
# 'a' => 1,
# 'b' => do{my $o},
# 'c' => [],
# 'd' => {}
#};
#*::foo{HASH}->{'b'} = *::foo{SCALAR};
#*::foo{HASH}->{'c'} = \@bar;
#*::foo{HASH}->{'d'} = *::foo{HASH};
#$bar[2] = *::foo{HASH};
#%baz = %{*::foo{HASH}};
#$foo = $bar[1];
############# 67
##
#$bar = [
# -10,
# \*::foo,
# {}
#];
#*::foo = \5;
#*::foo = $bar;
#*::foo = {
# 'a' => 1,
# 'b' => do{my $o},
# 'c' => [],
# 'd' => {}
#};
#*::foo{HASH}->{'b'} = *::foo{SCALAR};
#*::foo{HASH}->{'c'} = $bar;
#*::foo{HASH}->{'d'} = *::foo{HASH};
#$bar->[2] = *::foo{HASH};
#$baz = *::foo{HASH};
#$foo = $bar->[1];
############# 73
##
#$foo = \*::foo;
#@bar = (
# -10,
# $foo,
# {
# a => 1,
# b => \5,
# c => \@bar,
# d => $bar[2]
# }
#);
#%baz = %{$bar[2]};
############# 79
##
#$foo = \*::foo;
#$bar = [
# -10,
# $foo,
# {
# a => 1,
# b => \5,
# c => $bar,
# d => $bar->[2]
# }
#];
#$baz = $bar->[2];
}
#############
#############
{
%kennel = (
);
############# 85
##
#%kennels = (
# First => \'Fido',
# Second => \'Wags'
#);
#@dogs = (
# ${$kennels{First}},
# ${$kennels{Second}},
# \%kennels
#);
#%mutts = %kennels;
TEST q(
$d->Dump;
);
TEST q(
$d->Dumpxs;
);
}
############# 91
##
#%kennels = %kennels;
#@dogs = @dogs;
#%mutts = %kennels;
############# 97
##
#%kennels = (
# First => \'Fido',
# Second => \'Wags'
#);
#@dogs = (
# ${$kennels{First}},
# ${$kennels{Second}},
# \%kennels
#);
#%mutts = %kennels;
}
############# 103
##
#@dogs = (
# 'Fido',
# 'Wags',
# {
# First => \$dogs[0],
# Second => \$dogs[1]
# }
#);
#%kennels = %{$dogs[2]};
#%mutts = %{$dogs[2]};
TEST q(
$d->Dump;
);
TEST q(
$d->Dumpxs;
);
}
############# 109
##
}
############# 115
##
#@dogs = (
# 'Fido',
# 'Wags',
# {
# First => \'Fido',
# Second => \'Wags'
# }
#);
#%kennels = (
# First => \'Fido',
# Second => \'Wags'
#);
TEST q(
);
}
}
{
sub z { print "foo\n" }
$c = [ \&z ];
############# 121
##
#$a = $b;
#$c = [
# $b
#];
if $XS;
############# 127
##
#$a = \&b;
#$c = [
# \&b
#];
if $XS;
############# 133
##
#*a = \&b;
#@c = (
# \&b
#);
if $XS;
}
{
$a = [];
$a->[1] = \$a->[0];
############# 139
##
#@a = (
# undef,
# do{my $o}
#);
#$a[1] = \$a[0];
if $XS;
}
{
$a = \\\\\'foo';
$b = $$$a;
############# 145
##
#$a = \\\\\'foo';
#$b = ${${$a}};
if $XS;
}
{
$b = [{ c => \$b }, { d => \$a }];
############# 151
##
#$a = [
# {
# a => \[
# {
# c => do{my $o}
# },
# {
# d => \[]
# }
# ]
# },
# {
# b => undef
# }
#];
#${$a->[0]{a}}->[0]->{c} = $a->[0]{a};
#${${$a->[0]{a}}->[1]->{d}} = $a;
#$b = ${$a->[0]{a}};
if $XS;
}
{
$a = [[[[\\\\\'foo']]]];
$b = $a->[0][0];
$c = $${$b->[0][0]};
############# 157
##
#$a = [
# [
# [
# [
# \\\\\'foo'
# ]
# ]
# ]
#];
#$b = $a->[0][0];
#$c = ${${$a->[0][0][0][0]}};
if $XS;
}
{
$f = "pearl";
$e = [ $f ];
$d = { 'e' => $e };
$c = [ $d ];
$b = { 'c' => $c };
$a = { 'b' => $b };
############# 163
##
#$a = {
# b => {
# c => [
# {
# e => 'ARRAY(0xdeadbeef)'
# }
# ]
# }
#};
#$b = $a->{b};
#$c = $a->{b}{c};
if $XS;
############# 169
##
#$a = {
# b => 'HASH(0xdeadbeef)'
#};
#$b = $a->{b};
#$c = [
# 'HASH(0xdeadbeef)'
#];
if $XS;
}
{
$a = \$a;
$b = [$a];
############# 175
##
#$b = [
# \$b->[0]
#];
if $XS;
############# 181
##
#$b = [
# \do{my $o}
#];
#${$b->[0]} = $b->[0];
if $XS;
}
{
$a = "\x{09c10}";
############# 187
## XS code was adding an extra \0
#$a = "\x{9c10}";
if($] >= 5.007) {
} else {
}
if $XS;
}
{
$i = 0;
############# 193
##
#$VAR1 = {
# III => 1,
# JJJ => 2,
# KKK => 3,
# LLL => 4,
# MMM => 5,
# NNN => 6,
# OOO => 7,
# PPP => 8,
# QQQ => 9
#};
if $XS;
}
{
$i = 5;
sub sort199 {
my $hash = shift;
}
############# 199
##
#$VAR1 = {
# 14 => 'QQQ',
# 13 => 'PPP',
# 12 => 'OOO',
# 11 => 'NNN',
# 10 => 'MMM',
# 9 => 'LLL',
# 8 => 'KKK',
# 7 => 'JJJ',
# 6 => 'III'
#};
# perl code does keys and values as numbers if possible
# XS code always does them as strings
if $XS;
}
{
$i = 5;
$d = { reverse %$c };
sub sort205 {
my $hash = shift;
return [
];
}
############# 205
##
#$VAR1 = [
# {
# 6 => 'III',
# 7 => 'JJJ',
# 8 => 'KKK',
# 9 => 'LLL',
# 10 => 'MMM',
# 11 => 'NNN',
# 12 => 'OOO',
# 13 => 'PPP',
# 14 => 'QQQ'
# },
# {
# QQQ => 14,
# PPP => 13,
# OOO => 12,
# NNN => 11,
# MMM => 10,
# LLL => 9,
# KKK => 8,
# JJJ => 7,
# III => 6
# }
#];
if $XS;
}
{
############# 211
##
#$VAR1 = {
# foo => sub {
# print 'foo';
# }
# };
}
############# 214
##
# This is messy.
# The controls (bare numbers) are stored either as integers or floating point.
# [depending on whether the tokeniser sees things like ".".
# The peephole optimiser only runs for constant folding, not single constants,
# so I already have some NVs, some IVs
# The string versions are not. They are all PV
# This is arguably all far too chummy with the implementation, but I really
# want to ensure that we don't go wrong when flags on scalars get as side
# effects of reading them.
# These tests are actually testing the precise output of the current
# implementation, so will most likely fail if the implementation changes,
# even if the new implementation produces different but correct results.
# It would be nice to test for wrong answers, but I can't see how to do that,
# so instead I'm checking for unexpected answers. (ie -2 becoming "-2" is not
# wrong, but I can't see an easy, reliable way to code that knowledge)
# Numbers (seen by the tokeniser as numbers, stored as numbers.
@numbers =
(
0, +1, -2, 3.0, +4.0, -5.0, 6.5, +7.5, -8.5,
9, +10, -11, 12.0, +13.0, -14.0, 15.5, +16.25, -17.75,
);
# Strings
@strings =
(
"0", "+1", "-2", "3.0", "+4.0", "-5.0", "6.5", "+7.5", "-8.5", " 9",
" +10", " -11", " 12.0", " +13.0", " -14.0", " 15.5", " +16.25", " -17.75",
);
# The perl code always does things the same way for numbers.
#$VAR1 = 0;
#$VAR2 = 1;
#$VAR3 = -2;
#$VAR4 = 3;
#$VAR5 = 4;
#$VAR6 = -5;
#$VAR7 = '6.5';
#$VAR8 = '7.5';
#$VAR9 = '-8.5';
#$VAR10 = 9;
#$VAR11 = 10;
#$VAR12 = -11;
#$VAR13 = 12;
#$VAR14 = 13;
#$VAR15 = -14;
#$VAR16 = '15.5';
#$VAR17 = '16.25';
#$VAR18 = '-17.75';
# The perl code knows that 0 and -2 stringify exactly back to the strings,
# so it dumps them as numbers, not strings.
#$VAR1 = 0;
#$VAR2 = '+1';
#$VAR3 = -2;
#$VAR4 = '3.0';
#$VAR5 = '+4.0';
#$VAR6 = '-5.0';
#$VAR7 = '6.5';
#$VAR8 = '+7.5';
#$VAR9 = '-8.5';
#$VAR10 = ' 9';
#$VAR11 = ' +10';
#$VAR12 = ' -11';
#$VAR13 = ' 12.0';
#$VAR14 = ' +13.0';
#$VAR15 = ' -14.0';
#$VAR16 = ' 15.5';
#$VAR17 = ' +16.25';
#$VAR18 = ' -17.75';
# The XS code differs.
# These are the numbers as seen by the tokeniser. Constants aren't folded
# (which makes IVs where possible) so values the tokeniser thought were
# floating point are stored as NVs. The XS code outputs these as strings,
# but as it has converted them from NVs, leading + signs will not be there.
#$VAR1 = 0;
#$VAR2 = 1;
#$VAR3 = -2;
#$VAR4 = '3';
#$VAR5 = '4';
#$VAR6 = '-5';
#$VAR7 = '6.5';
#$VAR8 = '7.5';
#$VAR9 = '-8.5';
#$VAR10 = 9;
#$VAR11 = 10;
#$VAR12 = -11;
#$VAR13 = '12';
#$VAR14 = '13';
#$VAR15 = '-14';
#$VAR16 = '15.5';
#$VAR17 = '16.25';
#$VAR18 = '-17.75';
# These are the strings as seen by the tokeniser. The XS code will output
# these for all cases except where the scalar has been used in integer context
#$VAR1 = '0';
#$VAR2 = '+1';
#$VAR3 = '-2';
#$VAR4 = '3.0';
#$VAR5 = '+4.0';
#$VAR6 = '-5.0';
#$VAR7 = '6.5';
#$VAR8 = '+7.5';
#$VAR9 = '-8.5';
#$VAR10 = ' 9';
#$VAR11 = ' +10';
#$VAR12 = ' -11';
#$VAR13 = ' 12.0';
#$VAR14 = ' +13.0';
#$VAR15 = ' -14.0';
#$VAR16 = ' 15.5';
#$VAR17 = ' +16.25';
#$VAR18 = ' -17.75';
# These are the numbers as IV-ized by &
# These will differ from WANT_XS_N because now IV flags will be set on all
# values that were actually integer, and the XS code will then output these
# as numbers not strings.
#$VAR1 = 0;
#$VAR2 = 1;
#$VAR3 = -2;
#$VAR4 = 3;
#$VAR5 = 4;
#$VAR6 = -5;
#$VAR7 = '6.5';
#$VAR8 = '7.5';
#$VAR9 = '-8.5';
#$VAR10 = 9;
#$VAR11 = 10;
#$VAR12 = -11;
#$VAR13 = 12;
#$VAR14 = 13;
#$VAR15 = -14;
#$VAR16 = '15.5';
#$VAR17 = '16.25';
#$VAR18 = '-17.75';
# Some of these tests will be redundant.
@numbers_s = @numbers_i = @numbers_is = @numbers_n = @numbers_ns = @numbers_ni
= @numbers_nis = @numbers;
@strings_s = @strings_i = @strings_is = @strings_n = @strings_ns = @strings_ni
= @strings_nis = @strings;
# Use them in an integer context
foreach (@numbers_i, @numbers_ni, @numbers_nis, @numbers_is,
}
# Use them in a floating point context
foreach (@numbers_n, @numbers_ni, @numbers_nis, @numbers_ns,
}
# Use them in a string context
foreach (@numbers_s, @numbers_is, @numbers_nis, @numbers_ns,
}
# use Devel::Peek; Dump ($_) foreach @vanilla_c;
# This one used to really mess up. New code actually emulates the .pm code
# This one used to really mess up. New code actually emulates the .pm code
}
{
$a = "1\n";
############# 310
## Perl code was using /...$/ and hence missing the \n.
my $VAR1 = '42
';
# Can't pad with # as the output has an embedded newline.
if $XS;
}
{
@a = (
999999999,
1000000000,
9999999999,
10000000000,
-999999999,
-1000000000,
-9999999999,
-10000000000,
4294967295,
4294967296,
-2147483648,
-2147483649,
);
############# 316
## Perl code flips over at 10 digits.
#$VAR1 = 999999999;
#$VAR2 = '1000000000';
#$VAR3 = '9999999999';
#$VAR4 = '10000000000';
#$VAR5 = -999999999;
#$VAR6 = '-1000000000';
#$VAR7 = '-9999999999';
#$VAR8 = '-10000000000';
#$VAR9 = '4294967295';
#$VAR10 = '4294967296';
#$VAR11 = '-2147483648';
#$VAR12 = '-2147483649';
## XS code flips over at 11 characters ("-" is a char) or larger than int.
if (~0 == 0xFFFFFFFF) {
# 32 bit system
#$VAR1 = 999999999;
#$VAR2 = 1000000000;
#$VAR3 = '9999999999';
#$VAR4 = '10000000000';
#$VAR5 = -999999999;
#$VAR6 = '-1000000000';
#$VAR7 = '-9999999999';
#$VAR8 = '-10000000000';
#$VAR9 = 4294967295;
#$VAR10 = '4294967296';
#$VAR11 = '-2147483648';
#$VAR12 = '-2147483649';
} else {
#$VAR1 = 999999999;
#$VAR2 = 1000000000;
#$VAR3 = 9999999999;
#$VAR4 = '10000000000';
#$VAR5 = -999999999;
#$VAR6 = '-1000000000';
#$VAR7 = '-9999999999';
#$VAR8 = '-10000000000';
#$VAR9 = 4294967295;
#$VAR10 = 4294967296;
#$VAR11 = '-2147483648';
#$VAR12 = '-2147483649';
}
}
}
#XXX}
{
$b = "Bad. XS didn't escape dollar sign";
############# 322
#\$VAR1 = '\$b\"\@\\\\\xA3';
$a = "\$b\"\@\\\xA3\x{100}";
chop $a;
#$VAR1 = "\$b\"\@\\\x{a3}";
}
# XS used to produce "$b\"' which is 4 chars, not 3. [ie wrongly qq(\$b\\\")]
############# 328
#$VAR1 = '$b"';
$a = "\$b\"\x{100}";
chop $a;
}
# XS used to produce 'D'oh!' which is well, D'oh!
# Andreas found this one, which in turn discovered the previous two.
############# 334
#$VAR1 = 'D\'oh!';
$a = "D'oh!\x{100}";
chop $a;
}
}
# Jarkko found that -Mutf8 caused some tests to fail. Turns out that there
# was an otherwise untested code path in the XS for utf8 hash keys with purity
# 1
{
#$ping = \*::ping;
#*::ping = \5;
#*::ping = {
# "\x{decaf}\x{decaf}\x{decaf}\x{decaf}" => do{my $o}
#};
#*::ping{HASH}->{"\x{decaf}\x{decaf}\x{decaf}\x{decaf}"} = *::ping{SCALAR};
#%pong = %{*::ping{HASH}};
$ping = 5;
if($] >= 5.007) {
} else {
}
}
}
# XS for quotekeys==0 was not being defensive enough against utf8 flagged
# scalars
{
#$VAR1 = {
# perl => 'rocks'
#};
chop $k;
}
############# 358
{
#$VAR1 = [
# undef,
# undef,
# 1
#];
$foo[2] = 1;
TEST q(Data::Dumper->Dump([\@foo])), 'Richard Clamp, Message-Id: <20030104005247.GA27685@mirth.demon.co.uk>';
}