Slash Boxes
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
More | Login | Reply
Loading... please wait.
  • by schwern (1528) on 2003.08.05 16:17 (#22802) Homepage Journal
    ok($a==1, "Testing 1st Parameter");

    is better written as

    is( $a, 1, "Testing 1st Parameter");

    for better diagnostics on failure. Any time you're writing

    ok( $a == 1 )
    you probably want
    is( $a, 1 );
    unless your name is Nick Clark, in which case you reall, really meant '==' so its cmp_ok($a, '==', 1 ) or Damian Conway, in which case there's probably a really good reason you used ok() instead of is().

    Even better would be:

    is( $a, 1, 'getting A' );

    Mentioning that you're "testing" something in a test name is redundant and redundant, strike that out. Then there's the matter of properly describing what you're testing. You're not testing the first parameter, there's no order that I can see here, you're testing that you can get A.

    Finally, assuming you don't need $a, which you don't...

    is( $t->get('A'), 1, 'getting A');

    why clutter up your code with unnecessary temp variables?

    The last test, as mentioned before, is better written as:

    ok( !defined $t->get('D'), 'no extra params created' )

    to remove all that life support around it. But what if $t->get('D') did return something? How would we know what it was? Same way we do with everything else, use is().

    is( $t->get('D'), undef, 'no extra params created' )