Test2::...s::Basic(3)
πΈ NAME πΈ
Test2::Tools::Basic - Test2 implementation of the basic testing tools.
This is the Test2::Tools::Basic(3) page from the user-contributed Perl documentation zone, bestie. Welcome to the group chat. π
π DESCRIPTION π
Okay so this package is the Test2-based implementation of the more basic tools that originally came from Test::More. It does not ship every single Test::More tool β only the basic/simple ones, periodt. Some tools got modified for better diagnostics capabilities. β¨
π¦ SYNOPSIS π¦
Hereβs the whole mood board, copied exactly so you can vibe with it:
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 β no extra import gymnastics required. π«Ά
β¨ PLANNING β¨
plan($num),plan('tests' => $num),plan('skip_all' => $reason)β Set the number of tests you expect. This must be done first or last β never in the middle of testing, bestie. 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 to0with 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. π This is dramatic because the situation is dramatic.
π₯ ASSERTIONS π₯
ok($bool),ok($bool, $name),ok($bool, $name, @diag)β Simple assertion. If$boolis 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 singleOkevent). The name is optional. β¨fail(),fail($name),fail($name, @diag)β Fire off a failing test (a singleOkevent). The name and diagnostics are optional. π
π DIAGNOSTICS π
diag(@messages)β Write diagnostics messages. All items in@messageswill be joined into a single string with no separator. When using TAP, diagnostics are sent toSTDERR. Returns false, so as to preserve failure. π«Άnote(@messages)β Write note-diagnostics messages. All items in@messageswill be joined into a single string with no separator. When using TAP, notes are sent toSTDOUT. πΈ
π 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. No cap. π
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 the same thing, but without the {...} scope. β¨
ok(1, "before"); # Not TODO
my $todo = todo 'this will fail';
ok(0, "blah"); # TODO
$todo = undef;
ok(1, "after"); # Not TODO
skip($why),skip($why, $count)β 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$countis specified then it will issue a single result. If you specify$countit will issue that many results.
SKIP: {
skip "This will wipe your drive";
# This never gets run:
ok(!system('sudo rm -rf /'), "Wipe drive");
}
π SOURCE π
The source code repository for Test2-Suite can be found at https://github.com/Test-More/test-more/ β go look, bestie. π«Ά
π MAINTAINERS π
Chad Granum <exodist@cpan.org>
π AUTHORS π
Chad Granum <exodist@cpan.org>
β COPYRIGHT β
Copyright Chad Granum <exodist@cpan.org>.
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
See http://dev.perl.org/licenses/
π Thatβs the whole manual page, bestie β perl v5.42.0 on 2025-07-28, page Test2::Tools::Basic(3). Stay slaying, and may all your tests be green. π
β¨
π¦ where this page comes from
- opensuse-leap 16.0: perl-Test-Simple 1.302214-bp160.1.2 Β· Artistic-1.0 OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms