Skip to content

Commit

Permalink
Convert dumper.t to Test::More.
Browse files Browse the repository at this point in the history
Also move the calculation of test count earlier, and remove a prototype
which isn't needed to force correct parsing.

All the other Data::Dumper tests unconditionally assume Test::More, so it's
reasonable for this test to make the same assumption.

Given that we now specify a minimal Perl version of 5.8.1, this doesn't
introduce an external dependency. It seems that the original intent of the
tests were that the pure-perl implementation of Data::Dumper could be used
as a test of/tested with miniperl. However, the ability to load it with
miniperl was lost/broken in Jan 2005 by commit a76739e:
    Fix spurious warnings emitted by XSLoader via Data::Dumper

    p4raw-id: //depot/perl@23851

and no-one has actually noticed this for 15 years. By the time the loader
code was fixed so that miniperl *could* load it, the "pure perl"
Data::Dumper required several routines from Scalar::Util, which (in turn)
won't load with miniperl.

("pure perl" is unfortunately an overloaded concept once one considers
bootstrapping the core. For CPAN "pure perl" means is "the distribution and
all its dependencies on CPAN can be built without a C compiler", which is
useful for constrained environments. But for building the core itself there
is always a C compiler. It's dynamic loading of core's own C extensions that
isn't possible with miniperl, and what matters during the build/when you're
debugging a change that breaks things badly with no obvious cause.)

Hence there is no advantage in constraining Data::Dumper to be testable
without Test::More, because both have the same dependencies.
  • Loading branch information
nwc10 committed May 23, 2021
1 parent 9fb51e1 commit f7397e4
Showing 1 changed file with 65 additions and 57 deletions.
122 changes: 65 additions & 57 deletions dist/Data-Dumper/t/dumper.t
Expand Up @@ -8,16 +8,32 @@ use warnings;

use Data::Dumper;
use Config;
use Test::More;

# Since Perl 5.8.1 because otherwise hash ordering is really random.
$Data::Dumper::Sortkeys = 1;
$Data::Dumper::Pad = "#";

my $TMAX;
my $XS;
my $TNUM = 0;
my $TMAX = 486;
my $WANT = '';

# 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)
$Data::Dumper::Useperl = 1;
if (defined &Data::Dumper::Dumpxs) {
print "### XS extension loaded, will run XS tests\n";
$XS = 1;
}
else {
print "### XS extensions not loaded, will NOT run XS tests\n";
$TMAX /= 2;
$XS = 0;
}

plan(tests => $TMAX);

our ( @a, $c, $d, $foo, @foo, %foo, @globs, $v, $ping, %ping );
our ( @dogs, %kennel, $mutts );

Expand All @@ -40,7 +56,7 @@ sub change_glob_expectation {
return $input;
}

sub convert_to_native($) {
sub convert_to_native {
my $input = shift;

my @output;
Expand Down Expand Up @@ -92,66 +108,58 @@ sub convert_to_native($) {
}

sub TEST {
my $string = shift;
my $name = shift;
my $t;
{
no strict;
$t = eval $string;
}
$t = '' unless defined $t;
++$TNUM;
$t =~ s/([A-Z]+)\(0x[0-9a-f]+\)/$1(0xdeadbeef)/g
if ($WANT =~ /deadbeef/);
$name = $name ? " - $name" : '';
my $ok = ($t eq $WANT and not $@);
print( $ok ? "ok $TNUM$name\n"
: "not ok $TNUM X$name\n--Expected--\n$WANT\n--Got--\n$@$t\n");

++$TNUM;
{
no strict;
eval "$t";
}
print $@ ? "not ok $TNUM YY\n# \$@ says: $@\n" : "ok $TNUM - no eval error\n";
my ($string, $desc) = @_;
Carp::confess("Tests must have a description")
unless $desc;

local $Test::Builder::Level = $Test::Builder::Level + 1;
SKIP: {
my $have = do {
no strict;
eval $string;
};
my $error = $@;

if (defined $error && length $error) {
is($error, "", "$desc set \$@");
skip('No point in running eval after an error', 2);
}

{
no strict;
$t = eval $string;
}
$t = '' unless defined $t;
++$TNUM;
$t =~ s/([A-Z]+)\(0x[0-9a-f]+\)/$1(0xdeadbeef)/g
if ($WANT =~ /deadbeef/);
$ok = ($t eq $WANT and not $@);
print( $ok ? "ok $TNUM - works a 2nd time after intervening eval\n"
: "not ok $TNUM - re-evaled version \n--Expected--\n$WANT\n--Got--\n$@$t\n");
}
$have =~ s/([A-Z]+)\(0x[0-9a-f]+\)/$1(0xdeadbeef)/g
if $WANT =~ /deadbeef/;
is($have, $WANT, $desc);

sub SKIP_TEST {
my $reason = shift;
++$TNUM; print "ok $TNUM # skip $reason\n";
++$TNUM; print "ok $TNUM # skip $reason\n";
++$TNUM; print "ok $TNUM # skip $reason\n";
}
{
no strict;
eval "$have";
}

$TMAX = 486;
is($@, "", "$desc - output did not eval")
or skip('No point in restesting if output failed eval');

# 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)
$Data::Dumper::Useperl = 1;
if (defined &Data::Dumper::Dumpxs) {
print "### XS extension loaded, will run XS tests\n";
$XS = 1;
}
else {
print "### XS extensions not loaded, will NOT run XS tests\n";
$TMAX /= 2;
$XS = 0;
$have = do {
no strict;
eval $string;
};
$error = $@;

if (defined $error && length $error) {
is($error, "", "$desc after eval set \$@");
}
else {
$have =~ s/([A-Z]+)\(0x[0-9a-f]+\)/$1(0xdeadbeef)/g
if $WANT =~ /deadbeef/;
is($have, $WANT, "$desc after eval");
}
}
}

print "1..$TMAX\n";
sub SKIP_TEST {
my $reason = shift;
SKIP: {
skip($reason, 3);
}
}

#XXXif (0) {
#############
Expand Down

0 comments on commit f7397e4

Please sign in to comment.