Test::SubCalls(3)
okay bestie, welcome to the Test::SubCalls(3) page β yep, User Contributed Perl Documentation is in the building π«Ά. let's get into it.
π NAME π
Test::SubCalls β Track the number of times subs are called β¨
πΈ VERSION πΈ
version 1.10 β periodt.
π SYNOPSIS π
here's the whole vibe, bestie:
use Test::SubCalls;
# Start tracking calls to a named sub
sub_track( 'Foo::foo' );
# Run some test code
...
# Test that some sub deep in the codebase was called
# a specific number of times.
sub_calls( 'Foo::foo', 5 );
sub_calls( 'Foo::foo', 5, 'Use a custom test message' );
# Reset the counts for one or all subs
sub_reset( 'Foo::foo' );
sub_reset_all();
π¦ DESCRIPTION π¦
There are a number of different situations (like testing caching code) where you want to do a number of tests, and then verify that some underlying subroutine deep within the code was called a specific number of times. lowkey iconic use case, honestly π§
This module gives you a bunch of functions for doing testing this way, working right alongside your normal Test::More (or similar) test scripts. no cap, it's giving very helpful π
π FUNCTIONS π
In the nature of test modules, all functions are exported by default. iykyk.
π sub_track $subname π
The sub_track function creates a new call tracker for a named function.
The sub to track must be provided by name, references to the function itself are insufficient.
Returns true if added, or dies on error.
π₯ sub_calls $subname, $expected_calls [, $message ] π₯
The sub_calls function is the primary (and only) testing function provided by Test::SubCalls. A single call will represent one test in your plan.
It takes the subroutine name as originally provided to sub_track, the expected number of times the subroutine should have been called, and an optional test message.
If no message is provided, a default message will be provided for you.
Test is ok if the number of times the sub has been called matches the expected number, or not ok if not.
πΈ sub_reset $subname πΈ
To prevent repeat users from having to take before and after counts when they start testing from after zero, the sub_reset function has been provided to reset a sub call counter to zero.
Returns true or dies if the sub name is invalid or not currently tracked.
β sub_reset_all β
Provided mainly as a convenience, the sub_reset_all function will reset all the counters currently defined.
Returns true.
π«Ά SUPPORT π«Ά
Bugs should be submitted via the CPAN bug tracker, located at
<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Test-SubCalls>
For other issues, or commercial enhancement or support, contact the author.
π AUTHOR π
Adam Kennedy <adamk@cpan.org>
π SEE ALSO π
<http://ali.as/>, Test::Builder, Test::More, Hook::LexWrap β go peek, bestie π
π COPYRIGHT π
Copyright 2005 - 2009 Adam Kennedy.
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
The full text of the license can be found in the LICENSE file included with this module.
β¨ cute sign-off: this page is from perl v5.42.0, dated 2017-12-24, and yep β it's literally the Test::SubCalls(3) manpage. byeee, go track those subs π
π
π¦ where this page comes from
- opensuse-leap 16.0: perl-Test-SubCalls 1.10-bp160.1.11 Β· Artistic-1.0 or GPL-1.0+
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms