TEST2::TOOLS::DEFER(3perl)

✨ NAME ✨

ok so bestie, this is Test2::Tools::Defer from the Test2:...::Defer(3perl) page in the Perl Programmers Reference Guide πŸ’– β€” and it's literally the module that lets you write tests that get executed at a later time. periodt. πŸŽ€


🌸 DESCRIPTION 🌸

ngl, sometimes you need to test things BEFORE loading the necessary functions. It's giving "I want to test it but it doesn't exist yet 😭". And that's exactly what this module lets you do. You write your tests now, and then have them run later, after "Test2" is loaded. Iconic behaviour, honestly. πŸ‘‘

So the vibe is: you tell it what test function to run, and what arguments to give it. The function name and arguments will be stored to be executed later. Then when you're ready, you run do_def() to kick them off once the functions are defined. main character energy fr fr πŸ’…


✨ SYNOPSIS ✨

use strict;
use warnings;

use Test2::Tools::Defer;

BEGIN {
    def ok => (1, 'pass');
    def is => ('foo', 'foo', 'runs is');
    ...
}

use Test2::Tools::Basic;

do_def(); # Run the tests

# Declare some more tests to run later:
def ok => (1, "another pass");
...

do_def(); # run the new tests

done_testing;

πŸ¦‹ EXPORTS πŸ¦‹

  • def function => @args; β€” this will store the function name, and the arguments to be run later. Heads up though, bestie: note that each package has a separate store of tests to run. So don't go expecting your tests from one package to show up in another, iykyk πŸ™ˆ
  • do_def() β€” this will run all the stored tests. It will also reset the list to be empty so you can add more tests to run even later. It's giving "run it, then clean slate ✨". You can call this multiple times and it just keeps going, no cap.

πŸ’œ SOURCE πŸ’œ

The source code repository for Test2-Suite can be found at https://github.com/Test-More/test-more/. Go look, it's right there 🫢


πŸ‘‘ 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/


ok that's the whole page, you're literally so welcome πŸ’– go forth and defer those tests bestie, it's giving organised and I'm obsessed 🌸

πŸ’… perl v5.44.0 Β· 2026-10-17 Β· signing off from Test2:...::Defer(3perl) Β· slay πŸ¦‹

πŸ“¦ 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