Skip Menu |

Preferred bug tracker

Please visit the preferred bug tracker to report your issue.

This queue is for tickets about the Test-Differences CPAN distribution.

Report information
The Basics
Id: 95446
Status: resolved
Priority: 0/
Queue: Test-Differences

People
Owner: Nobody in particular
Requestors: SREZIC [...] cpan.org
Cc: davidp [...] preshweb.co.uk
AdminCc:

Bug Information
Severity: Wishlist
Broken in: 0.61
Fixed in: (no value)



Subject: Don't use _flatten for HASH_of_scalars
Reading the diff of two HASH_of_scalars variables is actually quite difficult. Here's a sample script: #!perl use strict; use Test::More 'no_plan'; use Test::Differences; my $force_dumpit = shift; my $expected = { 'id' => 1828781669, 'name' => 'Paul', 'city' => 'Cairo', 'country' => 'USA', 'version' => 1, ($force_dumpit ? ('DUMMY'=>[]) : ()), }; my $got = { 'id' => 1828781670, 'name' => 'Paul', 'city' => 'Cairo', 'country' => 'USA', 'version' => 1, ($force_dumpit ? ('DUMMY'=>[]) : ()), }; eq_or_diff $got, $expected; __END__ The output is: # +----+----------------------------------------+----------------------------------------+ # | Elt|Got |Expected | # +----+----------------------------------------+----------------------------------------+ # | 0|'city','country','id','name','version' |'city','country','id','name','version' | # * 1|'Cairo','USA',1828781670,'Paul',1 |'Cairo','USA',1828781669,'Paul',1 * # +----+----------------------------------------+----------------------------------------+ Finding the difference here is quite difficult, and more difficult if the hashes are larger. It's much easier to spot the difference if the comparison is done using Data::Dumper (here forced by adding a dummy pair with a non-scalar value): # +----+---------------------+---------------------+ # | Elt|Got |Expected | # +----+---------------------+---------------------+ # | 0|{ |{ | # | 1| DUMMY => [], | DUMMY => [], | # | 2| city => 'Cairo', | city => 'Cairo', | # | 3| country => 'USA', | country => 'USA', | # * 4| id => 1828781670, | id => 1828781669, * # | 5| name => 'Paul', | name => 'Paul', | # | 6| version => 1 | version => 1 | # | 7|} |} | # +----+---------------------+---------------------+ I am not sure if there are situations where the output created by _flatten() is easier to read. Regards, Slaven
On Wed May 07 11:56:58 2014, SREZIC wrote: Show quoted text
> Reading the diff of two HASH_of_scalars variables is actually quite > difficult. Here's a sample script: > > #!perl > use strict; > use Test::More 'no_plan'; > use Test::Differences; > > my $force_dumpit = shift; > > my $expected = { > 'id' => 1828781669, > 'name' => 'Paul', > 'city' => 'Cairo', > 'country' => 'USA', > 'version' => 1, > ($force_dumpit ? ('DUMMY'=>[]) : ()), > }; > my $got = { > 'id' => 1828781670, > 'name' => 'Paul', > 'city' => 'Cairo', > 'country' => 'USA', > 'version' => 1, > ($force_dumpit ? ('DUMMY'=>[]) : ()), > }; > eq_or_diff $got, $expected; > __END__ > > The output is: > # +----+---------------------------------------- > +----------------------------------------+ > # | Elt|Got |Expected > | > # +----+---------------------------------------- > +----------------------------------------+ > # | 0|'city','country','id','name','version' > |'city','country','id','name','version' | > # * 1|'Cairo','USA',1828781670,'Paul',1 > |'Cairo','USA',1828781669,'Paul',1 * > # +----+---------------------------------------- > +----------------------------------------+ > > Finding the difference here is quite difficult, and more difficult if > the hashes are larger. > > It's much easier to spot the difference if the comparison is done > using Data::Dumper (here forced by adding a dummy pair with a non- > scalar value): > > # +----+---------------------+---------------------+ > # | Elt|Got |Expected | > # +----+---------------------+---------------------+ > # | 0|{ |{ | > # | 1| DUMMY => [], | DUMMY => [], | > # | 2| city => 'Cairo', | city => 'Cairo', | > # | 3| country => 'USA', | country => 'USA', | > # * 4| id => 1828781670, | id => 1828781669, * > # | 5| name => 'Paul', | name => 'Paul', | > # | 6| version => 1 | version => 1 | > # | 7|} |} | > # +----+---------------------+---------------------+ > > I am not sure if there are situations where the output created by > _flatten() is easier to read.
I doubt there are. I'd be happy to apply a test, code and doco patch to remove it.
On 2014-10-21 23:31:19, DCANTRELL wrote: Show quoted text
> On Wed May 07 11:56:58 2014, SREZIC wrote:
> > I am not sure if there are situations where the output created by > > _flatten() is easier to read.
> > I doubt there are. I'd be happy to apply a test, code and doco patch > to remove it.
I've done just that in https://github.com/Ovid/Test-Differences/pull/5
On Fri Nov 07 12:48:49 2014, BIGPRESH wrote: Show quoted text
> On 2014-10-21 23:31:19, DCANTRELL wrote:
> > On Wed May 07 11:56:58 2014, SREZIC wrote:
> > > I am not sure if there are situations where the output created by > > > _flatten() is easier to read.
> > > > I doubt there are. I'd be happy to apply a test, code and doco patch > > to remove it.
> > I've done just that in https://github.com/Ovid/Test-Differences/pull/5
Merged. It introduces a regression on some older perls, but I expect I can find a work-around.
On Thu Nov 20 08:54:04 2014, DCANTRELL wrote: Show quoted text
> On Fri Nov 07 12:48:49 2014, BIGPRESH wrote:
> > On 2014-10-21 23:31:19, DCANTRELL wrote:
> > > On Wed May 07 11:56:58 2014, SREZIC wrote:
> > > > I am not sure if there are situations where the output created by > > > > _flatten() is easier to read.
> > > > > > I doubt there are. I'd be happy to apply a test, code and doco > > > patch > > > to remove it.
> > > > I've done just that in https://github.com/Ovid/Test- > > Differences/pull/5
> > Merged. It introduces a regression on some older perls, but I expect I > can find a work-around.
Fixed