is_deeply on a hash
Another example with is_deeply
checking the returned hash from a bug tracking system.
use strict;
use warnings;
use MyBugs;
use Test::More tests => 3;
my %expected = (
bugs => 3,
errors => 6,
failures => 8,
warnings => 1,
);
my %a = fetch_data_from_bug_tracking_system(0);
is_deeply( \%a, \%expected, "Query 0" );
my %b = fetch_data_from_bug_tracking_system(1);
is_deeply( \%b, \%expected, "Query 1" );
my %c = fetch_data_from_bug_tracking_system(2);
is_deeply( \%c, \%expected, "Query 2" );
# Failed test 'Query 1'
# at t/is_deeply_bugs.t line 21.
# Structures begin differing at:
# $got->{errors} = '9'
# $expected->{errors} = '6'
# Failed test 'Query 2'
# at t/is_deeply_bugs.t line 24.
# Structures begin differing at:
# $got->{bugs} = Does not exist
# $expected->{bugs} = '3'
# Looks like you failed 2 tests of 3.
t/is_deeply_bugs.t ..
Dubious, test returned 2 (wstat 512, 0x200)
Failed 2/3 subtests
Test Summary Report
-------------------
t/is_deeply_bugs.t (Wstat: 512 Tests: 3 Failed: 2)
Failed tests: 2-3
Non-zero exit status: 2
Files=1, Tests=3, 0 wallclock secs ( 0.01 usr 0.00 sys + 0.03 cusr 0.00 csys = 0.04 CPU)
Result: FAIL
What if we are testing a live system and so not interested in the exact values, just in the keys and the fact that the values are numbers?