Test-Deep - Re: Comparing undef and empty string

Posted on Tue Jun 10 18:50:05 2008 by fergal in response to 8050 (See the whole thread of 6)
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