1Test::SubCalls(3) User Contributed Perl Documentation Test::SubCalls(3)
2
3
4
6 Test::SubCalls - Track the number of times subs are called
7
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
27 There are a number of different situations (like testing caching 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
37 In the nature of test modules, all functions are exported by default.
38
39 sub_track $subname
40 The "sub_track" function creates a new call tracker for a named
41 function.
42
43 The sub to track must be provided by name, references to the function
44 itself are insufficient.
45
46 Returns true if added, or dies on error.
47
48 sub_calls $subname, $expected_calls [, $message ]
49 The "sub_calls" function is the primary (and only) testing function
50 provided by "Test::SubCalls". A single call will represent one test in
51 your plan.
52
53 It takes the subroutine name as originally provided to "sub_track", the
54 expected number of times the subroutine should have been called, and an
55 optional test message.
56
57 If no message is provided, a default message will be provided for you.
58
59 Test is ok if the number of times the sub has been called matches the
60 expected number, or not ok if not.
61
62 sub_reset $subname
63 To prevent repeat users from having to take before and after counts
64 when they start testing from after zero, the "sub_reset" function has
65 been provided to reset a sub call counter to zero.
66
67 Returns true or dies if the sub name is invalid or not currently
68 tracked.
69
70 sub_reset_all
71 Provided mainly as a convenience, the "sub_reset_all" function will
72 reset all the counters currently defined.
73
74 Returns true.
75
77 Bugs should be submitted via the CPAN bug tracker, located at
78
79 <http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Test-SubCalls>
80
81 For other issues, or commercial enhancement or support, contact the
82 author.
83
85 Adam Kennedy <adamk@cpan.org>
86
88 <http://ali.as/>, Test::Builder, Test::More, Hook::LexWrap
89
91 Copyright 2005 - 2009 Adam Kennedy.
92
93 This program is free software; you can redistribute it and/or modify it
94 under the same terms as Perl itself.
95
96 The full text of the license can be found in the LICENSE file included
97 with this module.
98
99
100
101perl v5.16.3 2009-04-19 Test::SubCalls(3)