1Test2::Tools::Exports(3U)ser Contributed Perl DocumentatiToenst2::Tools::Exports(3)
2
3
4
6 Test2::Tools::Exports - Tools for validating exporters.
7
9 These are tools for checking that symbols have been imported into your
10 namespace.
11
13 use Test2::Tools::Exports
14
15 use Data::Dumper;
16 imported_ok qw/Dumper/;
17 not_imported_ok qw/dumper/;
18
20 All subs are exported by default.
21
22 imported_ok(@SYMBOLS)
23 Check that the specified symbols exist in the current package. This
24 will not find inherited subs. This will only find symbols in the
25 current package's symbol table. This WILL NOT confirm that the
26 symbols were defined outside of the package itself.
27
28 imported_ok( '$scalar', '@array', '%hash', '&sub', 'also_a_sub' );
29
30 @SYMBOLS can contain any number of symbols. Each item in the array
31 must be a string. The string should be the name of a symbol. If a
32 sigil is present then it will search for that specified type, if no
33 sigil is specified it will be used as a sub name.
34
35 not_imported_ok(@SYMBOLS)
36 Check that the specified symbols do not exist in the current
37 package. This will not find inherited subs. This will only look at
38 symbols in the current package's symbol table.
39
40 not_imported_ok( '$scalar', '@array', '%hash', '&sub', 'also_a_sub' );
41
42 @SYMBOLS can contain any number of symbols. Each item in the array
43 must be a string. The string should be the name of a symbol. If a
44 sigil is present, then it will search for that specified type. If
45 no sigil is specified, it will be used as a sub name.
46
48 Before Perl 5.10, it is very difficult to distinguish between a package
49 scalar that is undeclared vs declared and undefined. Currently
50 "imported_ok" and "not_imported_ok" cannot see package scalars declared
51 using "our $var" unless the variable has been assigned a defined value.
52
53 This will pass on recent perls, but fail on perls older than 5.10:
54
55 use Test2::Tools::Exports;
56
57 our $foo;
58
59 # Fails on perl onlder than 5.10
60 imported_ok(qw/$foo/);
61
62 If $foo is imported from another module, or imported using "use vars
63 qw/$foo/;" then it will work on all supported perl versions.
64
65 use Test2::Tools::Exports;
66
67 use vars qw/$foo/;
68 use Some::Module qw/$bar/;
69
70 # Always works
71 imported_ok(qw/$foo $bar/);
72
74 The source code repository for Test2-Suite can be found at
75 https://github.com/Test-More/Test2-Suite/.
76
78 Chad Granum <exodist@cpan.org>
79
81 Chad Granum <exodist@cpan.org>
82
84 Copyright 2018 Chad Granum <exodist@cpan.org>.
85
86 This program is free software; you can redistribute it and/or modify it
87 under the same terms as Perl itself.
88
89 See http://dev.perl.org/licenses/
90
91
92
93perl v5.34.0 2022-03-08 Test2::Tools::Exports(3)