1Test::Exports(3) User Contributed Perl Documentation Test::Exports(3)
2
3
4
6 Test::Exports - Test that modules export the right symbols
7
9 use Test::More;
10 use Test::Exports;
11
12 require_ok "My::Module" or BAIL_OUT "can't load module";
13
14 import_ok "My::Module", [], "default import OK";
15 is_import qw/foo bar/, "My::Module", "imports subs";
16
17 new_import_pkg;
18
19 import_ok "My::Module", ["foo"], "named import OK";
20 is_import "foo", "My::Module", "imports foo";
21 cant_ok "bar", "doesn't import bar";
22
24 This module provides simple test functions for testing other modules'
25 "import" methods. Testing is currently limited to checking which subs
26 have been imported.
27
28 In order to keep different calls to "->import" separate, Test::Exports
29 performs these calls from a private package. The symbol-testing
30 functions then test whether or not symbols are present in this private
31 package, ensuring none of this interferes with your test script itself.
32
34 These are all exported by default, as is usual with testing modules.
35
36 "new_import_pkg"
37 Create a new package to perform imports into. This is useful when you
38 want to test "->import" with different arguments: otherwise you'd need
39 to find some way of going back and clearing up the imports from the
40 last call.
41
42 This returns the name of the new package (which will look like
43 "Test::Exports::TestAAAAB") in case you need it.
44
45 "import_ok $module, \@args, $name"
46 Call "$module->import" from the current testing package, passing @args,
47 and check the call succeeded. 'Success' means not throwing an
48 exception: "use" doesn't care if "import" returns false, so neither do
49 we.
50
51 @args defaults to the empty list; $name defaults to something sensible.
52
53 "import_nok $module, \@args, $name"
54 Call "$module->import(@args)" and expect it to throw an exception.
55 Defaults as for "import_ok".
56
57 "is_import @subs, $module, $name"
58 For each name in @subs, check that the current testing package has a
59 sub by that name and that it is the same as the equinominal sub in the
60 $module package.
61
62 Neither $module nor $name are optional.
63
64 "cant_ok @subs, $name"
65 For each sub in @subs, check that a sub of that name does not exist in
66 the current testing package. If one is found the diagnostic will
67 indicate where it was originally defined, to help track down the stray
68 export.
69
71 "is_import"
72 Currently this just checks that "\&Our::Pkg::sub == \&Your::Pkg::sub",
73 which means
74
75 • it is impossible to test for exports which have been renamed, and
76
77 • we can't be sure the sub originally came from Your::Pkg: it may
78 have been exported into both packages from somewhere else.
79
80 It would be good to fix at least the former.
81
83 Ben Morrow <ben@morrow.me.uk>
84
86 Please report any bugs to <bug-Test-Exports@rt.cpan.org>.
87
89 Copyright 2010 Ben Morrow.
90
91 Redistribution and use in source and binary forms, with or without
92 modification, are permitted provided that the following conditions are
93 met:
94
95 • Redistributions of source code must retain the above copyright
96 notice, this list of conditions and the following disclaimer.
97
98 • Redistributions in binary form must reproduce the above copyright
99 notice, this list of conditions and the following disclaimer in the
100 documentation and/or other materials provided with the
101 distribution.
102
103 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
104 IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
105 TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
106 PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER>
107 BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
108 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
109 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
110 BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
111 WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
112 OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
113 ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
114
115
116
117perl v5.36.0 2023-01-20 Test::Exports(3)