Subject: | is( is_foo(), 1 ); dangerous |
I was fixing a bug in Utils when I noticed this peculiar style:
is( is_perl_builtin('print'), 1, 'Is perl builtin function' );
isnt( is_perl_builtin('foobar'), 1, 'Is not perl builtin function' );
It's incorrect to assume that a function documented to return true and
false will return 1. For example...
sub has_stuff {
return scalar @Stuff;
}
So the above should be written...
ok( is_perl_builtin('print'), 'Is perl builtin function' );
ok( !is_perl_builtin('foobar'), 'Is not perl builtin function' );
While it's true that ok() won't tell you the return value on failure,
what more do you need to know than it wasn't true?
If you ever find yourself having to test truth using is(), normalize the
values using !!
is( !!$this, !!$that, "this and that have the same truthiness" );