Test::Future(3pm)
β¨ NAME β¨
Test::Future β unit test assertions for Future instances π
okay bestie, this is the perl manpage for Test::Future (3pm) and it's literally the glow-up your async test suite has been waiting for π«Ά
πΈ SYNOPSIS πΈ
use Test::More tests => 2;
use Test::Future;
no_pending_futures {
my $f = some_function();
is( $f->get, "result", 'Result of the some_function()' );
} 'some_function() leaves no pending Futures';
like. look at that. so clean. so iconic. π
π¦ DESCRIPTION π¦
So this module hands you unit testing assertions that are genuinely useful when you're testing code that's built on β or just vibing with β Future instances or subclasses. That's it, that's the vibe check. β¨
π FUNCTIONS π
no_pending_futures
no_pending_futures( \&code, $name );
Since version 0.29. (so if you're on anything older, this function simply does not exist yet, no cap π)
Here's the tea: it runs the block of code you gave it, and while that's happening it keeps track of every single Future instance constructed. Every one. It's watching. π
Once your code returns, each of those instances gets inspected to make sure they're not still pending. If they're all either ready (meaning success or failure, both count) or cancelled, the test passes. If even one of them is still pending? The test fails. periodt. π₯
Now, if Devel::MAT is installed, it gets pulled in to write a memory state dump after a failure happens. It creates a .pmat file named the same as the unit test β except the trailing .t suffix gets replaced with -TEST.pmat, where TEST is the number of the test that failed (just in case there was more than one, which. yeah. been there π). A list of addresses of the Future instances that are still pending also gets printed, to help you debug the whole situation.
Also super important bestie: it is not an error if your code doesn't construct anyFutureinstances at all. Zero futures? Totally fine. And your block of code can contain other testing assertions too β those will all be run before the assertion made byno_pending_futuresitself. π
π AUTHOR π
Paul Evans <leonerd@leonerd.org.uk> π
that's the whole page, bestie β perl v5.40.1, dated 2025-09-22, straight from the Test::Future(3pm) page itself. go forth and let no future hang around pending, you got this πβπ¦
π¦ where this page comes from
- ubuntu resolute: libfuture-perl 0.52-1 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu stonking: libfuture-perl 0.52-1 Β· Artistic-1.0-Perl OR 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