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

NAME

6       Test::Strict - Check syntax, presence of use strict; and test coverage
7

VERSION

9       Version 0.52
10

SYNOPSIS

12       "Test::Strict" lets you check the syntax, presence of "use strict;" and
13       presence "use warnings;" in your perl code.  It report its results in
14       standard Test::Simple fashion:
15
16           use Test::Strict tests => 3;
17           syntax_ok( 'bin/myscript.pl' );
18           strict_ok( 'My::Module', "use strict; in My::Module" );
19           warnings_ok( 'lib/My/Module.pm' );
20
21       Module authors can include the following in a t/strict.t and have
22       "Test::Strict" automatically find and check all perl files in a module
23       distribution:
24
25         use Test::Strict;
26         all_perl_files_ok(); # Syntax ok and use strict;
27
28       or
29
30           use Test::Strict;
31           all_perl_files_ok( @mydirs );
32
33       "Test::Strict" can also enforce a minimum test coverage the test suite
34       should reach.  Module authors can include the following in a t/cover.t
35       and have "Test::Strict" automatically check the test coverage:
36
37           use Test::Strict;
38           all_cover_ok( 80 );  # at least 80% coverage
39
40       or
41
42           use Test::Strict;
43           all_cover_ok( 80, 't/' );
44

DESCRIPTION

46       The most basic test one can write is "does it compile ?".  This module
47       tests if the code compiles and play nice with Test::Simple modules.
48
49       Another good practice this module can test is to "use strict;" in all
50       perl files.
51
52       By setting a minimum test coverage through "all_cover_ok()", a code
53       author can ensure his code is tested above a preset level of kwality
54       throughout the development cycle.
55
56       Along with Test::Pod, this module can provide the first tests to setup
57       for a module author.
58
59       This module should be able to run under the -T flag for perl >= 5.6.
60       All paths are untainted with the following pattern:
61       "qr|^([-+@\w./:\\]+)$|" controlled by $Test::Strict::UNTAINT_PATTERN.
62

FUNCTIONS

64   syntax_ok( $file [, $text] )
65       Run a syntax check on $file by running "perl -c $file" with an external
66       perl interpreter.  The external perl interpreter path is stored in
67       $Test::Strict::PERL which can be modified.  You may prefer "use_ok()"
68       from Test::More to syntax test a module.  For a module, the path
69       (lib/My/Module.pm) or the name (My::Module) can be both used.
70
71   strict_ok( $file [, $text] )
72       Check if $file contains a "use strict;" statement.  "use Moose" and
73       "use Mouse" are also considered valid.  use Modern::Perl is also
74       accepted.
75
76       This is a pretty naive test which may be fooled in some edge cases.
77       For a module, the path (lib/My/Module.pm) or the name (My::Module) can
78       be both used.
79
80   modules_enabling_strict
81       Experimental. Returning a list of modules and pragmata that enable
82       strict.  To modify this list, change
83       @Test::Strict::MODULES_ENABLING_STRICT.
84
85       List taken from Module::CPANTS::Kwalitee::Uses v95
86
87   modules_enabling_warnings
88       Experimental. Returning a list of modules and pragmata that enable
89       warnings To modify this list, change
90       @Test::Strict::MODULES_ENABLING_WARNINGS.
91
92       List taken from Module::CPANTS::Kwalitee::Uses v95
93
94   warnings_ok( $file [, $text] )
95       Check if warnings have been turned on.
96
97       If $file is a module, check if it contains a "use warnings;" or "use
98       warnings::..."  or "use Moose" or "use Mouse" statement. use
99       Modern::Perl is also accepted.  If the perl version is <= 5.6, this
100       test is skipped ("use warnings" appeared in perl 5.6).
101
102       If $file is a script, check if it starts with "#!...perl -w".  If the
103       -w is not found and perl is >= 5.6, check for a "use warnings;" or "use
104       warnings::..."  or "use Moose" or "use Mouse" statement. use
105       Modern::Perl is also accepted.
106
107       This is a pretty naive test which may be fooled in some edge cases.
108       For a module, the path (lib/My/Module.pm) or the name (My::Module) can
109       be both used.
110
111   all_perl_files_ok( [ @directories ] )
112       Applies "strict_ok()" and "syntax_ok()" to all perl files found in
113       @directories (and sub directories).  If no <@directories> is given, the
114       starting point is one level above the current running script, that
115       should cover all the files of a typical CPAN distribution.  A perl file
116       is *.pl or *.pm or *.t or a file starting with "#!...perl"
117
118       If the test plan is defined:
119
120         use Test::Strict tests => 18;
121         all_perl_files_ok();
122
123       the total number of files tested must be specified.
124
125       You can control which tests are run on each perl site through:
126
127         $Test::Strict::TEST_SYNTAX   (default = 1)
128         $Test::Strict::TEST_STRICT   (default = 1)
129         $Test::Strict::TEST_WARNINGS (default = 0)
130         $Test::Strict::TEST_SKIP     (default = []) "Trusted" files to skip
131
132   all_cover_ok( [coverage_threshold [, @t_dirs]] )
133       This will run all the tests in @t_dirs (or current script's directory
134       if @t_dirs is undef) under Devel::Cover and calculate the global test
135       coverage of the code loaded by the tests.  If the test coverage is
136       greater or equal than "coverage_threshold", it is a pass, otherwise
137       it's a fail. The default coverage threshold is 50 (meaning 50% of the
138       code loaded has been covered by test).
139
140       The threshold can be modified through
141       $Test::Strict::COVERAGE_THRESHOLD.
142
143       You may want to select which files are selected for code coverage
144       through $Test::Strict::DEVEL_COVER_OPTIONS, see Devel::Cover for the
145       list of available options.  The default is '+ignore,"/Test/Strict\b"'.
146
147       The path to "cover" utility can be modified through
148       $Test::Strict::COVER.
149
150       The 50% threshold is a completely arbitrary value, which should not be
151       considered as a good enough coverage.
152
153       The total coverage is the return value of "all_cover_ok()".
154

CAVEATS

156       For "all_cover_ok()" to work properly, it is strongly advised to
157       install the most recent version of Devel::Cover and use perl 5.8.1 or
158       above.  In the case of a "make test" scenario, "all_perl_files_ok()"
159       re-run all the tests in a separate perl interpreter, this may lead to
160       some side effects.
161

SEE ALSO

163       Test::More, Test::Pod. Test::Distribution, Test::NoWarnings
164

REPOSITORY

166       <https://github.com/manwar/Test-Strict>
167

AUTHOR

169       Pierre Denis, "<pdenis@gmail.com>".
170

MAINTAINER

172       Gabor Szabo <http://szabgab.com/>
173
174       Currently maintained by Mohammad S Anwar (MANWAR), "<mohammad.anwar at
175       yahoo.com>"
176
178       Copyright 2005, 2010 Pierre Denis, All Rights Reserved.
179
180       You may use, modify, and distribute this package under the same terms
181       as Perl itself.
182
183
184
185perl v5.36.0                      2022-07-22                   Test::Strict(3)
Impressum