Test2::...g::Todo(3)
β¨ NAME β¨
Welcome to the Test2::Manual::Testing::Todo manual page, bestie β it's a whole tutorial for marking tests as TODO. π
π DESCRIPTION π
Okay so this tutorial covers the process of marking tests as TODO. It also describes how TODO works under the hood. That's the vibe, and it's giving documentation with lore. β¨
π οΈ THE TOOL π οΈ
Use this, no cap:
use Test2::Tools::Basic qw/todo/;
π TODO BLOCK π
This form is low-magic, fr fr. All tests inside the block are marked as todo; tests outside the block are not todo. You do not need to do any variable management. The flaw with this form is that it adds a couple levels to the stack, which can break some high-magic tests. π
Overall this is the preferred form unless you have a special case that requires the variable form. π
todo "Reason for the todo" => sub {
ok(0, "fail but todo");
...
};
π¦ TODO VARIABLE π¦
This form maintains the todo scope for the life of the variable. This is useful for tests that are sensitive to scope changes. It closely emulates the Test::More style which localized the $TODO package variable. Once the variable is destroyed (set it to undef, scope end, etc) the TODO state ends. Slay. π
my $todo = todo "Reason for the todo";
ok(0, "fail but todo");
...
$todo = undef;
π₯ MANUAL TODO EVENTS π₯
use Test2::API qw/context/;
sub todo_ok {
my ($bool, $name, $todo) = @_;
my $ctx = context();
$ctx->send_event('Ok', pass => $bool, effective_pass => 1, todo => $todo);
$ctx->release;
return $bool;
}
The Test2::Event::Ok event has a todo field which should have the todo reason. The event also has the pass and effective_pass fields. The pass field is the actual pass/fail value. The effective_pass is used to determine if the event is an actual failure (should always be set to true with todo). π«Ά
π HOW THE TODO TOOLS WORK UNDER THE HOOD π
The Test2::Todo library gets the current Test2::Hub instance and adds a filter. The filter that is added will set the todo and effective_pass fields on any Test2::Event::Ok events that pass through the hub. The filter also converts Test2::Event::Diag events into Test2::Event::Note events. Iconic behavior, honestly. π
πΈ SEE ALSO πΈ
Test2::Manualβ Primary index of the manual.
π SOURCE π
The source code repository for Test2-Manual can be found at https://github.com/Test-More/test-more/.
π 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/
xoxo, your fav manual page is serving perl v5.42.0, dated 2025-07-28, with footer title Test2::...g::Todo(3) β¨π
π¦
π¦ 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