You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The above warning is generated by the following code:
use Test::More;
use Test::Deep;
plan tests => 1;
my @data = (
{
name => 'Foo',
},
{
name => undef,
},
);
cmp_deeply \@data, array_each({
name => re('^.*$')
});
If undef is ineed an acceptable value then the test should be written name => any(undef, re('^.*$')
but when the data we are checking is a lot more complex it is quite hard to find the problematic field and regex.
Would it be possible to make this a test failure? Maybe, in order to keep backward compatibility, depending on some parameter?
e.g. adding return 0 if not defined $got; on line 31 of Text/Deep/Regexp would have helped me.
The text was updated successfully, but these errors were encountered:
I just encountered this issue when using bag(), which is another situation where the warning doesn't make sense.
Here's an example that shows it:
my$data = [
{ start=>'2021-06-16', end=>undef },
{ start=>'2021-06-16', end=>'2021-06-17' },
];
cmp_deeply(
$data,
bag(
{
start=> re('^\d{4}-\d{2}-\d{2}$'),
end=> re('^\d{4}-\d{2}-\d{2}$'),
},{
start=> re('^\d{4}-\d{2}-\d{2}$'),
end=>undef,
},
),
"The data should contain one entry with an end date and another entry with end undefined"
);
For those of you who have got here from Google and looking for a workaround then you can get rid of the warning by swapping the re() out for a code() that checks to see if the value is defined and matches your regular expression - e.g.
cmp_deeply(
$data,
bag(
{
start=> re('^\d{4}-\d{2}-\d{2}$'),
# Using code() rather than re() to avoid the undef warning bug# see https://github.com/rjbs/Test-Deep/issues/39end=> code( sub { defined$_[0] && $_[0] =~ m/^\d{4}-\d{2}-\d{2}$/ } ),
},{
start=> re('^\d{4}-\d{2}-\d{2}$'),
end=>undef,
},
),
"The data should contain one entry with an end date and another entry with end undefined"
);
The above warning is generated by the following code:
If undef is ineed an acceptable value then the test should be written
name => any(undef, re('^.*$')
but when the data we are checking is a lot more complex it is quite hard to find the problematic field and regex.
Would it be possible to make this a test failure? Maybe, in order to keep backward compatibility, depending on some parameter?
e.g. adding
return 0 if not defined $got;
on line 31 of Text/Deep/Regexp would have helped me.The text was updated successfully, but these errors were encountered: