1Test::SubCalls(3)     User Contributed Perl Documentation    Test::SubCalls(3)
2
3
4

NAME

6       Test::SubCalls - Track the number of times subs are called
7

VERSION

9       version 1.10
10

SYNOPSIS

12         use Test::SubCalls;
13
14         # Start tracking calls to a named sub
15         sub_track( 'Foo::foo' );
16
17         # Run some test code
18         ...
19
20         # Test that some sub deep in the codebase was called
21         # a specific number of times.
22         sub_calls( 'Foo::foo', 5 );
23         sub_calls( 'Foo::foo', 5, 'Use a custom test message' );
24
25         # Reset the counts for one or all subs
26         sub_reset( 'Foo::foo' );
27         sub_reset_all();
28

DESCRIPTION

30       There are a number of different situations (like testing caching code)
31       where you want to want to do a number of tests, and then verify that
32       some underlying subroutine deep within the code was called a specific
33       number of times.
34
35       This module provides a number of functions for doing testing in this
36       way in association with your normal Test::More (or similar) test
37       scripts.
38

FUNCTIONS

40       In the nature of test modules, all functions are exported by default.
41
42   sub_track $subname
43       The "sub_track" function creates a new call tracker for a named
44       function.
45
46       The sub to track must be provided by name, references to the function
47       itself are insufficient.
48
49       Returns true if added, or dies on error.
50
51   sub_calls $subname, $expected_calls [, $message ]
52       The "sub_calls" function is the primary (and only) testing function
53       provided by "Test::SubCalls". A single call will represent one test in
54       your plan.
55
56       It takes the subroutine name as originally provided to "sub_track", the
57       expected number of times the subroutine should have been called, and an
58       optional test message.
59
60       If no message is provided, a default message will be provided for you.
61
62       Test is ok if the number of times the sub has been called matches the
63       expected number, or not ok if not.
64
65   sub_reset $subname
66       To prevent repeat users from having to take before and after counts
67       when they start testing from after zero, the "sub_reset" function has
68       been provided to reset a sub call counter to zero.
69
70       Returns true or dies if the sub name is invalid or not currently
71       tracked.
72
73   sub_reset_all
74       Provided mainly as a convenience, the "sub_reset_all" function will
75       reset all the counters currently defined.
76
77       Returns true.
78

SUPPORT

80       Bugs should be submitted via the CPAN bug tracker, located at
81
82       <http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Test-SubCalls>
83
84       For other issues, or commercial enhancement or support, contact the
85       author.
86

AUTHOR

88       Adam Kennedy <adamk@cpan.org>
89

SEE ALSO

91       <http://ali.as/>, Test::Builder, Test::More, Hook::LexWrap
92
94       Copyright 2005 - 2009 Adam Kennedy.
95
96       This program is free software; you can redistribute it and/or modify it
97       under the same terms as Perl itself.
98
99       The full text of the license can be found in the LICENSE file included
100       with this module.
101
102
103
104perl v5.28.1                      2017-12-23                 Test::SubCalls(3)
Impressum