You are viewing the version of this documentation from Perl 5.39.4. This is a development version of Perl.

CONTENTS

NAME

Test2::Tools::Basic - Test2 implementation of the basic testing tools.

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.

SYNOPSIS

use Test2::Tools::Basic;

ok($x, "simple test");

if ($passing) {
    pass('a passing test');
}
else {
    fail('a failing test');
}

diag "This is a diagnostics message on STDERR";
note "This is a diagnostics message on STDOUT";

{
    my $todo = todo "Reason for todo";
    ok(0, "this test is todo");
}

ok(1, "this test is not todo");

todo "reason" => sub {
    ok(0, "this test is todo");
};

ok(1, "this test is not todo");

SKIP: {
    skip "This will wipe your drive";

    # This never gets run:
    ok(!system('sudo rm -rf /'), "Wipe drive");
}

done_testing;

EXPORTS

All subs are exported by default.

PLANNING

plan($num)
plan('tests' => $num)
plan('skip_all' => $reason)

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