Data-Dumper: Boost test coverage and refactor.
authorJames E Keenan <jkeenan@cpan.org>
Sun, 20 Jan 2013 00:20:21 +0000 (19:20 -0500)
committerJames E Keenan <jkeenan@cpan.org>
Thu, 31 Jan 2013 02:20:15 +0000 (21:20 -0500)
commit3bd791fa111f523487bc4f8decd761d9b5ccca50
tree38635da52e63806ccefb106b5f0b88f313f2bb40
parentf3f40957880ac97205d3dec85be9b1a10abed0d6
Data-Dumper: Boost test coverage and refactor.

Thanks to coverage data posted by Paul Johnson as part of Perl
Foundation-sponsored work, we know that as of Jan 01 2013, Data::Dumper
(v2.139) had the following coverage of its code by its test suite:

                          stmt  bran  cond   sub
Dumper.xs                 94.8  64.5
blib/lib/Data/Dumper.pm   85.3  76.7  69.6  71.4

The coverage levels reported for Dumper.pm are unacceptably low,
particularly for a library which is part of the Perl 5 core
distribution.  With this commit, we significantly improve
coverage of Dumper.pm; Dumper.xs will need attention from those with XS
expertise.

Attempting to write tests for every line in a codebase frequently
uncovers places in the code that are superfluous or cannot be reached.
The close study of the code required to achieve high test coverage also
discloses places where the code and its documentation are at odds with
each other.  This work on Data::Dumper is no exception, so we have made
changes to Dumper.pm where appropriate.  In addition, in order to
facilitate this analysis and to make the codebase easier to maintain
going forward, the code in Dumper.pm has been tidied up in certain
locations, mostly with respect to tabs vs. whitespace in indentation and
cuddled elses.

Specifics of this commit:

* Modifications to Dumper.pm

** Eliminate subs Dumpf() and Dumpp, which were neither documented nor
tested anywhere in the codebase.  (They will be reinstated if and only
if someone can provide a rationale for that, along with documentation
and testing.)

** For both Values() and Names():  explicit handling (croak) of the case
where the method is provided with a defined argument that is not an
array reference.

** Tidying, mostly in _dump().

** Deletion of commented-out code.

* New test files

** t/deparse.t
** t/dumpperl.t
** t/indent.t
** t/misc.t
** t/names.t
** t/purity_deepcopy_maxdepth.t
** t/quotekeys.t
** t/seen.t
** t/sortkeys.t
** t/sparseseen.t
** t/toaster.t
** t/values.t

** t/lib/Testing.pm - package holding subs used in the new test files

* Expanded test files

** t/freezer.t
** t/terse.t

* Add test for variable type which Data-Dumper does not handle.  Improve
punctuation in fatal error messge.  Related to: RT #101508.

The work done so far has significantly improved the coverage.  As of Jan
26 2013 we are at:
                                  stmt  bran  cond   sub
Jan 01: blib/lib/Data/Dumper.pm   85.3  76.7  69.6  71.4
Jan 26: blib/lib/Data/Dumper.pm   97.9  94.3  82.1  97.6

Additional revisions submitted by Aaron Crane++:

* Adjust newly-added comment.  Without this change, it appears to run on
into the existing comment on the next line.

* Mention "undefined" in carp message, not "non-ref".  This is a more
precise description of the problem encountered.

* Whitespace corrections.

* Avoid scalar-IO in test routine; just return the concatenated ->Dump
return values directly.
20 files changed:
MANIFEST
dist/Data-Dumper/Dumper.pm
dist/Data-Dumper/t/bless_var_method.t [new file with mode: 0644]
dist/Data-Dumper/t/bugs.t
dist/Data-Dumper/t/deparse.t [new file with mode: 0644]
dist/Data-Dumper/t/dumper.t
dist/Data-Dumper/t/dumpperl.t [new file with mode: 0644]
dist/Data-Dumper/t/freezer.t
dist/Data-Dumper/t/indent.t [new file with mode: 0644]
dist/Data-Dumper/t/lib/Testing.pm [new file with mode: 0644]
dist/Data-Dumper/t/misc.t [new file with mode: 0644]
dist/Data-Dumper/t/names.t [new file with mode: 0644]
dist/Data-Dumper/t/purity_deepcopy_maxdepth.t [new file with mode: 0644]
dist/Data-Dumper/t/quotekeys.t [new file with mode: 0644]
dist/Data-Dumper/t/seen.t [new file with mode: 0644]
dist/Data-Dumper/t/sortkeys.t [new file with mode: 0644]
dist/Data-Dumper/t/sparseseen.t [new file with mode: 0644]
dist/Data-Dumper/t/terse.t
dist/Data-Dumper/t/toaster.t [new file with mode: 0644]
dist/Data-Dumper/t/values.t [new file with mode: 0644]