Compare two Perl data structures:
Example 6-5. examples/intro/is_deeply.t
#!/usr/bin/perl
use strict;
use warnings;
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" );
sub fetch_data_from_bug_tracking_system {
my @sets = (
{ bugs => 3,
errors => 6,
failures => 8,
warnings => 1,
},
{ bugs => 3,
errors => 9,
failures => 8,
warnings => 1,
},
{ bogs => 3,
erors => 9,
failures => 8,
warnings => 1,
},
);
my $h = $sets[shift];
return %$h;
}
Example 6-6. examples/intro/is_deeply.out
1..3
ok 1 - Query 0
not ok 2 - Query 1
# Failed test 'Query 1'
# in is_deeply.t at line 19.
# Structures begin differing at:
# $got->{errors} = '9'
# $expected->{errors} = '6'
not ok 3 - Query 2
# Failed test 'Query 2'
# in is_deeply.t at line 22.
# Structures begin differing at:
# $got->{errors} = Does not exist
# $expected->{errors} = '6'
# Looks like you failed 2 tests of 3.| Prev | Home (Copyright Gabor Szabo) Perl Training Israel | Next |
| cmp_ok( this, op, that, name); | Up | TODO |