.\" Automatically generated by Pod::Man 4.14 (Pod::Simple 3.40) .\" .\" Standard preamble: .\" ======================================================================== .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" Set up some character translations and predefined strings. \*(-- will .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left .\" double quote, and \*(R" will give a right double quote. \*(C+ will .\" give a nicer C++. Capital omega is used to do unbreakable dashes and .\" therefore won't be available. \*(C` and \*(C' expand to `' in nroff, .\" nothing in troff, for use with C<>. .tr \(*W- .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p' .ie n \{\ . ds -- \(*W- . ds PI pi . if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch . if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch . ds L" "" . ds R" "" . ds C` "" . ds C' "" 'br\} .el\{\ . ds -- \|\(em\| . ds PI \(*p . ds L" `` . ds R" '' . ds C` . ds C' 'br\} .\" .\" Escape single quotes in literal strings from groff's Unicode transform. .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" .\" If the F register is >0, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .\" .\" Avoid warning from groff about undefined register 'F'. .de IX .. .nr rF 0 .if \n(.g .if rF .nr rF 1 .if (\n(rF:(\n(.g==0)) \{\ . if \nF \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{\ . nr % 0 . nr F 2 . \} . \} .\} .rr rF .\" ======================================================================== .\" .IX Title "Apache::Test 3pm" .TH Apache::Test 3pm "2021-02-22" "perl v5.32.1" "User Contributed Perl Documentation" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l .nh .SH "NAME" Apache::Test \- Test.pm wrapper with helpers for testing Apache .SH "SYNOPSIS" .IX Header "SYNOPSIS" .Vb 1 \& use Apache::Test; .Ve .SH "DESCRIPTION" .IX Header "DESCRIPTION" \&\fBApache::Test\fR is a wrapper around the standard \f(CW\*(C`Test.pm\*(C'\fR with helpers for testing an Apache server. .SH "FUNCTIONS" .IX Header "FUNCTIONS" .IP "plan" 4 .IX Item "plan" This function is a wrapper around \f(CW\*(C`Test::plan\*(C'\fR: .Sp .Vb 1 \& plan tests => 3; .Ve .Sp just like using Test.pm, plan 3 tests. .Sp If the first argument is an object, such as an \f(CW\*(C`Apache::RequestRec\*(C'\fR object, \f(CW\*(C`STDOUT\*(C'\fR will be tied to it. The \f(CW\*(C`Test.pm\*(C'\fR global state will also be refreshed by calling \f(CW\*(C`Apache::Test::test_pm_refresh\*(C'\fR. For example: .Sp .Vb 1 \& plan $r, tests => 7; .Ve .Sp ties \s-1STDOUT\s0 to the request object \f(CW$r\fR. .Sp If there is a last argument that doesn't belong to \f(CW\*(C`Test::plan\*(C'\fR (which expects a balanced hash), it's used to decide whether to continue with the test or to skip it all-together. This last argument can be: .RS 4 .IP "\(bu" 4 a \f(CW\*(C`SCALAR\*(C'\fR .Sp the test is skipped if the scalar has a false value. For example: .Sp .Vb 1 \& plan tests => 5, 0; .Ve .Sp But this won't hint the reason for skipping therefore it's better to use \fBneed()\fR: .Sp .Vb 3 \& plan tests => 5, \& need \*(AqLWP\*(Aq, \& { "not Win32" => sub { $^O eq \*(AqMSWin32\*(Aq} }; .Ve .Sp see \f(CW\*(C`need()\*(C'\fR for more info. .IP "\(bu" 4 an \f(CW\*(C`ARRAY\*(C'\fR reference .Sp \&\fBneed_module()\fR is called for each value in this array. The test is skipped if \fBneed_module()\fR returns false (which happens when at least one C or Perl module from the list cannot be found). .Sp Watch out for case insensitive file systems or duplicate modules with the same name. I.E. If you mean mod_env.c need_module('mod_env.c') Not need_module('env') .IP "\(bu" 4 a \f(CW\*(C`CODE\*(C'\fR reference .Sp the tests will be skipped if the function returns a false value. For example: .Sp .Vb 1 \& plan tests => 5, need_lwp; .Ve .Sp the test will be skipped if \s-1LWP\s0 is not available .RE .RS 4 .Sp All other arguments are passed through to \fITest::plan\fR as is. .RE .IP "ok" 4 .IX Item "ok" Same as \fITest::ok\fR, see \fITest.pm\fR documentation. .IP "sok" 4 .IX Item "sok" Allows one to skip a sub-test, controlled from the command line. The argument to \fBsok()\fR is a \s-1CODE\s0 reference or a \s-1BLOCK\s0 whose return value will be passed to \fBok()\fR. By default behaves like \fBok()\fR. If all sub-tests of the same test are written using \fBsok()\fR, and a test is executed as: .Sp .Vb 1 \& % ./t/TEST \-v skip_subtest 1 3 .Ve .Sp only sub-tests 1 and 3 will be run, the rest will be skipped. .IP "skip" 4 .IX Item "skip" Same as \fITest::skip\fR, see \fITest.pm\fR documentation. .IP "test_pm_refresh" 4 .IX Item "test_pm_refresh" Normally called by \fIApache::Test::plan\fR, this function will refresh the global state maintained by \fITest.pm\fR, allowing \f(CW\*(C`plan\*(C'\fR and friends to be called more than once per-process. This function is not exported. .PP Functions that can be used as a last argument to the extended \fBplan()\fR. Note that for each \f(CW\*(C`need_*\*(C'\fR function there is a \f(CW\*(C`have_*\*(C'\fR equivalent that performs the exact same function except that it is designed to be used outside of \f(CW\*(C`plan()\*(C'\fR. \f(CW\*(C`need_*\*(C'\fR functions have the side effect of generating skip messages, if the test is skipped. \f(CW\*(C`have_*\*(C'\fR functions don't have this side effect. In other words, use \f(CW\*(C`need_apache()\*(C'\fR with \f(CW\*(C`plan()\*(C'\fR to decide whether a test will run, but \f(CW\*(C`have_apache()\*(C'\fR within test logic to adjust expectations based on older or newer server versions. .IP "need_http11" 4 .IX Item "need_http11" .Vb 1 \& plan tests => 5, need_http11; .Ve .Sp Require \s-1HTTP/1.1\s0 support. .IP "need_ssl" 4 .IX Item "need_ssl" .Vb 1 \& plan tests => 5, need_ssl; .Ve .Sp Require \s-1SSL\s0 support. .Sp Not exported by default. .IP "need_lwp" 4 .IX Item "need_lwp" .Vb 1 \& plan tests => 5, need_lwp; .Ve .Sp Require \s-1LWP\s0 support. .IP "need_cgi" 4 .IX Item "need_cgi" .Vb 1 \& plan tests => 5, need_cgi; .Ve .Sp Requires mod_cgi or mod_cgid to be installed. .IP "need_cache_disk" 4 .IX Item "need_cache_disk" .Vb 1 \& plan tests => 5, need_cache_disk .Ve .Sp Requires mod_cache_disk or mod_disk_cache to be installed. .IP "need_php" 4 .IX Item "need_php" .Vb 1 \& plan tests => 5, need_php; .Ve .Sp Requires a \s-1PHP\s0 module to be installed (version 4 or 5). .IP "need_php4" 4 .IX Item "need_php4" .Vb 1 \& plan tests => 5, need_php4; .Ve .Sp Requires a \s-1PHP\s0 version 4 module to be installed. .IP "need_imagemap" 4 .IX Item "need_imagemap" .Vb 1 \& plan tests => 5, need_imagemap; .Ve .Sp Requires a mod_imagemap or mod_imap be installed .IP "need_apache" 4 .IX Item "need_apache" .Vb 1 \& plan tests => 5, need_apache 2; .Ve .Sp Requires Apache 2nd generation httpd\-2.x.xx .Sp .Vb 1 \& plan tests => 5, need_apache 1; .Ve .Sp Requires Apache 1st generation (apache\-1.3.xx) .Sp See also \f(CW\*(C`need_min_apache_version()\*(C'\fR. .IP "need_min_apache_version" 4 .IX Item "need_min_apache_version" Used to require a minimum version of Apache. .Sp For example: .Sp .Vb 1 \& plan tests => 5, need_min_apache_version("2.0.40"); .Ve .Sp requires Apache 2.0.40 or higher. .IP "need_apache_version" 4 .IX Item "need_apache_version" Used to require a specific version of Apache. .Sp For example: .Sp .Vb 1 \& plan tests => 5, need_apache_version("2.0.40"); .Ve .Sp requires Apache 2.0.40. .IP "need_min_apache_fix" 4 .IX Item "need_min_apache_fix" Used to require a particular micro version from corresponding minor release .Sp For example: .Sp .Vb 1 \& plan tests => 5, need_min_apache_fix("2.0.40", "2.2.30", "2.4.18"); .Ve .Sp requires Apache 2.0.40 or higher. .IP "need_apache_mpm" 4 .IX Item "need_apache_mpm" Used to require a specific Apache Multi-Processing Module. .Sp For example: .Sp .Vb 1 \& plan tests => 5, need_apache_mpm(\*(Aqprefork\*(Aq); .Ve .Sp requires the prefork \s-1MPM.\s0 .IP "need_perl" 4 .IX Item "need_perl" .Vb 2 \& plan tests => 5, need_perl \*(Aqiolayers\*(Aq; \& plan tests => 5, need_perl \*(Aqithreads\*(Aq; .Ve .Sp Requires a perl extension to be present, or perl compiled with certain capabilities. .Sp The first example tests whether \f(CW\*(C`PerlIO\*(C'\fR is available, the second whether: .Sp .Vb 1 \& $Config{useithread} eq \*(Aqdefine\*(Aq; .Ve .IP "need_min_perl_version" 4 .IX Item "need_min_perl_version" Used to require a minimum version of Perl. .Sp For example: .Sp .Vb 1 \& plan tests => 5, need_min_perl_version("5.008001"); .Ve .Sp requires Perl 5.8.1 or higher. .IP "need_fork" 4 .IX Item "need_fork" Requires the perl built-in function \f(CW\*(C`fork\*(C'\fR to be implemented. .IP "need_module" 4 .IX Item "need_module" .Vb 3 \& plan tests => 5, need_module \*(AqCGI\*(Aq; \& plan tests => 5, need_module qw(CGI Find::File); \& plan tests => 5, need_module [\*(AqCGI\*(Aq, \*(AqFind::File\*(Aq, \*(Aqcgid\*(Aq]; .Ve .Sp Requires Apache C and Perl modules. The function accept a list of arguments or a reference to a list. .Sp In case of C modules, depending on how the module name was passed it may pass through the following completions: .RS 4 .IP "1 need_module 'proxy_http.c'" 4 .IX Item "1 need_module 'proxy_http.c'" If there is the \fI.c\fR extension, the module name will be looked up as is, i.e. \fI'proxy_http.c'\fR. .IP "2 need_module 'mod_cgi'" 4 .IX Item "2 need_module 'mod_cgi'" The \fI.c\fR extension will be appended before the lookup, turning it into \&\fI'mod_cgi.c'\fR. .IP "3 need_module 'cgi'" 4 .IX Item "3 need_module 'cgi'" The \fI.c\fR extension and \fImod_\fR prefix will be added before the lookup, turning it into \fI'mod_cgi.c'\fR. .RE .RS 4 .RE .IP "need_min_module_version" 4 .IX Item "need_min_module_version" Used to require a minimum version of a module .Sp For example: .Sp .Vb 1 \& plan tests => 5, need_min_module_version(CGI => 2.81); .Ve .Sp requires \f(CW\*(C`CGI.pm\*(C'\fR version 2.81 or higher. .Sp Currently works only for perl modules. .IP "need" 4 .IX Item "need" .Vb 8 \& plan tests => 5, \& need \*(AqLWP\*(Aq, \& { "perl >= 5.8.0 and w/ithreads is required" => \& ($Config{useperlio} && $] >= 5.008) }, \& { "not Win32" => sub { $^O eq \*(AqMSWin32\*(Aq }, \& "foo is disabled" => \e&is_foo_enabled, \& }, \& \*(Aqcgid\*(Aq; .Ve .Sp \&\fBneed()\fR is more generic function which can impose multiple requirements at once. All requirements must be satisfied. .Sp \&\fBneed()\fR's argument is a list of things to test. The list can include scalars, which are passed to \fBneed_module()\fR, and hash references. If hash references are used, the keys, are strings, containing a reason for a failure to satisfy this particular entry, the values are the condition, which are satisfaction if they return true. If the value is 0 or 1, it used to decide whether the requirements very satisfied, so you can mix special \f(CW\*(C`need_*()\*(C'\fR functions that return 0 or 1. For example: .Sp .Vb 2 \& plan tests => 1, need \*(AqCompress::Zlib\*(Aq, \*(Aqdeflate\*(Aq, \& need_min_apache_version("2.0.49"); .Ve .Sp If the scalar value is a string, different from 0 or 1, it's passed to \&\fI\f(BIneed_module()\fI\fR. If the value is a code reference, it gets executed at the time of check and its return value is used to check the condition. If the condition check fails, the provided (in a key) reason is used to tell user why the test was skipped. .Sp In the presented example, we require the presence of the \f(CW\*(C`LWP\*(C'\fR Perl module, \f(CW\*(C`mod_cgid\*(C'\fR, that we run under perl >= 5.7.3 on Win32. .Sp It's possible to put more than one requirement into a single hash reference, but be careful that the keys will be different. .Sp It's also important to mention to avoid using: .Sp .Vb 1 \& plan tests => 1, requirement1 && requirement2; .Ve .Sp technique. While test-wise that technique is equivalent to: .Sp .Vb 1 \& plan tests => 1, need requirement1, requirement2; .Ve .Sp since the test will be skipped, unless all the rules are satisfied, it's not equivalent for the end users. The second technique, deploying \&\f(CW\*(C`need()\*(C'\fR and a list of requirements, always runs all the requirement checks and reports all the missing requirements. In the case of the first technique, if the first requirement fails, the second is not run, and the missing requirement is not reported. So let's say all the requirements are missing Apache modules, and a user wants to satisfy all of these and run the test suite again. If all the unsatisfied requirements are reported at once, she will need to rebuild Apache once. If only one requirement is reported at a time, she will have to rebuild Apache as many times as there are elements in the \f(CW\*(C`&&\*(C'\fR statement. .Sp Also see \fBplan()\fR. .IP "under_construction" 4 .IX Item "under_construction" .Vb 1 \& plan tests => 5, under_construction; .Ve .Sp skip all tests, noting that the tests are under construction .IP "skip_reason" 4 .IX Item "skip_reason" .Vb 1 \& plan tests => 5, skip_reason(\*(Aqmy custom reason\*(Aq); .Ve .Sp skip all tests. the reason you specify will be given at runtime. if no reason is given a default reason will be used. .SH "Additional Configuration Variables" .IX Header "Additional Configuration Variables" .RS 4 .IP "basic_config" 4 .IX Item "basic_config" .Vb 2 \& my $basic_cfg = Apache::Test::basic_config(); \& $basic_cfg\->write_perlscript($file, $content); .Ve .Sp \&\f(CW\*(C`basic_config()\*(C'\fR is similar to \f(CW\*(C`config()\*(C'\fR, but doesn't contain any httpd-specific information and should be used for operations that don't require any httpd-specific knowledge. .IP "config" 4 .IX Item "config" .Vb 3 \& my $cfg = Apache::Test::config(); \& my $server_rev = $cfg\->{server}\->{rev}; \& ... .Ve .Sp \&\f(CW\*(C`config()\*(C'\fR gives an access to the configuration object. .IP "vars" 4 .IX Item "vars" .Vb 3 \& my $serverroot = Apache::Test::vars\->{serverroot}; \& my $serverroot = Apache::Test::vars(\*(Aqserverroot\*(Aq); \& my($top_dir, $t_dir) = Apache::Test::vars(qw(top_dir t_dir)); .Ve .Sp \&\f(CW\*(C`vars()\*(C'\fR gives an access to the configuration variables, otherwise accessible as: .Sp .Vb 1 \& $vars = Apache::Test::config()\->{vars}; .Ve .Sp If no arguments are passed, the reference to the variables hash is returned. If one or more arguments are passed the corresponding values are returned. .RE .RS 4 .RE .SH "Test::More Integration" .IX Header "Test::More Integration" There are a few caveats if you want to use \fIApache::Test\fR with \&\fITest::More\fR instead of the default \fITest\fR backend. The first is that \fITest::More\fR requires you to use its own \f(CW\*(C`plan()\*(C'\fR function and not the one that ships with \fIApache::Test\fR. \fITest::More\fR also defines \f(CW\*(C`ok()\*(C'\fR and \f(CW\*(C`skip()\*(C'\fR functions that are different, and simply \f(CW\*(C`use\*(C'\fRing both modules in your test script will lead to redefined warnings for these subroutines. .PP To assist \fITest::More\fR users we have created a special \fIApache::Test\fR import tag, \f(CW\*(C`:withtestmore\*(C'\fR, which will export all of the standard \&\fIApache::Test\fR symbols into your namespace except the ones that collide with \fITest::More\fR. .PP .Vb 2 \& use Apache::Test qw(:withtestmore); \& use Test::More; \& \& plan tests => 1; # Test::More::plan() \& \& ok (\*(Aqyes\*(Aq, \*(Aqtesting ok\*(Aq); # Test::More::ok() .Ve .PP Now, while this works fine for standard client-side tests (such as \f(CW\*(C`t/basic.t\*(C'\fR), the more advanced features of \fIApache::Test\fR require using \fITest::More\fR as the sole driver behind the scenes. .PP Should you choose to use \fITest::More\fR as the backend for server-based tests (such as \f(CW\*(C`t/response/TestMe/basic.pm\*(C'\fR) you will need to use the \f(CW\*(C`\-withtestmore\*(C'\fR action tag: .PP .Vb 1 \& use Apache::Test qw(\-withtestmore); \& \& sub handler { \& \& my $r = shift; \& \& plan $r, tests => 1; # Test::More::plan() with \& # Apache::Test features \& \& ok (\*(Aqyes\*(Aq, \*(Aqtesting ok\*(Aq); # Test::More::ok() \& } .Ve .PP \&\f(CW\*(C`\-withtestmore\*(C'\fR tells \fIApache::Test\fR to use \fITest::More\fR instead of \fITest.pm\fR behind the scenes. Note that you are not required to \f(CW\*(C`use Test::More\*(C'\fR yourself with the \f(CW\*(C`\-withtestmore\*(C'\fR option and that the \f(CW\*(C`use Test::More tests => 1\*(C'\fR syntax may have unexpected results. .PP Note that \fITest::More\fR version 0.49, available within the \&\fITest::Simple\fR 0.49 distribution on \s-1CPAN,\s0 or greater is required to use this feature. .PP Because \fIApache:Test\fR was initially developed using \fITest\fR as the framework driver, complete \fITest::More\fR integration is considered experimental at this time \- it is supported as best as possible but is not guaranteed to be as stable as the default \fITest\fR interface at this time. .SH "Apache::TestToString Class" .IX Header "Apache::TestToString Class" The \fIApache::TestToString\fR class is used to capture \fITest.pm\fR output into a string. Example: .PP .Vb 1 \& Apache::TestToString\->start; \& \& plan tests => 4; \& \& ok $data eq \*(Aqfoo\*(Aq; \& \& ... \& \& # $tests will contain the Test.pm output: 1..4\enok 1\en... \& my $tests = Apache::TestToString\->finish; .Ve .SH "SEE ALSO" .IX Header "SEE ALSO" The Apache-Test tutorial: . .PP Apache::TestRequest subclasses LWP::UserAgent and exports a number of useful functions for sending request to the Apache test server. You can then test the results of those requests. .PP Use Apache::TestMM in your \fIMakefile.PL\fR to set up your distribution for testing. .SH "AUTHOR" .IX Header "AUTHOR" Doug MacEachern with contributions from Geoffrey Young, Philippe M. Chiasson, Stas Bekman and others. .PP Questions can be asked at the test-dev httpd.apache.org list For more information see: http://httpd.apache.org/test/.