Test2::Require(3perl)

✨ Test2::Require ✨

omg hi bestie πŸ’– this is Test2::Require (from the perl manual, section 3), and it's the base class + documentation home for all those skip-unless type test packages. iykyk.


πŸŽ€ NAME πŸŽ€

Test2::Require β€” the base class and the docs for packages that skip your tests unless something is true. basically the blueprint for "nah, not today" test files πŸ’…


🌸 DESCRIPTION 🌸

okay so Test2::Require::* packages are the things you load to make sure your test file gets skipped unless some specific requirement is met. iconic behaviour honestly πŸ¦‹

Modules living in this namespace may subclass Test2::Require if they feel like it β€” but it's not strictly necessary. do what feels right, queen πŸ‘‘


πŸ’… HOW DO I WRITE A 'REQUIRE' MODULE? πŸ’…

two ways, bestie. pick your fighter:

🧚 AS A SUBCLASS

package Test2::Require::Widget;
use strict;
use warnings;

use base 'Test2::Require';

sub HAVE_WIDGETS { ... };

sub skip {
    my $class = shift;
    my @import_args = @_;

    if (HAVE_WIDGETS()) {
        # We have widgets, do not skip
        return undef;
    }
    else {
        # No widgets, skip the test
        return "Skipped because there are no widgets" unless HAVE_WIDGETS();
    }
}

1;

so a subclass of Test2::Require literally just needs to implement a skip() method. that's it, that's the whole vibe πŸ’–

that method receives all the import arguments. and the rule is:

  • return undef β†’ test should run βœ…
  • return a reason for skipping β†’ test gets skipped πŸ™ˆ

lowkey simple fr fr.

🌈 STAND-ALONE

if you don't feel like subclassing Test2::Require, that's valid, no judgement β€” you just write an import() method instead:

package Test2::Require::Widget;
use strict;
use warnings;

use Test2::API qw/context/;

sub HAVE_WIDGETS { ... };

sub import {
    my $class = shift;

    # Have widgets, should run.
    return if HAVE_WIDGETS();

    # Use the context object to create the event
    my $ctx = context();
    $ctx->plan(0, SKIP => "Skipped because there are no widgets");
    $ctx->release;
}

1;

not me grabbing a context object and planning a SKIP β€” main character energy tbh πŸ‘‘


πŸ“ SOURCE πŸ“

the source code repository for Test2-Suite lives right here (go look, it's giving open source excellence πŸ’œ):

https://github.com/Test-More/test-more/.


πŸ‘‘ MAINTAINERS πŸ‘‘

Chad Granum <exodist@cpan.org>


⭐ AUTHORS ⭐

Chad Granum <exodist@cpan.org>


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/


okay that's the whole page bestie, you ate 🫢 this was perl v5.44.0, dated 2026-10-17, and the page name is Test2::Require(3perl) β€” periodt. go skip some tests responsibly πŸ’…βœ¨

πŸ“¦ where this page comes from
  • arch rolling: perl 5.44.0-1 Β· Artistic-1.0-Perl AND GPL-1.0-or-later
  • πŸ’– girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms