Test::Requires(3)

πŸ’… Test::Requires β€” the vibe check for your modules, bestie ✨

Okay so real talk: this is the manual page for Test::Requires, and it's genuinely one of those tiny modules that just gets it. No cap. Let's break it down together 🫢


✨ NAME ✨

Test::Requires β€” it literally just checks to see if the module can be loaded. That's the whole job. Iconic, low-effort, high-impact πŸŽ€


🌸 SYNOPSIS 🌸

So here's how you actually use it, in all its forms. Copy these exactly, bestie, don't freestyle πŸ’…

    # in your Makefile.PL
    use inc::Module::Install;
    test_requires 'Test::Requires';

    # in your test
    use Test::More tests => 10;
    use Test::Requires {
        'HTTP::MobileAttribute' => 0.01, # skip all if HTTP::MobileAttribute doesn't installed
    };
    isa_ok HTTP::MobileAttribute->new, 'HTTP::MobileAttribute::NonMobile';

    # or
    use Test::More tests => 10;
    use Test::Requires qw(
        HTTP::MobileAttribute
    );
    isa_ok HTTP::MobileAttribute->new, 'HTTP::MobileAttribute::NonMobile';

    # or
    use Test::More tests => 10;
    use Test::Requires;
    test_requires 'Some::Optional::Test::Required::Modules';
    isa_ok HTTP::MobileAttribute->new, 'HTTP::MobileAttribute::NonMobile';

Like… pick whichever flavor speaks to you, they all slay 🌈


πŸ¦‹ DESCRIPTION πŸ¦‹

So Test::Requires checks to see if the module can be loaded. That's it. That's the whole mood ✨

And here's the cute part: if this fails, it doesn't fail your tests β€” it skips all of them instead. It's giving "no drama, just gracefully stepping aside" energy πŸ’€

It can also be used to require a minimum version of Perl, which is honestly so useful:

    use Test::Requires "5.010";  # quoting is necessary!!

    # or
    use Test::Requires "v5.10";
⚠️ Bestie, notice that # quoting is necessary!! comment? Yeah. Quote it. Don't come crying to me when it breaks 😭

πŸ’– AUTHOR πŸ’–

Tokuhiro Matsuno <tokuhirom @*(#RJKLFHFSDLJF gmail.com>

(Yes, that email is exactly as cursed as it looks. I don't make the rules, I just report them πŸ™ˆ)


πŸ‘‘ THANKS TO πŸ‘‘

These absolute legends made it happen:

    kazuho++ # some tricky stuff
    miyagawa++ # original code from t/TestPlagger.pm
    tomyhero++ # reported issue related older test::builder
    tobyink++ # documented that Test::Requires "5.010" works

We stan a collaborative community 🫢✨


πŸ“ ENVIRONMENT πŸ“

So there's this environment variable, right? If RELEASE_TESTING is true, then instead of skipping tests, Test::Requires bails out. Different energy entirely β€” that's the "we're not playing around anymore" mode πŸ’…πŸ”₯


🧚 SEE ALSO 🧚

  • "TestPlagger.pm" in t β€” go look, iykyk πŸ‘€

πŸ’œ LICENSE πŸ’œ

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself. Slay, open source queen πŸ‘‘πŸŒΈ


Okay bestie, that's the whole page πŸ’– This iconic documentation was brought to you by perl v5.42.0, dated 2020-05-14, and honestly? A moment. Periodt. πŸŽ€βœ¨πŸ¦‹

πŸ“¦ where this page comes from