Test2::Tools::Basic(3) | User Contributed Perl Documentation | Test2::Tools::Basic(3) |
Test2::Tools::Basic - Test2 implementation of the basic testing tools.
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.
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;
All subs are exported by default.
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.
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: { skip "This will wipe your drive"; # This never gets run: ok(!system('sudo rm -rf /'), "Wipe drive"); }
The source code repository for Test2-Suite can be found at https://github.com/Test-More/Test2-Suite/.
Copyright 2018 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/
2020-10-22 | perl v5.34.0 |