I have a subroutine that populates a hash of arrays with coderefs by calling
closures. I'm trying to call Test::More::is_deeply to compare two structures
that should be identical and I'm running into trouble. When none of the
closures take arguments, everything is fine, but when one of the closure
subroutines takes an argument to generate the code, is_deeply fails. I put
together a simple test case:

sub closure_no_args{
    return sub{
        return 1;
    }
}

sub closure_args{
    my $arg = shift;
    return sub{
        return $arg;
    }
}

my $ds1 = {
    one => &closure_no_args,
    two => &closure_args(15),
};

my $ds2 = {
    one => &closure_no_args,
    two => &closure_args(15),
};

is_deeply( $ds1, $ds2, "they're the same" );

yields:

not ok 1 - they're the same
#   Failed test 'they're the same'
#   in test.t at line 29.
#     Structures begin differing at:
#          $got->{two} = CODE(0x13ef94)
#     $expected->{two} = CODE(0x152c28)
1..1
# Looks like you failed 1 test of 1.

I suppose that the important thing is not the content of the coderefs, but
that their return values are equal, but I'm not sure what would really make
a valid test in this case or what the best means of comparing those would
be. Any assistance would be appreciated.

Andrew

----

Andrew Gianni
Administrative Computing Services
Computing and Information Technology
University at Buffalo
215 MFAC, Ellicott Complex
Buffalo, NY 14261-0026
716.645.3587x7124

Reply via email to