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

SYNOPSIS

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

DESCRIPTION

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

FUNCTIONS

37       In the nature of test modules, all functions are exported by default.
38
39       sub_track $subname
40
41       The "sub_track" function creates a new call tracker for a named func‐
42       tion.
43
44       The sub to track must be provided by name, references to the function
45       itself are insufficient.
46
47       Returns true if added, or dies on error.
48
49       sub_calls $subname, $expected_calls [, $message ]
50
51       The "sub_calls" function is the primary (and only) testing function
52       provided by "Test::SubCalls". A single call will represent one test in
53       your plan.
54
55       It takes the subroutine name as originally provided to "sub_track", the
56       expected number of times the subroutine should have been called, and an
57       optional test message.
58
59       If no message is provided, a default message will be provided for you.
60
61       Test is ok if the number of times the sub has been called matches the
62       expected number, or not ok if not.
63
64       sub_reset $subname
65
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
75       Provided mainly as a convenience, the "sub_reset_all" function will
76       reset all the counters currently defined.
77
78       Returns true.
79

SUPPORT

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

AUTHOR

89       Adam Kennedy <cpan@ali.as>
90

SEE ALSO

92       <http://ali.as/>, Test::Builder, Test::More, Hook::LexWrap
93
95       Copyright (c) 2005, 2006 Adam Kennedy. All rights reserved.  This pro‐
96       gram is free software; you can redistribute it and/or modify it under
97       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.8.8                       2006-05-12                 Test::SubCalls(3)
Impressum