When to use is()

is() is likely to be the test function you use most.

Use instead of ok() when you're testing "this equals that".

# Instead Of This                 # Do This
ok( $sum == 42 );                 is( $sum, 42 );
ok( $err eq 'Out Of Cheese' );    is( $err, 'Out Of Cheese' );
not ok 12
#     Failed test (foo.t at line 14)
#          got: 'No Tengo Queso'
#     expected: 'Out Of Cheese'

is() does a string comparison which 99.99% of the time comes out right.

# Instead of this                 # Do This
ok( !defined $deleted );          is( $deleted, undef );

Yes, there is an isnt() and isn't().

# Instead of this                 # Do This
ok( defined $widget );            isnt( $widget, undef );

| toc |