Posted on 2008-06-10 15:50:05-07 by fergal in response to 8050
Re: Comparing undef and empty string

Unfortunately I don't have a good suggestion right now. You can force Test::Deep to use stringwise comparison using str() but that'll only be useful you're constructing one side by hand. In your case both sides are constructed by things out of your control.

Just in case you, Test::More::is_deeply considers undef and "" to be equal but I assume since you're using Test::Deep, Test::More::is_deeply is not suitable.

You could do something a little drastic - intercept all the values and convert undef to "". Something like (untested)

{ my $old_descend = \&Test::Deep::descend; local *Test::Deep::descend = sub { my $d1, $d2 = @_; $d1 = "" unless defined $d1; $old_descend->($d1, $d2); } }

It's kinda sucky but descend() is part of Test::Deep's interface (although not documented).

Direct Responses: 8058 | Write a response
Perl Weekly newsletter
A free weekly newsletter for people who are busy to read all the blogs. click here to check it out.