Skip Menu |

Preferred bug tracker

Please visit the preferred bug tracker to report your issue.

This queue is for tickets about the Perl-Critic CPAN distribution.

Report information
The Basics
Id: 43910
Status: resolved
Priority: 0/
Queue: Perl-Critic

People
Owner: Nobody in particular
Requestors: mschwern [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: Unimportant
Broken in: (no value)
Fixed in: 1.104



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" );
The code in the RT report appears to be from t/05_utils.t. A sweep with a custom policy failed to find any examples of this anywhere else. Is there any place to put a policy whose sole use is to look for this kind of thing in Perl::Critic tests? If so, would such a test be desirable? Proposed change to t/05_utils.t committed as svn revision 3242. Tom Wyant
On Thu Mar 19 21:36:08 2009, WYANT wrote: Show quoted text
> The code in the RT report appears to be from t/05_utils.t. A sweep with > a custom policy failed to find any examples of this anywhere else. Is > there any place to put a policy whose sole use is to look for this kind > of thing in Perl::Critic tests? If so, would such a test be desirable?
I don't think it's worth trying to come up with a heuristic just to catch this small mistake. There are valid reasons for writing is( foo(), 1 ); This just ain't one of them. And when it goes wrong, it fails anyway. Show quoted text
> Proposed change to t/05_utils.t committed as svn revision 3242.
Thanks.
Subject: Re: [rt.cpan.org #43910] is( is_foo(), 1 ); dangerous
Date: Tue, 25 Aug 2009 22:28:25 -0500
To: bug-Perl-Critic [...] rt.cpan.org
From: Elliot Shank <perl [...] galumph.com>
Fix released in 1.104.