NAME

DESCRIPTION

This is a Test2 based implementation of the more basic tools originally provided by Test::More. Not all Test::More tools are provided by this package, only the basic/simple ones. Some tools have been modified for better diagnostics capabilities.

EXPORTS

PLANNING

Set the number of tests that are expected. This must be done first or last, never in the middle of testing.

For legacy compatibility you can specify 'tests' as the first argument before the number. You can also use this to skip all with the 'skip_all' prefix, followed by a reason for skipping.

skip_all($reason)

Set the plan to 0 with a reason, then exit true. This should be used before any tests are run.

done_testing

Used to mark the end of testing. This is a safe way to have a dynamic or unknown number of tests.

bail_out($reason)

Invoked when something has gone horribly wrong: stop everything, kill all threads and processes, end the process with a false exit status.

ASSERTIONS

ok($bool)

ok($bool, $name)

ok($bool, $name, @diag)

Simple assertion. If $bool is true the test passes, and if it is false the test fails. The test name is optional, and all arguments after the name are added as diagnostics message if and only if the test fails. If the test passes all the diagnostics arguments will be ignored.

pass()

pass($name)

Fire off a passing test (a single Ok event). The name is optional

fail()

fail($name)

fail($name, @diag)

Fire off a failing test (a single Ok event). The name and diagnostics are optional.

DIAGNOSTICS

diag(@messages)

Write diagnostics messages. All items in @messages will be joined into a single string with no separator. When using TAP, diagnostics are sent to STDERR.

note(@messages)

Write note-diagnostics messages. All items in @messages will be joined into a single string with no separator. When using TAP, notes are sent to STDOUT.

META

$todo = todo($reason)

todo $reason => sub { ... }

This is used to mark some results as TODO. TODO means that the test may fail, but will not cause the overall test suite to fail.

There are two ways to use this. The first is to use a codeblock, and the TODO will only apply to the codeblock.

ok(1, "before"); # Not TODO
todo 'this will fail' => sub {
# This is TODO, as is any other test in this block.
ok(0, "blah");
};
ok(1, "after"); # Not TODO

The other way is to use a scoped variable. TODO will end when the variable is destroyed or set to undef.

ok(1, "before"); # Not TODO
{
my $todo = todo 'this will fail';
# This is TODO, as is any other test in this block.
ok(0, "blah");
};
ok(1, "after"); # Not TODO

This is used to skip some tests. This requires you to wrap your tests in a block labeled SKIP:. This is somewhat magical. If no $count is specified then it will issue a single result. If you specify $count it will issue that many results.

As a valued partner and proud supporter of MetaCPAN, StickerYou is
happy to offer a 10% discount on all Custom Stickers,
Business Labels, Roll Labels,
Vinyl Lettering or Custom Decals. StickerYou.com
is your one-stop shop to make your business stick.
Use code METACPAN10 at checkout to apply your discount.