LanX has asked for the wisdom of the Perl Monks concerning the following question:
Moin Monks!
I need some help using Test::Deep ...
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:
to be able to use Test::More::is_deeply() between to runs I need to ignore the time benchmark.my $h_data1 = { '756' => { 'firstname' => [ '17833329', '17785333', ], 'lastname' => [ '17785333', '17785974', ], 'pks' => [ '17833329', '17785333', '17785974', ], 'time' => '0.00718307495117188', # How long + it took }, '755' => { 'lastname' => [ '17833329' ], 'pks' => [ '17833329' ], 'time' => '0.00639796257019043', } };
I already solved this quite complicatedly by copying new filtered hashes...
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->{$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 +");
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 ;-)
Any help appreciated!
Cheers Rolf
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Regression test with nested data structures -- Or how to use Test::Deep?
by ELISHEVA (Prior) on Oct 18, 2012 at 13:31 UTC | |
by LanX (Saint) on Oct 18, 2012 at 13:35 UTC |
Back to
Seekers of Perl Wisdom