<?xml version="1.0" encoding="windows-1252"?>
<node id="999704" title="Regression test with nested data structures -- Or how to use Test::Deep?" created="2012-10-18 06:48:43" updated="2012-10-18 06:48:43">
<type id="115">
perlquestion</type>
<author id="708738">
LanX</author>
<data>
<field name="doctext">
Moin Monks!&lt;P&gt;

I need some help using [mod://Test::Deep] ...&lt;P&gt;

my problem:
I wanna refactor a rather complicated module which produces nested data structures like the following and I wanna test that the output stays stable:&lt;P&gt;

&lt;c&gt;
my $h_data1 = {
         '756' =&gt; {                                   
                   'firstname' =&gt; [                         
                                   '17833329',
                                   '17785333',
                                  ],
                   'lastname' =&gt; [                          
                                   '17785333',
                                   '17785974',
                                  ],
                   'pks' =&gt; [                              
                             '17833329',
                             '17785333',
                             '17785974',
                            ],
                   'time' =&gt; '0.00718307495117188',         # How long it took
                  },
         '755' =&gt; {                                    
                  'lastname' =&gt; [                          
                                  '17833329'
                                 ],
                   'pks' =&gt; [                               
                             '17833329'
                            ],
                   'time' =&gt; '0.00639796257019043',         
                  }
                   };
&lt;/c&gt;

to be able to use Test::More::is_deeply() between to runs I need to ignore the time benchmark.&lt;P&gt;

I already solved this quite complicatedly by copying new filtered hashes...&lt;P&gt;


&lt;c&gt;
use strict;
use warnings;

use Test::More;
use Data::Dump qw/pp/;

sub ignore_fields {
	my $h_in = shift;
	my $h_out;
	my @to_ignore =qw(time);
	
	while ( my ($pk, $h_matches) = each %$h_in ) {
		my $h_filtered = { %$h_matches };
		delete @$h_filtered{@to_ignore};
		$h_out-&gt;{$pk}=$h_filtered;
	}
	return $h_out;
}

pp ignore_fields($h_data1);
pp $h_data1;


is_deeply(ignore_fields($h_data1), ignore_fields($h_data2), "is_deeply");
&lt;/c&gt;&lt;P&gt;

But Test::Deep should be the right module to do this appropriately, unfortunately today my brain is to slow to understand the docs... (it's flue season ;-)&lt;P&gt;

Any help appreciated!&lt;P&gt;

&lt;!-- Node text goes above. Div tags should contain sig only --&gt;
&lt;div class="pmsig"&gt;&lt;div class="pmsig-708738"&gt;
&lt;p&gt;Cheers Rolf
&lt;/div&gt;&lt;/div&gt;</field>
</data>
</node>
