The naming convention for SomeModule.pm test code is
SomeModule.t. This is not enforced in any way, but it's what
everyone expects.
| Well, it's what I expected, anyway.
See Update Note 1 below.
Some comments on the is_lousy_prime() function code.
if ( $prime_candidate <= 0 ) {
return 0;
exit;
}
The exit; statement in the code above will never be reached.
No code in the function will be executed after the return 0;
statement executes. There's another example of this unreachable-code
syntax in the foreach loop further on in the function.
exit if $prime_candidate == 1 && return 0;
This is more involved, but essentially the same thing is happening:
the exit built-in function will never be executed.
-
If the $prime_candidate == 1 expression is false,
exit will not be executed because the
if-condition is not true.
(Update: The return 0 expression
will not be executed because && short-circuits.)
-
If the $prime_candidate == 1 expression is true, the
return 0 expression will be executed and will
immediately return from the function; exit
will not be executed.
And one more thing: Please, please choose a reasonable indentation
style and stick to it!
Update:
Notes:
-
After reading kcott's reply, I thought to myself
"Yeah, I do seem to recall spending many happy hours watching files
with exactly that nn_name.t format roll by
during countless module installs." WTF?!? I think my confusion stems
from my practice of writing test scripts with the naming format I
mentioned as part of my personal code development best practices. I
then conflated personal and general. Oh, well...
Give a man a fish: <%-{-{-{-<
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|